1 ;; info.el --- Info package for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1992-2018 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 <https://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."
86 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
87 (t :height
1.2 :inherit info-title-3
))
88 "Face for info titles at level 2."
92 '((((type tty pc
) (class color
)) :weight bold
)
93 (t :height
1.2 :inherit info-title-4
))
94 "Face for info titles at level 3."
98 '((((type tty pc
) (class color
)) :weight bold
)
99 (t :weight bold
:inherit variable-pitch
))
100 "Face for info titles at level 4."
103 (defface info-menu-header
108 :inherit variable-pitch
110 "Face for headers in Info menus."
113 (defface info-menu-star
114 '((((class color
)) :foreground
"red1")
116 "Face for every third `*' in an Info menu."
121 "Face for unvisited Info cross-references."
124 (defface info-xref-visited
125 '((t :inherit
(link-visited info-xref
)))
126 "Face for visited Info cross-references."
130 (defcustom Info-fontify-visited-nodes t
131 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
136 ;; It's unfortunate that nil means no fontification, as opposed to no limit,
137 ;; since that differs from font-lock-maximum-size.
138 (defcustom Info-fontify-maximum-menu-size
400000
139 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
140 Set to nil to disable node fontification; set to t for no limit."
141 :type
'(choice (const :tag
"No fontification" nil
)
142 (const :tag
"No size limit" t
)
143 (integer :tag
"Up to this many characters"))
144 :version
"25.1" ; 100k -> 400k
147 (defcustom Info-use-header-line t
148 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
149 A header-line does not scroll with the rest of the buffer."
153 (defface info-header-xref
154 '((t :inherit info-xref
))
155 "Face for Info cross-references in a node header."
158 (defface info-header-node
159 '((t :inherit info-node
))
160 "Face for Info nodes in a node header."
163 (defface info-index-match
164 '((t :inherit match
))
165 "Face used to highlight matches in an index entry."
169 ;; This is a defcustom largely so that we can get the benefit
170 ;; of custom-initialize-delay. Perhaps it would work to make it a
171 ;; defvar and explicitly give it a standard-value property, and
172 ;; call custom-initialize-delay on it.
173 ;; The progn forces the autoloader to include the whole thing, not
174 ;; just an abbreviated version. The value is initialized at startup
175 ;; time, when command-line calls custom-reevaluate-setting on all
176 ;; the defcustoms in custom-delayed-init-variables. This is
177 ;; somewhat sub-optimal, as ideally this should be done when Info
178 ;; mode is first invoked.
181 (defcustom Info-default-directory-list
183 (file-name-as-directory
184 ;; Self-contained NS build with info/ in the app-bundle.
185 (or (and (featurep 'ns
)
186 (let ((dir (expand-file-name "../info" data-directory
)))
187 (if (file-directory-p dir
) dir
)))
188 configure-info-directory
)))
190 ;; Directory trees in which to look for info subdirectories
191 (prune-directory-list '("/usr/local/" "/usr/" "/opt/")))
193 ;; Subdirectories in each directory tree that may contain info
198 (mapcar (lambda (pfx)
200 (mapcar (lambda (sfx)
201 (concat pfx sfx
"info/"))
203 (prune-directory-list dirs
)))
205 ;; If $(prefix)/share/info is not one of the standard info
206 ;; directories, they are probably installing an experimental
207 ;; version of Emacs, so make sure that experimental version's Info
208 ;; files override the ones in standard directories.
210 (if (member config-dir standard-info-dirs
)
211 ;; FIXME? What is the point of adding it again at the end
212 ;; when it is already present earlier in the list?
213 (nconc standard-info-dirs
(list config-dir
))
214 (cons config-dir standard-info-dirs
))))
215 (if (not (eq system-type
'windows-nt
))
217 ;; Include the info directory near where Emacs executable was installed.
218 (let* ((instdir (file-name-directory invocation-directory
))
219 (dir1 (expand-file-name "../info/" instdir
))
220 (dir2 (expand-file-name "../../../info/" instdir
)))
221 (cond ((file-exists-p dir1
) (append dirs
(list dir1
)))
222 ((file-exists-p dir2
) (append dirs
(list dir2
)))
225 "Default list of directories to search for Info documentation files.
226 They are searched in the order they are given in the list.
227 Therefore, the directory of Info files that come with Emacs
228 normally should come last (so that local files override standard ones),
229 unless Emacs is installed into a non-standard directory. In the latter
230 case, the directory of Info files that come with Emacs should be
233 Once Info is started, the list of directories to search
234 comes from the variable `Info-directory-list'.
235 This variable `Info-default-directory-list' is used as the default
236 for initializing `Info-directory-list' when Info is started, unless
237 the environment variable INFOPATH is set.
239 Although this is a customizable variable, that is mainly for technical
240 reasons. Normally, you should either set INFOPATH or customize
241 `Info-additional-directory-list', rather than changing this variable."
242 :initialize
'custom-initialize-delay
243 :type
'(repeat directory
)
246 (defvar Info-directory-list nil
247 "List of directories to search for Info documentation files.
248 If nil, meaning not yet initialized, Info uses the environment
249 variable INFOPATH to initialize it, or `Info-default-directory-list'
250 if there is no INFOPATH variable in the environment, or the
251 concatenation of the two if INFOPATH ends with a `path-separator'.
253 When `Info-directory-list' is initialized from the value of
254 `Info-default-directory-list', and Emacs is installed in one of the
255 standard directories, the directory of Info files that come with Emacs
256 is put last (so that local Info files override standard ones).
258 When `Info-directory-list' is initialized from the value of
259 `Info-default-directory-list', and Emacs is not installed in one
260 of the standard directories, the first element of the resulting
261 list is the directory where Emacs installs the Info files that
262 come with it. This is so that Emacs's own manual, which suits the
263 version of Emacs you are using, will always be found first. This
264 is useful when you install an experimental version of Emacs without
265 removing the standard installation.
267 If you want to override the order of directories in
268 `Info-default-directory-list', set INFOPATH in the environment.
270 If you run the Emacs executable from the `src' directory in the Emacs
271 source tree, and INFOPATH is not defined, the `info' directory in the
272 source tree is used as the first element of `Info-directory-list', in
273 place of the installation Info directory. This is useful when you run
274 a version of Emacs without installing it.")
276 (defcustom Info-additional-directory-list nil
277 "List of additional directories to search for Info documentation files.
278 These directories are searched after those in `Info-directory-list'."
279 :type
'(repeat directory
)
282 (defcustom Info-scroll-prefer-subnodes nil
283 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
285 If this is non-nil, and you scroll far enough in a node that its menu
286 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
287 moves to a subnode indicated by the following menu item. This means
288 that you visit a subnode before getting to the end of the menu.
290 Setting this option to nil results in behavior similar to the stand-alone
291 Info reader program, which visits the first subnode from the menu only
292 when you hit the end of the current node."
297 (defcustom Info-hide-note-references t
298 "If non-nil, hide the tag and section reference in *note and * menu items.
299 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
300 If value is non-nil but not t or `hide', the reference section is still shown.
301 nil completely disables this feature. If this is non-nil, you might
302 want to set `Info-refill-paragraphs'."
304 :type
'(choice (const :tag
"No hiding" nil
)
305 (const :tag
"Replace tag and hide reference" t
)
306 (const :tag
"Hide tag and reference" hide
)
307 (other :tag
"Only replace tag" tag
))
308 :set
(lambda (sym val
)
310 (dolist (buffer (buffer-list))
311 (with-current-buffer buffer
312 (when (eq major-mode
'Info-mode
)
313 (revert-buffer t t
)))))
316 (defcustom Info-refill-paragraphs nil
317 "If non-nil, attempt to refill paragraphs with hidden references.
318 This refilling may accidentally remove explicit line breaks in the Info
319 file, so be prepared for a few surprises if you enable this feature.
320 This only has an effect if `Info-hide-note-references' is non-nil."
325 (defcustom Info-breadcrumbs-depth
4
326 "Depth of breadcrumbs to display.
327 0 means do not display breadcrumbs."
332 (defcustom Info-search-whitespace-regexp
"\\s-+"
333 "If non-nil, regular expression to match a sequence of whitespace chars.
334 This applies to Info search for regular expressions.
335 You might want to use something like \"[ \\t\\r\\n]+\" instead.
336 In the Customization buffer, that is `[' followed by a space,
337 a tab, a carriage return (control-M), a newline, and `]+'."
341 (defcustom Info-isearch-search t
342 "If non-nil, isearch in Info searches through multiple nodes.
343 Before leaving the initial Info node, where isearch was started,
344 it fails once with the error message [end of node], and with
345 subsequent C-s/C-r continues through other nodes without failing
346 with this error message in other nodes. When isearch fails for
347 the rest of the manual, it displays the error message [end of manual],
348 wraps around the whole manual and restarts the search from the top/final
349 node depending on search direction.
351 Setting this option to nil restores the default isearch behavior
352 with wrapping around the current Info node."
357 (defvar Info-isearch-initial-node nil
)
358 (defvar Info-isearch-initial-history nil
)
359 (defvar Info-isearch-initial-history-list nil
)
361 (defcustom Info-mode-hook
362 ;; Try to obey obsolete Info-fontify settings.
363 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
364 '(turn-on-font-lock))
365 "Hook run when activating Info Mode."
369 (defcustom Info-selection-hook nil
370 "Hook run when an Info node is selected as the current node."
374 (defvar Info-edit-mode-hook nil
375 "Hook run when `Info-edit-mode' is activated.")
377 (make-obsolete-variable 'Info-edit-mode-hook
378 "editing Info nodes by hand is not recommended." "24.4")
380 (defvar-local Info-current-file nil
381 "Info file that Info is now looking at, or nil.
382 This is the name that was specified in Info, not the actual file name.
383 It doesn't contain directory names or file name extensions added by Info.")
385 (defvar-local Info-current-subfile nil
386 "Info subfile that is actually in the *info* buffer now.
387 It is nil if current Info file is not split into subfiles.")
389 (defvar-local Info-current-node nil
390 "Name of node that Info is now looking at, or nil.")
392 (defvar-local Info-tag-table-marker nil
393 "Marker pointing at beginning of current Info file's tag table.
394 Marker points nowhere if file has no tag table.")
396 (defvar-local Info-tag-table-buffer nil
397 "Buffer used for indirect tag tables.")
399 (defvar-local Info-current-file-completions nil
400 "Cached completion list for current Info file.")
402 (defvar Info-file-completions nil
403 "Cached completion alist of visited Info files.
404 Each element of the alist is (FILE . COMPLETIONS)")
406 (defvar-local Info-file-supports-index-cookies nil
407 "Non-nil if current Info file supports index cookies.")
409 (defvar Info-file-supports-index-cookies-list nil
410 "List of Info files with information about index cookies support.
411 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
412 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
414 (defvar-local Info-index-alternatives nil
415 "List of possible matches for last `Info-index' command.")
417 (defvar Info-point-loc nil
418 "Point location within a selected node.
419 If string, the point is moved to the proper occurrence of the
420 name of the followed cross reference within a selected node.
421 If number, the point is moved to the corresponding line.")
423 (defvar Info-standalone nil
424 "Non-nil if Emacs was started solely as an Info browser.")
426 (defvar Info-file-attributes nil
427 "Alist of file attributes of visited Info files.
428 Each element is a list (FILE-NAME FILE-ATTRIBUTES...).")
430 (defvar Info-toc-nodes nil
431 "Alist of cached parent-children node information in visited Info files.
432 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
433 where PARENT is the parent node extracted from the Up pointer,
434 SECTION is the section name in the Top node where this node is placed,
435 CHILDREN is a list of child nodes extracted from the node menu.")
437 (defvar Info-index-nodes nil
438 "Alist of cached index node names of visited Info files.
439 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
441 (defvar Info-virtual-files nil
442 "List of definitions of virtual Info files.
443 Each element of the list has the form (FILENAME (OPERATION . HANDLER) EXTRA)
444 where FILENAME is a regexp that matches a class of virtual Info file names,
445 it should be carefully chosen to not cause file name clashes with
447 OPERATION is one of the symbols `find-file', `find-node', `toc-nodes';
448 and HANDLER is a function to call when OPERATION is invoked on a
450 EXTRA, if present, is one or more cons cells specifying extra
451 attributes important to some applications which use this data.
452 For example, desktop saving and desktop restoring use the `slow'
453 attribute to avoid restoration of nodes that could be expensive
456 (defvar Info-virtual-nodes nil
457 "List of definitions of virtual Info nodes.
458 Each element of the list has the form (NODENAME (OPERATION . HANDLER) EXTRA)
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
462 OPERATION is the symbol `find-node';
463 and HANDLER is a function to call when OPERATION is invoked on a
465 EXTRA, if present, is one or more cons cells specifying extra
466 attributes important to some applications which use this data.
467 For example, desktop saving and desktop restoring use the `slow'
468 attribute to avoid restoration of nodes that could be expensive
471 (defvar-local Info-current-node-virtual nil
472 "Non-nil if the current Info node is virtual.")
474 (defun Info-virtual-file-p (filename)
475 "Check if Info file FILENAME is virtual."
476 (Info-virtual-fun 'find-file filename nil
))
478 (defun Info-virtual-fun (op filename nodename
)
479 "Find a function that handles operations on virtual manuals.
480 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
481 FILENAME is a virtual Info file name, NODENAME is a virtual Info
482 node name. Return a function found either in `Info-virtual-files'
483 or `Info-virtual-nodes'."
484 (or (and (stringp filename
) ; some legacy code can still use a symbol
485 (cdr-safe (assoc op
(assoc-default filename
488 (and (stringp nodename
) ; some legacy code can still use a symbol
489 (cdr-safe (assoc op
(assoc-default nodename
493 (defun Info-virtual-call (virtual-fun &rest args
)
494 "Call a function that handles operations on virtual manuals."
495 (when (functionp virtual-fun
)
496 (or (apply virtual-fun args
) t
)))
499 (defvar Info-suffix-list
500 ;; The MS-DOS list should work both when long file names are
501 ;; supported (Windows 9X), and when only 8+3 file names are available.
502 (if (eq system-type
'ms-dos
)
503 '( (".gz" .
"gunzip")
505 (".bz2" .
("bzip2" "-dc"))
508 (".info.Z" .
"gunzip")
509 (".info.gz" .
"gunzip")
510 ("-info.Z" .
"gunzip")
511 ("-info.gz" .
"gunzip")
512 ("/index.gz" .
"gunzip")
513 ("/index.z" .
"gunzip")
519 '( (".info.Z" .
"uncompress")
520 (".info.Y" .
"unyabba")
521 (".info.gz" .
"gunzip")
522 (".info.z" .
"gunzip")
523 (".info.bz2" .
("bzip2" "-dc"))
524 (".info.xz" .
"unxz")
526 ("-info.Z" .
"uncompress")
527 ("-info.Y" .
"unyabba")
528 ("-info.gz" .
"gunzip")
529 ("-info.bz2" .
("bzip2" "-dc"))
530 ("-info.z" .
"gunzip")
531 ("-info.xz" .
"unxz")
533 ("/index.Z" .
"uncompress")
534 ("/index.Y" .
"unyabba")
535 ("/index.gz" .
"gunzip")
536 ("/index.z" .
"gunzip")
537 ("/index.bz2" .
("bzip2" "-dc"))
538 ("/index.xz" .
"unxz")
540 (".Z" .
"uncompress")
544 (".bz2" .
("bzip2" "-dc"))
547 "List of file name suffixes and associated decoding commands.
548 Each entry should be (SUFFIX . STRING); the file is given to
549 the command as standard input.
551 STRING may be a list of strings. In that case, the first element is
552 the command name, and the rest are arguments to that command.
554 If STRING is nil, no decoding is done.
555 Because the SUFFIXes are tried in order, the empty string should
556 be last in the list.")
558 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
559 ;; First, on MS-DOS with no long file names support, delete some of
560 ;; the extension in FILENAME to make room.
561 (defun info-insert-file-contents-1 (filename suffix lfn
)
562 (if lfn
; long file names are supported
563 (concat filename suffix
)
564 (let* ((sans-exts (file-name-sans-extension filename
))
565 ;; How long is the extension in FILENAME (not counting the dot).
566 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
568 ;; SUFFIX starts with a dot. If FILENAME already has one,
569 ;; get rid of the one in SUFFIX (unless suffix is empty).
570 (or (and (<= ext-len
0)
571 (not (eq (aref filename
(1- (length filename
))) ?.
)))
572 (= (length suffix
) 0)
573 (setq suffix
(substring suffix
1)))
574 ;; How many chars of that extension should we keep?
575 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
576 ;; Get rid of the rest of the extension, and add SUFFIX.
577 (concat (substring filename
0 (- (length filename
)
578 (- ext-len ext-left
)))
581 (defun info-file-exists-p (filename)
582 (and (file-exists-p filename
)
583 (not (file-directory-p filename
))))
585 (defun info-insert-file-contents (filename &optional visit
)
586 "Insert the contents of an Info file in the current buffer.
587 Do the right thing if the file has been compressed or zipped."
588 (let* ((tail Info-suffix-list
)
589 (jka-compr-verbose nil
)
590 (lfn (if (fboundp 'msdos-long-file-names
)
591 (msdos-long-file-names)
593 (check-short (and (fboundp 'msdos-long-file-names
)
595 fullname decoder done
)
596 (if (info-file-exists-p filename
)
597 ;; FILENAME exists--see if that name contains a suffix.
598 ;; If so, set DECODE accordingly.
602 (concat (regexp-quote (car (car tail
))) "$")
604 (setq tail
(cdr tail
)))
605 (setq fullname filename
606 decoder
(cdr (car tail
))))
607 ;; Try adding suffixes to FILENAME and see if we can find something.
608 (while (and tail
(not done
))
609 (setq fullname
(info-insert-file-contents-1 filename
610 (car (car tail
)) lfn
))
611 (if (info-file-exists-p fullname
)
613 ;; If we found a file with a suffix, set DECODER
614 ;; according to the suffix.
615 decoder
(cdr (car tail
)))
616 ;; When the MS-DOS port runs on Windows, we need to check
617 ;; the short variant of a long file name as well.
619 (setq fullname
(info-insert-file-contents-1 filename
620 (car (car tail
)) nil
))
621 (if (info-file-exists-p fullname
)
623 decoder
(cdr (car tail
))))))
624 (setq tail
(cdr tail
)))
626 (error "Can't find %s or any compressed version of it" filename
)))
627 ;; check for conflict with jka-compr
628 (if (and (jka-compr-installed-p)
629 (jka-compr-get-compression-info fullname
))
633 (insert-file-contents-literally fullname visit
)
634 (let ((inhibit-read-only t
)
635 (coding-system-for-write 'no-conversion
)
636 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
637 (default-directory (or (file-name-directory fullname
)
640 (setq decoder
(list decoder
)))
641 (apply #'call-process-region
(point-min) (point-max)
642 (car decoder
) t t nil
(cdr decoder
))))
643 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
644 (insert-file-contents fullname visit
)))
646 ;; Clear the caches of modified Info files.
647 (let* ((attribs-old (cdr (assoc fullname Info-file-attributes
)))
648 (modtime-old (and attribs-old
(nth 5 attribs-old
)))
649 (attribs-new (and (stringp fullname
) (file-attributes fullname
)))
650 (modtime-new (and attribs-new
(nth 5 attribs-new
))))
651 (when (and modtime-old modtime-new
652 (time-less-p modtime-old modtime-new
))
653 (setq Info-index-nodes
(remove (assoc (or Info-current-file filename
)
656 (setq Info-toc-nodes
(remove (assoc (or Info-current-file filename
)
659 ;; Add new modtime to `Info-file-attributes'.
660 (setq Info-file-attributes
661 (cons (cons fullname attribs-new
)
662 (remove (assoc fullname Info-file-attributes
)
663 Info-file-attributes
))))))
665 (defun Info-file-supports-index-cookies (&optional file
)
666 "Return non-nil value if FILE supports Info index cookies.
667 Info index cookies were first introduced in 4.7, and all later
668 makeinfo versions output them in index nodes, so we can rely
669 solely on the makeinfo version. This function caches the information
670 in `Info-file-supports-index-cookies-list'."
671 (or file
(setq file Info-current-file
))
672 (or (assoc file Info-file-supports-index-cookies-list
)
673 ;; Skip virtual Info files
674 (and (or (not (stringp file
))
675 (Info-virtual-file-p file
))
676 (setq Info-file-supports-index-cookies-list
677 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
680 (goto-char (point-min))
682 (if (and (re-search-forward
683 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
684 (line-beginning-position 4) t
)
685 (not (version< (match-string 1) "4.7")))
688 (setq Info-file-supports-index-cookies-list
689 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
690 (cdr (assoc file Info-file-supports-index-cookies-list
)))
693 (defun Info-default-dirs ()
694 (let ((source (expand-file-name "info/" source-directory
))
695 (sibling (if installation-directory
696 (expand-file-name "info/" installation-directory
)
697 (if invocation-directory
698 (let ((infodir (expand-file-name
700 invocation-directory
)))
701 (if (file-exists-p infodir
)
703 (setq infodir
(expand-file-name
704 "../../../share/info/"
705 invocation-directory
))
706 (and (file-exists-p infodir
)
710 (if (and sibling
(file-exists-p sibling
))
711 ;; Uninstalled, Emacs builddir != srcdir.
713 ;; Uninstalled, builddir == srcdir
715 (if (or (member alternative Info-default-directory-list
)
716 ;; On DOS/NT, we use movable executables always,
717 ;; and we must always find the Info dir at run time.
718 (if (memq system-type
'(ms-dos windows-nt
))
720 ;; Use invocation-directory for Info
721 ;; only if we used it for exec-directory also.
722 (not (string= exec-directory
723 (expand-file-name "lib-src/"
724 installation-directory
))))
725 (not (file-exists-p alternative
)))
726 Info-default-directory-list
727 ;; `alternative' contains the Info files that came with this
728 ;; version, so we should look there first. `Info-insert-dir'
729 ;; currently expects to find `alternative' first on the list.
731 ;; Don't drop the last part, it might contain non-Emacs stuff.
732 ;; (reverse (cdr (reverse
733 Info-default-directory-list
)))) ;; )))
735 (defun info-initialize ()
736 "Initialize `Info-directory-list', if that hasn't been done yet."
737 (unless Info-directory-list
738 (let ((path (getenv "INFOPATH"))
739 (sep (regexp-quote path-separator
)))
740 (setq Info-directory-list
741 (prune-directory-list
743 (if (string-match-p (concat sep
"\\'") path
)
744 (append (split-string (substring path
0 -
1) sep
)
746 (split-string path sep
))
747 (Info-default-dirs))))
748 ;; For a self-contained (ie relocatable) NS build, AFAICS we
749 ;; always want the included info directory to be at the head of
750 ;; the search path, unless it's already in INFOPATH somewhere.
751 ;; It's at the head of Info-default-directory-list,
752 ;; but there's no way to get it at the head of Info-directory-list
753 ;; except by doing it here.
756 (let ((dir (expand-file-name "../info" data-directory
)))
757 (and (file-directory-p dir
)
758 (not (member dir
(split-string path
":" t
)))
759 (push dir Info-directory-list
)))))))
762 (defun info-other-window (&optional file-or-node buffer
)
763 "Like `info' but show the Info buffer in another window."
765 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
766 (read-file-name "Info file name: " nil nil t
))
767 (if (numberp current-prefix-arg
)
768 (format "*info*<%s>" current-prefix-arg
))))
769 (info-setup file-or-node
770 (switch-to-buffer-other-window (or buffer
"*info*"))))
772 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
774 (defun info (&optional file-or-node buffer
)
775 "Enter Info, the documentation browser.
776 Optional argument FILE-OR-NODE specifies the file to examine;
777 the default is the top-level directory of Info.
778 Called from a program, FILE-OR-NODE may specify an Info node of the form
779 \"(FILENAME)NODENAME\".
780 Optional argument BUFFER specifies the Info buffer name;
781 the default buffer name is *info*. If BUFFER exists,
782 just switch to BUFFER. Otherwise, create a new buffer
783 with the top-level Info directory.
785 In interactive use, a non-numeric prefix argument directs
786 this command to read a file name from the minibuffer.
788 A numeric prefix argument of N selects an Info buffer named \"*info*<N>\".
790 The search path for Info files is in the variable `Info-directory-list'.
791 The top-level Info directory is made by combining all the files named `dir'
792 in all the directories in that path.
794 See a list of available Info commands in `Info-mode'."
796 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
797 (read-file-name "Info file name: " nil nil t
))
798 (if (numberp current-prefix-arg
)
799 (format "*info*<%s>" current-prefix-arg
))))
800 (info-setup file-or-node
801 (pop-to-buffer-same-window (or buffer
"*info*"))))
803 (defun info-setup (file-or-node buffer
)
804 "Display Info node FILE-OR-NODE in BUFFER."
805 (if (and buffer
(not (derived-mode-p 'Info-mode
)))
808 ;; If argument already contains parentheses, don't add another set
809 ;; since the argument will then be parsed improperly. This also
810 ;; has the added benefit of allowing node names to be included
811 ;; following the parenthesized filename.
813 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
815 (concat "(" file-or-node
")")))
816 (if (and (zerop (buffer-size))
818 ;; If we just created the Info buffer, go to the directory.
822 (defun info-emacs-manual ()
823 "Display the Emacs manual in Info mode."
828 (defun info-emacs-bug ()
829 "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
831 (info "(emacs)Bugs"))
834 (defun info-standalone ()
835 "Run Emacs as a standalone Info reader.
836 Usage: emacs -f info-standalone [filename]
837 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
838 (setq Info-standalone t
)
839 (if (and command-line-args-left
840 (not (string-match "^-" (car command-line-args-left
))))
843 (info (car command-line-args-left
))
844 (setq command-line-args-left
(cdr command-line-args-left
)))
845 (error (send-string-to-terminal
846 (format "%s\n" (if (eq (car-safe err
) 'error
)
848 (save-buffers-kill-emacs)))
851 ;; See if the accessible portion of the buffer begins with a node
852 ;; delimiter, and the node header line which follows matches REGEXP.
853 ;; Typically, this test will be followed by a loop that examines the
854 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
855 ;; to have the overhead of this special test inside the loop.
857 ;; This function changes match-data, but supposedly the caller might
858 ;; want to use the results of re-search-backward.
860 ;; The return value is the value of point at the beginning of matching
861 ;; REGEXP, if the function succeeds, nil otherwise.
862 (defun Info-node-at-bob-matching (regexp)
863 (and (bobp) ; are we at beginning of buffer?
864 (looking-at "\^_") ; does it begin with node delimiter?
868 (forward-line 1) ; does the line after delimiter match REGEXP?
869 (re-search-backward regexp beg t
))))
871 (defun Info-find-file (filename &optional noerror
)
872 "Return expanded FILENAME, or t if FILENAME is \"dir\".
873 Optional second argument NOERROR, if t, means if file is not found
874 just return nil (no error)."
875 ;; Convert filename to lower case if not found as specified.
879 (Info-virtual-fun 'find-file filename nil
)
882 (let (temp temp-downcase found
)
883 (setq filename
(substitute-in-file-name filename
))
884 (let ((dirs (if (string-match "^\\./" filename
)
885 ;; If specified name starts with `./'
886 ;; then just try current directory.
888 (if (file-name-absolute-p filename
)
889 ;; No point in searching for an
890 ;; absolute file name
892 (if Info-additional-directory-list
893 (append Info-directory-list
894 Info-additional-directory-list
)
895 Info-directory-list
)))))
896 ;; Fall back on the installation directory if we can't find
897 ;; the info node anywhere else.
898 (when installation-directory
899 (setq dirs
(append dirs
(list (expand-file-name
900 "info" installation-directory
)))))
901 ;; Search the directory list for file FILENAME.
902 (while (and dirs
(not found
))
903 (setq temp
(expand-file-name filename
(car dirs
)))
905 (expand-file-name (downcase filename
) (car dirs
)))
906 ;; Try several variants of specified name.
907 (let ((suffix-list Info-suffix-list
)
908 (lfn (if (fboundp 'msdos-long-file-names
)
909 (msdos-long-file-names)
911 (while (and suffix-list
(not found
))
912 (cond ((info-file-exists-p
913 (info-insert-file-contents-1
914 temp
(car (car suffix-list
)) lfn
))
917 (info-insert-file-contents-1
918 temp-downcase
(car (car suffix-list
)) lfn
))
919 (setq found temp-downcase
))
920 ((and (fboundp 'msdos-long-file-names
)
923 (info-insert-file-contents-1
924 temp
(car (car suffix-list
)) nil
)))
926 (setq suffix-list
(cdr suffix-list
))))
927 (setq dirs
(cdr dirs
))))
929 (setq filename found
)
932 ;; If there is no previous Info file, go to the directory.
933 (unless Info-current-file
935 (user-error "Info file %s does not exist" filename
)))
938 (defun Info-find-node (filename nodename
&optional no-going-back strict-case
)
939 "Go to an Info node specified as separate FILENAME and NODENAME.
940 NO-GOING-BACK is non-nil if recovering from an error in this function;
941 it says do not attempt further (recursive) error recovery.
943 This function first looks for a case-sensitive match for NODENAME;
944 if none is found it then tries a case-insensitive match (unless
945 STRICT-CASE is non-nil)."
947 (setq filename
(Info-find-file filename
))
948 ;; Go into Info buffer.
949 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
950 ;; Record the node we are leaving, if we were in one.
951 (and (not no-going-back
)
953 (push (list Info-current-file Info-current-node
(point))
955 (Info-find-node-2 filename nodename no-going-back strict-case
))
958 (defun Info-on-current-buffer (&optional nodename
)
959 "Use Info mode to browse the current Info buffer.
960 With a prefix arg, this queries for the node name to visit first;
961 otherwise, that defaults to `Top'."
963 (list (if current-prefix-arg
964 (completing-read "Node name: " (Info-build-node-completions)
966 (unless nodename
(setq nodename
"Top"))
969 (setq Info-current-file
971 ;; If called on a non-file buffer, make a fake file name.
972 (concat default-directory
(buffer-name))))
973 (Info-find-node-2 nil nodename
))
975 (defun Info-revert-find-node (filename nodename
)
976 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
977 When *info* is already displaying FILENAME and NODENAME, the window position
978 is preserved, if possible."
979 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
980 (let ((old-filename Info-current-file
)
981 (old-nodename Info-current-node
)
982 (window-selected (eq (selected-window) (get-buffer-window)))
983 (pcolumn (current-column))
984 (pline (count-lines (point-min) (line-beginning-position)))
985 (wline (count-lines (point-min) (window-start)))
986 (new-history (and Info-current-file
987 (list Info-current-file Info-current-node
(point)))))
988 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
989 (setq Info-current-file nil
)
990 (Info-find-node filename nodename
)
991 (if (and (equal old-filename Info-current-file
)
992 (equal old-nodename Info-current-node
))
994 ;; note goto-line is no good, we want to measure from point-min
995 (when window-selected
996 (goto-char (point-min))
998 (set-window-start (selected-window) (point)))
999 (goto-char (point-min))
1000 (forward-line pline
)
1001 (move-to-column pcolumn
))
1002 ;; only add to the history when coming from a different file+node
1004 (setq Info-history
(cons new-history Info-history
))))))
1006 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
1007 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
1008 (Info-revert-find-node Info-current-file Info-current-node
)
1009 (message "Reverted %s" Info-current-file
)))
1011 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
1012 "Find a node in a tag table.
1013 MARKER specifies the buffer and position to start searching at.
1014 REGEXP is a regular expression matching nodes or references. Its first
1015 group should match `Node:' or `Ref:'.
1016 CASE-FOLD t means search for a case-insensitive match.
1017 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1018 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the file position
1019 where the match was found, and MODE is `major-mode' of the buffer in
1020 which the match was found."
1021 (let ((case-fold-search case-fold
))
1022 (with-current-buffer (marker-buffer marker
)
1027 (when (re-search-forward regexp nil t
)
1028 (list (string-equal "Ref:" (match-string 1))
1029 (read (current-buffer))
1032 (defun Info-find-in-tag-table (marker regexp
&optional strict-case
)
1033 "Find a node in a tag table.
1034 MARKER specifies the buffer and position to start searching at.
1035 REGEXP is a regular expression matching nodes or references. Its first
1036 group should match `Node:' or `Ref:'.
1037 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1038 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the file position
1039 where the match was found, and MODE is `major-mode' of the buffer in
1040 which the match was found.
1041 This function tries to find a case-sensitive match first, then a
1042 case-insensitive match is tried (unless optional argument STRICT-CASE
1044 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
1045 (or strict-case
(car result
)
1046 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
1049 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
1050 "Find a node or anchor in the current buffer.
1051 REGEXP is a regular expression matching nodes or references. Its first
1052 group should match `Node:' or `Ref:'.
1053 CASE-FOLD t means search for a case-insensitive match.
1054 Value is the position at which a match was found, or nil if not found."
1055 (let ((case-fold-search case-fold
)
1058 (if (Info-node-at-bob-matching regexp
)
1059 (setq found
(point))
1060 (while (and (not found
)
1061 (search-forward "\n\^_" nil t
))
1063 (let ((beg (point)))
1065 (if (re-search-backward regexp beg t
)
1066 (setq found
(line-beginning-position)))))))
1069 (defun Info-find-node-in-buffer (regexp &optional strict-case
)
1070 "Find a node or anchor in the current buffer.
1071 REGEXP is a regular expression matching nodes or references. Its first
1072 group should match `Node:' or `Ref:'.
1073 Value is the position at which a match was found, or nil if not found.
1074 This function looks for a case-sensitive match first. If none is found,
1075 a case-insensitive match is tried (unless optional argument STRICT-CASE
1077 (or (Info-find-node-in-buffer-1 regexp nil
)
1078 (and (not strict-case
)
1079 (Info-find-node-in-buffer-1 regexp t
))))
1081 (defun Info-find-node-2 (filename nodename
&optional no-going-back strict-case
)
1082 (buffer-disable-undo (current-buffer))
1083 (or (derived-mode-p 'Info-mode
)
1086 (setq Info-current-node nil
)
1088 (let ((case-fold-search t
)
1089 (virtual-fun (Info-virtual-fun 'find-node
1090 (or filename Info-current-file
)
1094 ((functionp virtual-fun
)
1095 (let ((filename (or filename Info-current-file
)))
1096 (setq buffer-read-only nil
)
1097 (setq Info-current-file filename
1098 Info-current-subfile nil
1099 Info-current-file-completions nil
1100 buffer-file-name nil
)
1102 (Info-virtual-call virtual-fun filename nodename no-going-back
)
1103 (set-marker Info-tag-table-marker nil
)
1104 (setq buffer-read-only t
)
1105 (set-buffer-modified-p nil
)
1106 (setq Info-current-node-virtual t
)))
1108 ;; Reread a file when moving from a virtual node.
1109 (not Info-current-node-virtual
)
1111 (equal Info-current-file filename
))))
1112 ;; Switch files if necessary
1113 (let ((inhibit-read-only t
))
1114 (when Info-current-node-virtual
1115 ;; When moving from a virtual node.
1116 (setq Info-current-node-virtual nil
)
1118 (setq filename Info-current-file
)))
1119 (setq Info-current-file nil
1120 Info-current-subfile nil
1121 Info-current-file-completions nil
1122 buffer-file-name nil
)
1124 ;; Erase any memory of the previous coding-system, so that
1125 ;; info-insert-file-contents sets the buffer's encoding to
1126 ;; what the Info file specifies.
1127 (set-buffer-file-coding-system 'undecided t
)
1128 (info-insert-file-contents filename nil
)
1129 (setq default-directory
(file-name-directory filename
))
1130 (set-buffer-modified-p nil
)
1131 (setq Info-file-supports-index-cookies
1132 (Info-file-supports-index-cookies filename
))
1134 ;; See whether file has a tag table. Record the location if yes.
1135 (goto-char (point-max))
1137 ;; Use string-equal, not equal, to ignore text props.
1138 (if (not (or (string-equal nodename
"*")
1140 (search-forward "\^_\nEnd tag table\n" nil t
))))
1142 ;; We have a tag table. Find its beginning.
1143 ;; Is this an indirect file?
1144 (search-backward "\nTag table:\n")
1148 (looking-at "(Indirect)\n"))
1149 ;; It is indirect. Copy it to another buffer
1150 ;; and record that the tag table is in that buffer.
1151 (let ((buf (current-buffer))
1153 (or Info-tag-table-buffer
1154 (generate-new-buffer " *info tag table*"))))
1155 (setq Info-tag-table-buffer tagbuf
)
1156 (with-current-buffer tagbuf
1157 (buffer-disable-undo (current-buffer))
1158 (setq case-fold-search t
)
1160 (insert-buffer-substring buf
))
1161 (set-marker Info-tag-table-marker
1162 (match-end 0) tagbuf
))
1163 (set-marker Info-tag-table-marker pos
)))
1164 (set-marker Info-tag-table-marker nil
))
1165 (setq Info-current-file filename
)
1168 ;; Use string-equal, not equal, to ignore text props.
1169 (if (string-equal nodename
"*")
1170 (progn (setq Info-current-node nodename
)
1171 (Info-set-mode-line))
1174 ;; 1. Anchor found in tag table
1175 ;; 2. Anchor *not* in tag table
1177 ;; 3. Node found in tag table
1178 ;; 4. Node *not* found in tag table, but found in file
1179 ;; 5. Node *not* in tag table, and *not* in file
1181 ;; *Or* the same, but in an indirect subfile.
1183 ;; Search file for a suitable node.
1184 (let ((guesspos (point-min))
1185 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1186 (if (stringp nodename
)
1187 (regexp-quote nodename
)
1189 "\\) *[,\t\n\177]")))
1193 ;; First, search a tag table, if any
1194 (when (marker-position Info-tag-table-marker
)
1195 (let* ((m Info-tag-table-marker
)
1196 (found (Info-find-in-tag-table m regexp strict-case
)))
1199 ;; FOUND is (ANCHOR POS MODE).
1200 (let ((filepos (nth 1 found
))) ;File position in bytes.
1202 ;; If this is an indirect file, determine which
1203 ;; file really holds this node and read it in.
1204 (unless (eq (nth 2 found
) 'Info-mode
)
1205 ;; Note that the current buffer must be the
1206 ;; *info* buffer on entry to
1207 ;; Info-read-subfile. Thus the hackery above.
1208 (setq filepos
(Info-read-subfile filepos
)))
1211 (filepos-to-bufferpos filepos
'approximate
)))
1215 (goto-char (setq anchorpos guesspos
))
1218 ;; Else we may have a node, which we search for:
1219 (goto-char (max (point-min) (- guesspos
1000)))
1221 ;; Now search from our advised position (or from beg of
1222 ;; buffer) to find the actual node. First, check
1223 ;; whether the node is right where we are, in case the
1224 ;; buffer begins with a node.
1225 (let ((pos (Info-find-node-in-buffer regexp strict-case
)))
1230 ;; If the Texinfo source had an @ifnottex block of text
1231 ;; before the Top node, makeinfo 5.0 and 5.1 mistakenly
1232 ;; omitted that block's size from the starting position
1233 ;; of the 1st subfile, which makes GUESSPOS overshoot
1234 ;; the correct position by the length of that text. So
1235 ;; we try again with a larger slop.
1236 (goto-char (max (point-min) (- guesspos
10000)))
1237 (let ((pos (Info-find-node-in-buffer regexp strict-case
)))
1242 (when (string-match "\\([^.]+\\)\\." nodename
)
1243 (let (Info-point-loc)
1245 filename
(match-string 1 nodename
) no-going-back
))
1249 ;; No such anchor in tag table or node in tag table or file
1250 (user-error "No such node or anchor: %s" nodename
))
1253 (goto-char (point-min))
1254 (forward-line 1) ; skip header line
1255 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1256 ;; (forward-line 1))
1259 (let ((new-history (list Info-current-file
1260 (substring-no-properties nodename
))))
1261 ;; Add anchors to the history too
1262 (setq Info-history-list
1264 (remove new-history Info-history-list
))))
1265 (goto-char anchorpos
))
1266 ((numberp Info-point-loc
)
1267 (forward-line (- Info-point-loc
2))
1268 (setq Info-point-loc nil
))
1269 ((stringp Info-point-loc
)
1270 (Info-find-index-name Info-point-loc
)
1271 (setq Info-point-loc nil
))))))
1272 ;; If we did not finish finding the specified node,
1273 ;; go back to the previous one or to the Top node.
1274 (unless (or Info-current-node no-going-back
)
1276 (let ((hist (car Info-history
)))
1277 (setq Info-history
(cdr Info-history
))
1278 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1279 (goto-char (nth 2 hist
)))
1280 (Info-find-node Info-current-file
"Top" t
)))))
1282 ;; Cache the contents of the (virtual) dir file, once we have merged
1283 ;; it for the first time, so we can save time subsequently.
1284 (defvar-local Info-dir-contents nil
)
1286 ;; Cache for the directory we decided to use for the default-directory
1287 ;; of the merged dir text.
1288 (defvar-local Info-dir-contents-directory nil
)
1290 ;; Record the file attributes of all the files from which we
1291 ;; constructed Info-dir-contents.
1292 (defvar-local Info-dir-file-attributes nil
)
1294 (defvar-local Info-dir-file-name nil
)
1296 ;; Construct the Info directory node by merging the files named `dir'
1297 ;; from various directories. Set the *info* buffer's
1298 ;; default-directory to the first directory we actually get any text
1300 (defun Info-insert-dir ()
1301 (if (and Info-dir-contents Info-dir-file-attributes
1302 ;; Verify that none of the files we used has changed
1303 ;; since we used it.
1305 (mapcar (lambda (elt)
1306 (let ((curr (file-attributes
1308 (file-truename (car elt
)))))
1310 ;; Don't compare the access time.
1311 (if curr
(setcar (nthcdr 4 curr
) 0))
1312 (setcar (nthcdr 4 (cdr elt
)) 0)
1313 (equal (cdr elt
) curr
)))
1314 Info-dir-file-attributes
))))
1316 (insert Info-dir-contents
)
1317 (goto-char (point-min)))
1318 (let ((dirs (if Info-additional-directory-list
1319 (append Info-directory-list
1320 Info-additional-directory-list
)
1321 Info-directory-list
))
1322 (dir-file-attrs nil
)
1323 ;; Bind this in case the user sets it to nil.
1324 (case-fold-search t
)
1325 ;; This is set non-nil if we find a problem in some input files.
1327 buffers buffer others nodes dirs-done
)
1329 ;; Search the directory list for the directory file.
1331 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1332 (or (member truename dirs-done
)
1333 (member (directory-file-name truename
) dirs-done
)
1334 ;; Try several variants of specified name.
1335 ;; Try upcasing, appending `.info', or both.
1339 (progn (setq file
(expand-file-name "dir" truename
))
1340 (file-attributes file
))
1341 (progn (setq file
(expand-file-name "DIR" truename
))
1342 (file-attributes file
))
1343 (progn (setq file
(expand-file-name "dir.info" truename
))
1344 (file-attributes file
))
1345 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1346 (file-attributes file
))
1347 ;; Shouldn't really happen, but sometimes does,
1348 ;; eg on Debian systems with buggy packages;
1349 ;; so may as well try it.
1350 ;; https://lists.gnu.org/r/emacs-devel/2012-03/msg00005.html
1351 (progn (setq file
(expand-file-name "dir.gz" truename
))
1352 (file-attributes file
)))))
1355 (cons (directory-file-name truename
)
1358 (with-current-buffer (generate-new-buffer " info dir")
1360 (message "Composing main Info directory..."))
1362 ;; Index nodes include null bytes. DIR
1363 ;; files should not have indices, but who
1365 (let ((inhibit-null-byte-detection t
))
1366 (insert-file-contents file
)
1367 (setq Info-dir-file-name file
)
1368 (push (current-buffer) buffers
)
1369 (push (cons file attrs
) dir-file-attrs
))
1370 (error (kill-buffer (current-buffer))))))))
1372 (setq Info-dir-contents-directory
1373 (file-name-as-directory (car dirs
))))
1374 (setq dirs
(cdr dirs
))))
1377 (error "Can't find the Info directory node"))
1379 ;; Distinguish the dir file that comes with Emacs from all the
1380 ;; others. Yes, that is really what this is supposed to do.
1381 ;; The definition of `Info-directory-list' puts it first on that
1382 ;; list and so last in `buffers' at this point.
1383 (setq buffer
(car (last buffers
))
1384 others
(delq buffer buffers
))
1386 ;; Insert the entire original dir file as a start; note that we've
1387 ;; already saved its default directory to use as the default
1388 ;; directory for the whole concatenation.
1389 (save-excursion (insert-buffer-substring buffer
))
1391 ;; Look at each of the other buffers one by one.
1392 (dolist (other others
)
1393 (let (this-buffer-nodes)
1394 ;; In each, find all the menus.
1395 (with-current-buffer other
1396 (goto-char (point-min))
1397 ;; Find each menu, and add an elt to NODES for it.
1398 (while (re-search-forward "^\\* Menu:" nil t
)
1399 (while (and (zerop (forward-line 1)) (eolp)))
1402 (re-search-backward "^\^_")
1403 (search-forward "Node: ")
1404 (setq nodename
(Info-following-node-name))
1405 (search-forward "\n\^_" nil
'move
)
1408 (push (list nodename other beg end
) this-buffer-nodes
)))
1409 (if (assoc-string "top" this-buffer-nodes t
)
1410 (setq nodes
(nconc this-buffer-nodes nodes
))
1412 (message "No `top' node in %s" Info-dir-file-name
)))))
1413 ;; Add to the main menu a menu item for each other node.
1414 (re-search-forward "^\\* Menu:")
1416 (let ((menu-items '("top"))
1417 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1418 (dolist (node nodes
)
1419 (let ((nodename (car node
)))
1421 (or (member (downcase nodename
) menu-items
)
1422 (re-search-forward (concat "^\\* +"
1423 (regexp-quote nodename
)
1427 (insert "* " nodename
"::" "\n")
1428 (push nodename menu-items
)))))))
1429 ;; Now take each node of each of the other buffers
1430 ;; and merge it into the main buffer.
1431 (dolist (node nodes
)
1432 (let ((case-fold-search t
)
1433 (nodename (car node
)))
1434 (goto-char (point-min))
1435 ;; Find the like-named node in the main buffer.
1436 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1437 (regexp-quote nodename
)
1441 (search-forward "\n\^_" nil
'move
)
1444 ;; If none exists, add one.
1445 (goto-char (point-max))
1446 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1447 ;; Merge the text from the other buffer's menu
1448 ;; into the menu in the like-named node in the main buffer.
1449 (apply #'insert-buffer-substring
(cdr node
))))
1450 (Info-dir-remove-duplicates)
1451 ;; Kill all the buffers we just made, including the special one excised.
1452 (mapc #'kill-buffer
(cons buffer buffers
))
1453 (goto-char (point-min))
1455 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1456 (message "Composing main Info directory...done"))
1457 (setq Info-dir-contents
(buffer-string))
1458 (setq Info-dir-file-attributes dir-file-attrs
)))
1459 (setq default-directory Info-dir-contents-directory
))
1461 (defvar Info-streamline-headings
1462 '(("Emacs" .
"Emacs")
1463 ("Programming" .
"Programming")
1464 ("Libraries" .
"Libraries")
1465 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1466 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1468 (defun Info-dir-remove-duplicates ()
1470 (goto-char (point-min))
1471 ;; Remove duplicate headings in the same menu.
1472 (while (search-forward "\n* Menu:" nil t
)
1473 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1474 ;; Look for the next heading to unify.
1475 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1476 (let ((name (match-string 1))
1477 (start (match-beginning 0))
1479 ;; Check whether this heading should be streamlined.
1481 (dolist (x Info-streamline-headings
)
1482 (when (string-match (car x
) name
)
1484 (setq re
(car x
)))))
1485 (if re
(replace-match name t t nil
1))
1486 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1488 (or limit
(point-max))))
1489 ;; Look for other headings of the same category and merge them.
1491 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1492 (when (if re
(save-match-data (string-match re
(match-string 1)))
1493 (equal name
(match-string 1)))
1495 ;; Delete redundant heading.
1496 (delete-region (match-beginning 0) (point))
1497 ;; Push the entries onto `text'.
1499 (delete-and-extract-region
1501 (if (re-search-forward "^[^* \n\t]" nil t
)
1503 (or limit
(point-max))))
1506 ;; Insert the entries just found.
1507 (while (= (line-beginning-position 0) (1- (point)))
1509 (dolist (entry (nreverse entries
))
1511 (while (= (line-beginning-position 0) (1- (point)))
1512 (delete-region (1- (point)) (point))))
1514 ;; Now remove duplicate entries under the same heading.
1517 (narrow-to-region start
(point))
1518 (goto-char (point-min))
1519 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1520 ;; Fold case straight away; `member-ignore-case' here wasteful.
1521 (let ((x (downcase (match-string 1))))
1525 (if (re-search-forward "^[^ \t]" nil
'move
)
1526 (goto-char (match-beginning 0))
1528 (push x seen
)))))))))))
1530 ;; Note that on entry to this function the current-buffer must be the
1531 ;; *info* buffer; not the info tags buffer.
1532 (defun Info-read-subfile (nodepos)
1533 ;; NODEPOS is either a position in bytes (in the Info file as a whole,
1534 ;; not relative to a subfile) or the name of a subfile.
1537 (if (numberp nodepos
)
1538 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1539 (goto-char (point-min))
1540 (or (looking-at "\^_")
1541 (search-forward "\n\^_"))
1544 (while (not (looking-at "\^_"))
1547 thisfilepos thisfilename
)
1548 (search-forward ": ")
1549 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1550 (setq thisfilepos
(read (current-buffer)))
1551 ;; read in version 19 stops at the end of number.
1552 ;; Advance to the next line.
1554 (if (> thisfilepos nodepos
)
1556 (setq lastfilename thisfilename
)
1557 (setq lastfilepos thisfilepos
))
1558 (forward-line 1)))))
1559 (setq lastfilename nodepos
)
1560 (setq lastfilepos
0))
1561 ;; Assume previous buffer is in Info-mode.
1562 ;; (set-buffer (get-buffer "*info*"))
1563 (or (equal Info-current-subfile lastfilename
)
1564 (let ((inhibit-read-only t
))
1565 (setq buffer-file-name nil
)
1568 (info-insert-file-contents lastfilename
)
1569 (set-buffer-modified-p nil
)
1570 (setq Info-current-subfile lastfilename
)))
1571 ;; Widen in case we are in the same subfile as before.
1573 (goto-char (point-min))
1574 ;; Skip the summary segment for `Info-search'.
1575 (if (looking-at "\^_")
1577 (search-forward "\n\^_"))
1578 (if (numberp nodepos
)
1579 ;; Our caller ('Info-find-node-2') wants the (zero-based) byte
1580 ;; offset corresponding to NODEPOS, from the beginning of the
1581 ;; subfile. This is especially important if NODEPOS is for an
1582 ;; anchor reference, because for those the position is all we
1584 (+ (- nodepos lastfilepos
) (bufferpos-to-filepos (point) 'exact
)))))
1586 (defun Info-unescape-quotes (value)
1587 "Unescape double quotes and backslashes in VALUE."
1590 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1591 (setq unquote
(replace-match "" t t unquote
1))
1592 (setq start
(- (match-end 0) 1)))
1595 ;; As of Texinfo 4.6, makeinfo writes constructs like
1596 ;; \0\h[image param=value ...\h\0]
1597 ;; into the Info file for handling images.
1598 (defun Info-split-parameter-string (parameter-string)
1599 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1600 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1601 If VALUE contains whitespace or double quotes, it must be quoted
1602 in double quotes and any double quotes or backslashes must be
1603 escaped (\\\",\\\\)."
1606 (while (string-match
1607 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1608 parameter-string start
)
1609 (setq start
(match-end 0))
1610 (push (cons (match-string 1 parameter-string
)
1611 (or (match-string 2 parameter-string
)
1612 (Info-unescape-quotes
1613 (match-string 3 parameter-string
))))
1617 (defun Info-node-description (file)
1619 ((equal file
"dir") "*Info Directory*")
1620 ((eq file
'apropos
) "*Info Apropos*")
1621 ((eq file
'history
) "*Info History*")
1622 ((eq file
'toc
) "*Info TOC*")
1623 ((not (stringp file
)) "") ; Avoid errors
1625 (concat "(" (file-name-nondirectory file
) ") " Info-current-node
))))
1627 (defun Info-display-images-node ()
1628 "Display images in current node."
1630 (let ((inhibit-read-only t
)
1631 (case-fold-search t
))
1632 (goto-char (point-min))
1633 (while (re-search-forward
1634 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1636 (let* ((start (match-beginning 1))
1637 (parameter-alist (Info-split-parameter-string (match-string 2)))
1638 (src (cdr (assoc-string "src" parameter-alist
))))
1639 (if (display-images-p)
1640 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1641 (concat default-directory src
))
1643 (image (if (file-exists-p image-file
)
1644 (create-image image-file
)
1645 (or (cdr (assoc-string "text" parameter-alist
))
1646 (and src
(concat "[broken image:" src
"]"))
1647 "[broken image]"))))
1648 (if (not (get-text-property start
'display
))
1649 (add-text-properties
1651 `(display ,image rear-nonsticky
(display)
1652 help-echo
,(cdr (assoc-string "alt" parameter-alist
))))))
1653 ;; text-only display, show alternative text if provided, or
1654 ;; otherwise a clue that there's meant to be a picture
1655 (delete-region start
(point))
1656 (insert (or (cdr (assoc-string "text" parameter-alist
))
1657 (cdr (assoc-string "alt" parameter-alist
))
1658 (and src
(concat "[image:" src
"]"))
1660 (set-buffer-modified-p nil
)))
1662 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1663 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1664 ;; including one optional trailing newline.
1665 (defun Info-hide-cookies-node ()
1666 "Hide unrecognized cookies in current node."
1668 (let ((inhibit-read-only t
)
1669 (case-fold-search t
))
1670 (goto-char (point-min))
1671 (while (re-search-forward
1672 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1674 (let* ((start (match-beginning 1)))
1675 (if (and (not (get-text-property start
'invisible
))
1676 (not (get-text-property start
'display
)))
1677 (put-text-property start
(point) 'invisible t
)))))
1678 (set-buffer-modified-p nil
)))
1680 (defun Info-select-node ()
1681 "Select the Info node that point is in."
1682 ;; Bind this in case the user sets it to nil.
1683 (let ((case-fold-search t
))
1685 ;; Find beginning of node.
1686 (if (search-backward "\n\^_" nil
'move
)
1688 (if (looking-at "\^_")
1690 (signal 'search-failed
(list "\n\^_"))))
1691 ;; Get nodename spelled as it is in the node.
1692 (re-search-forward "Node:[ \t]*")
1693 (setq Info-current-node
1694 (buffer-substring-no-properties (point)
1696 (skip-chars-forward "^,\t\n")
1698 (Info-set-mode-line)
1699 ;; Find the end of it, and narrow.
1701 (let (active-expression)
1702 ;; Narrow to the node contents
1703 (narrow-to-region (point)
1704 (if (re-search-forward "\n[\^_\f]" nil t
)
1707 (if (looking-at "[\n\^_\f]*execute: ")
1709 (goto-char (match-end 0))
1710 (setq active-expression
1711 (read (current-buffer))))))
1713 (if Info-enable-active-nodes
(eval active-expression
))
1714 ;; Add a new unique history item to full history list
1715 (let ((new-history (list Info-current-file Info-current-node
)))
1716 (setq Info-history-list
1717 (cons new-history
(remove new-history Info-history-list
)))
1718 (setq Info-history-forward nil
))
1719 (if (not (eq Info-fontify-maximum-menu-size nil
))
1720 (Info-fontify-node))
1721 (setq list-buffers-directory
(Info-node-description Info-current-file
))
1722 (Info-display-images-node)
1723 (Info-hide-cookies-node)
1724 (run-hooks 'Info-selection-hook
)))))
1726 (defvar Info-mode-line-node-keymap
1727 (let ((map (make-sparse-keymap)))
1728 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1729 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1731 "Keymap to put on the Info node name in the mode line.")
1733 (defun Info-set-mode-line ()
1734 (setq mode-line-buffer-identification
1735 (nconc (propertized-buffer-identification "%b")
1739 (if (stringp Info-current-file
)
1740 (replace-regexp-in-string
1742 (file-name-sans-extension
1743 (file-name-nondirectory Info-current-file
)))
1744 (format "*%S*" Info-current-file
))
1746 (if Info-current-node
1747 (propertize (replace-regexp-in-string
1748 "%" "%%" Info-current-node
)
1749 'face
'mode-line-buffer-id
1751 "mouse-1: scroll forward, mouse-3: scroll back"
1752 'mouse-face
'mode-line-highlight
1753 'local-map Info-mode-line-node-keymap
)
1756 ;; Go to an Info node specified with a filename-and-nodename string
1757 ;; of the sort that is found in pointers in nodes.
1759 ;; Don't autoload this function: the correct entry point for other packages
1760 ;; to use is `info'. --Stef
1762 (defun Info-goto-node (nodename &optional fork strict-case
)
1763 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1764 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1765 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1767 Completion is available for node names in the current Info file as well as
1768 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1769 Empty NODENAME in (FILENAME) defaults to the Top node.
1770 If FORK is non-nil (interactively with a prefix arg), show the node in
1772 If FORK is a string, it is the name to use for the new buffer.
1774 This function first looks for a case-sensitive match for the node part
1775 of NODENAME; if none is found it then tries a case-insensitive match
1776 \(unless STRICT-CASE is non-nil)."
1777 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1781 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1783 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1785 (setq filename
(if (= (match-beginning 1) (match-end 1))
1787 (match-string 2 nodename
))
1788 nodename
(match-string 3 nodename
))
1789 (let ((trim (string-match "\\s +\\'" filename
)))
1790 (if trim
(setq filename
(substring filename
0 trim
))))
1791 (let ((trim (string-match "\\s +\\'" nodename
)))
1792 (if trim
(setq nodename
(substring nodename
0 trim
))))
1793 (if transient-mark-mode
(deactivate-mark))
1794 (Info-find-node (if (equal filename
"") nil filename
)
1795 (if (equal nodename
"") "Top" nodename
) nil strict-case
)))
1797 (defvar Info-read-node-completion-table
)
1799 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1800 "Internal function used to complete Info node names.
1801 Return a completion table for Info files---the FILENAME part of a
1802 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1803 directories to search if FILENAME is not absolute; SUFFIXES is a
1804 list of valid filename suffixes for Info files. See
1805 `try-completion' for a description of the remaining arguments."
1806 (setq suffixes
(remove "" suffixes
))
1807 (when (file-name-absolute-p string
)
1808 (setq dirs
(list (file-name-directory string
))))
1810 (names-sans-suffix nil
)
1811 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1812 (string-dir (file-name-directory string
)))
1815 (setq dir default-directory
))
1816 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1817 (when (file-directory-p dir
)
1818 (dolist (file (file-name-all-completions
1819 (file-name-nondirectory string
) dir
))
1820 ;; If the file name has no suffix or a standard suffix,
1822 (and (or (null (file-name-extension file
))
1823 (string-match suffix file
))
1824 ;; But exclude subfiles of split Info files.
1825 (not (string-match "-[0-9]+\\'" file
))
1826 ;; And exclude backup files.
1827 (not (string-match "~\\'" file
))
1828 (push (if string-dir
(concat string-dir file
) file
) names
))
1829 ;; If the file name ends in a standard suffix,
1830 ;; add the unsuffixed name as a completion option.
1831 (when (string-match suffix file
)
1832 (setq file
(substring file
0 (match-beginning 0)))
1833 (push (if string-dir
(concat string-dir file
) file
)
1834 names-sans-suffix
)))))
1835 ;; If there is just one file, don't duplicate it with suffixes,
1836 ;; so `Info-read-node-name-1' will be able to complete a single
1837 ;; candidate and to add the terminating ")".
1838 (if (and (= (length names
) 1) (= (length names-sans-suffix
) 1))
1839 (setq names names-sans-suffix
)
1840 (setq names
(append names-sans-suffix names
)))
1841 (complete-with-action action names string pred
)))
1843 (defun Info-read-node-name-1 (string predicate code
)
1844 "Internal function used by `Info-read-node-name'.
1845 See `completing-read' for a description of arguments and usage."
1847 ;; First complete embedded file names.
1848 ((string-match "\\`([^)]*\\'" string
)
1849 (completion-table-with-context
1851 (apply-partially #'completion-table-with-terminator
")"
1852 (apply-partially #'Info-read-node-name-2
1854 (mapcar #'car Info-suffix-list
)))
1855 (substring string
1)
1858 ;; If a file name was given, complete nodes in the file.
1859 ((string-match "\\`(\\([^)]+\\))" string
)
1860 (let ((file0 (match-string 0 string
))
1861 (file1 (match-string 1 string
))
1862 (nodename (substring string
(match-end 0))))
1863 (if (and (equal nodename
"") (eq code
'lambda
))
1864 ;; Empty node name is permitted that means "Top".
1866 (completion-table-with-context
1868 (lambda (string pred action
)
1869 (complete-with-action
1871 (Info-build-node-completions (Info-find-file file1
))
1873 nodename predicate code
))))
1874 ;; Otherwise use Info-read-node-completion-table.
1875 (t (complete-with-action
1876 code Info-read-node-completion-table string predicate
))))
1878 ;; Arrange to highlight the proper letters in the completion list buffer.
1879 (defun Info-read-node-name (prompt)
1880 "Read an Info node name with completion, prompting with PROMPT.
1881 A node name can have the form \"NODENAME\", referring to a node
1882 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1883 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1884 the Top node in FILENAME."
1885 (let* ((completion-ignore-case t
)
1886 (Info-read-node-completion-table (Info-build-node-completions))
1887 (nodename (completing-read prompt
#'Info-read-node-name-1 nil t
)))
1888 (if (equal nodename
"")
1889 (Info-read-node-name prompt
)
1892 (defun Info-build-node-completions (&optional filename
)
1894 (or (cdr (assoc filename Info-file-completions
))
1897 (Info-goto-node (format "(%s)Top" filename
))
1898 (Info-build-node-completions-1)
1899 (push (cons filename Info-current-file-completions
) Info-file-completions
)
1900 Info-current-file-completions
))
1901 (or Info-current-file-completions
1902 (Info-build-node-completions-1))))
1904 (defun Info-build-node-completions-1 ()
1906 ;; Bind this in case the user sets it to nil.
1907 (case-fold-search t
)
1908 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1911 (or Info-tag-table-marker
1912 (error "No Info tags found"))
1913 (if (marker-buffer Info-tag-table-marker
)
1914 (let ((marker Info-tag-table-marker
))
1915 (set-buffer (marker-buffer marker
))
1918 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1920 (cons (list (match-string-no-properties 2))
1923 (goto-char (point-min))
1924 ;; If the buffer begins with a node header, process that first.
1925 (if (Info-node-at-bob-matching node-regexp
)
1926 (setq compl
(list (match-string-no-properties 1))))
1927 ;; Now for the rest of the nodes.
1928 (while (search-forward "\n\^_" nil t
)
1930 (let ((beg (point)))
1932 (if (re-search-backward node-regexp beg t
)
1934 (cons (list (match-string-no-properties 1))
1936 (setq compl
(cons '("*") (nreverse compl
)))
1937 (setq Info-current-file-completions compl
)
1941 (defun Info-restore-point (hl)
1942 "If this node has been visited, restore the point value when we left."
1944 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1945 ;; Use string-equal, not equal, to ignore text props.
1946 (string-equal (nth 1 (car hl
)) Info-current-node
))
1948 (goto-char (nth 2 (car hl
)))
1949 (setq hl nil
)) ;terminate the while at next iter
1950 (setq hl
(cdr hl
)))))
1952 (defvar Info-search-history nil
1953 "The history list for `Info-search'.")
1955 (defvar Info-search-case-fold nil
1956 "The value of `case-fold-search' from previous `Info-search' command.")
1958 (defun Info--search-loop (regexp bound backward
)
1960 ;; Hide Info file header for backward search.
1961 (narrow-to-region (save-excursion
1962 (goto-char (point-min))
1963 (search-forward "\n\^_")
1969 (while (not (or give-up
1971 (funcall isearch-filter-predicate
1973 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1975 (if backward
#'re-search-backward
#'re-search-forward
)
1977 (setq found
(point) beg-found
(if backward
(match-end 0)
1978 (match-beginning 0)))
1979 (setq give-up t found nil
))))
1982 (defun Info-search (regexp &optional bound _noerror _count direction
)
1983 "Search for REGEXP, starting from point, and select node it's found in.
1984 If DIRECTION is `backward', search in the reverse direction."
1985 (interactive (list (read-string
1986 (if Info-search-history
1987 (format "Regexp search%s (default %s): "
1988 (if case-fold-search
"" " case-sensitively")
1989 (car Info-search-history
))
1990 (format "Regexp search%s: "
1991 (if case-fold-search
"" " case-sensitively")))
1992 nil
'Info-search-history
)))
1994 (when (equal regexp
"")
1995 (setq regexp
(car Info-search-history
)))
1997 (setq Info-search-case-fold case-fold-search
)
1998 (let* ((backward (eq direction
'backward
))
1999 (onode Info-current-node
)
2000 (ofile Info-current-file
)
2002 (opoint-min (point-min))
2003 (opoint-max (point-max))
2004 (ostart (window-start))
2005 (osubfile Info-current-subfile
)
2010 (Info--search-loop regexp bound backward
)))))
2012 (unless (or (not isearch-mode
) (not Info-isearch-search
)
2013 Info-isearch-initial-node
2015 (and found
(> found opoint-min
) (< found opoint-max
)))
2016 (signal 'user-search-failed
(list regexp
"(end of node)")))
2018 ;; If no subfiles, give error now.
2019 (unless (or found Info-current-subfile
)
2021 (signal 'user-search-failed
(list regexp
"end of manual"))
2022 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
2023 (unless (if backward
2024 (re-search-backward regexp nil t
)
2025 (re-search-forward regexp nil t
))
2026 (signal 'user-search-failed
(list regexp
))))))
2028 (if (and bound
(not found
))
2029 (signal 'user-search-failed
(list regexp
)))
2031 (unless (or found bound
)
2033 ;; Try other subfiles.
2035 (with-current-buffer (marker-buffer Info-tag-table-marker
)
2036 (goto-char (point-min))
2037 (search-forward "\n\^_\nIndirect:")
2039 (narrow-to-region (point)
2040 (progn (search-forward "\n\^_")
2042 (goto-char (point-min))
2043 ;; Find the subfile we just searched.
2044 (search-forward (concat "\n" osubfile
": "))
2046 (forward-line (if backward
0 1))
2047 (if backward
(forward-char -
1))
2048 ;; Make a list of all following subfiles.
2049 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2050 (while (not (if backward
(bobp) (eobp)))
2052 (re-search-backward "\\(^.*\\): [0-9]+$")
2053 (re-search-forward "\\(^.*\\): [0-9]+$"))
2054 (goto-char (+ (match-end 1) 2))
2055 (push (cons (read (current-buffer))
2056 (match-string-no-properties 1))
2058 (goto-char (if backward
2059 (1- (match-beginning 0))
2060 (1+ (match-end 0)))))
2061 ;; Put in forward order
2062 (setq list
(nreverse list
))))
2064 (message "Searching subfile %s..." (cdr (car list
)))
2065 (Info-read-subfile (car (car list
)))
2066 (when backward
(goto-char (point-max)))
2067 (setq list
(cdr list
))
2068 (setq found
(Info--search-loop regexp nil backward
))
2073 (signal 'user-search-failed
2074 `(,regexp
,@(if isearch-mode
'("end of manual"))))))
2076 (progn (Info-read-subfile osubfile
)
2079 (set-window-start (selected-window) ostart
)))))
2081 (if (and (string= osubfile Info-current-subfile
)
2082 (> found opoint-min
)
2083 (< found opoint-max
))
2084 ;; Search landed in the same node
2088 (save-match-data (Info-select-node)))
2090 ;; Use string-equal, not equal, to ignore text props.
2091 (or (and (string-equal onode Info-current-node
)
2092 (equal ofile Info-current-file
))
2093 (and isearch-mode isearch-wrapped
2094 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
2095 (setq Info-history
(cons (list ofile onode opoint
)
2098 (defun Info-search-case-sensitively ()
2099 "Search for a regexp case-sensitively."
2101 (let ((case-fold-search nil
))
2102 (call-interactively 'Info-search
)))
2104 (defun Info-search-next ()
2105 "Search for next regexp from a previous `Info-search' command."
2107 (let ((case-fold-search Info-search-case-fold
))
2108 (if Info-search-history
2109 (Info-search (car Info-search-history
))
2110 (call-interactively 'Info-search
))))
2112 (defun Info-search-backward (regexp &optional bound noerror count
)
2113 "Search for REGEXP in the reverse direction."
2114 (interactive (list (read-string
2115 (if Info-search-history
2116 (format "Regexp search%s backward (default %s): "
2117 (if case-fold-search
"" " case-sensitively")
2118 (car Info-search-history
))
2119 (format "Regexp search%s backward: "
2120 (if case-fold-search
"" " case-sensitively")))
2121 nil
'Info-search-history
)))
2122 (Info-search regexp bound noerror count
'backward
))
2124 (defun Info-isearch-search ()
2125 (if Info-isearch-search
2126 (lambda (string &optional bound noerror count
)
2127 (let ((Info-search-whitespace-regexp
2128 (if (if isearch-regexp
2129 isearch-regexp-lax-whitespace
2130 isearch-lax-whitespace
)
2131 search-whitespace-regexp
)))
2134 (isearch-regexp-function
2135 ;; Lax version of word search
2136 (let ((lax (and (not bound
) (isearch--lax-regexp-function-p))))
2138 (setq isearch-adjusted t
))
2139 (if (functionp isearch-regexp-function
)
2140 (funcall isearch-regexp-function string lax
)
2141 (word-search-regexp string lax
))))
2142 (isearch-regexp string
)
2143 (t (regexp-quote string
)))
2145 (unless isearch-forward
'backward
)))
2147 (isearch-search-fun-default)))
2149 (defun Info-isearch-wrap ()
2150 (if Info-isearch-search
2151 (if Info-isearch-initial-node
2153 (if isearch-forward
(Info-top-node) (Info-final-node))
2154 (goto-char (if isearch-forward
(point-min) (point-max))))
2155 (setq Info-isearch-initial-node Info-current-node
)
2156 (setq isearch-wrapped nil
))
2157 (goto-char (if isearch-forward
(point-min) (point-max)))))
2159 (defun Info-isearch-push-state ()
2161 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
2163 (defun Info-isearch-pop-state (_cmd file node
)
2164 (or (and (equal Info-current-file file
)
2165 (equal Info-current-node node
))
2166 (progn (Info-find-node file node
) (sit-for 0))))
2168 (defun Info-isearch-start ()
2169 (setq Info-isearch-initial-node
2170 ;; Don't stop at initial node for nonincremental search.
2171 ;; Otherwise this variable is set after first search failure.
2172 (and isearch-nonincremental Info-current-node
))
2173 (setq Info-isearch-initial-history Info-history
2174 Info-isearch-initial-history-list Info-history-list
)
2175 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
2177 (defun Info-isearch-end ()
2178 ;; Remove intermediate nodes (visited while searching)
2179 ;; from the history. Add only the last node (where Isearch ended).
2180 (if (> (length Info-history
)
2181 (length Info-isearch-initial-history
))
2183 (nthcdr (- (length Info-history
)
2184 (length Info-isearch-initial-history
)
2187 (if (> (length Info-history-list
)
2188 (length Info-isearch-initial-history-list
))
2189 (setq Info-history-list
2190 (cons (car Info-history-list
)
2191 Info-isearch-initial-history-list
)))
2192 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
2194 (defun Info-isearch-filter (beg-found found
)
2195 "Test whether the current search hit is a visible useful text.
2196 Return non-nil if the text from BEG-FOUND to FOUND is visible
2197 and is not in the header line or a tag table."
2199 (let ((backward (< found beg-found
)))
2202 (and (not search-invisible
)
2204 (or (text-property-not-all found beg-found
'invisible nil
)
2205 (text-property-not-all found beg-found
'display nil
))
2206 (or (text-property-not-all beg-found found
'invisible nil
)
2207 (text-property-not-all beg-found found
'display nil
))))
2208 ;; Skip node header line
2209 (and (save-excursion (forward-line -
1)
2211 (forward-line (if backward -
1 1)))
2212 ;; Skip Tag Table node
2214 (and (search-backward "\^_" nil t
)
2216 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2219 (defun Info-extract-pointer (name &optional errorname
)
2220 "Extract the value of the node-pointer named NAME.
2221 If there is none, use ERRORNAME in the error message;
2222 if ERRORNAME is nil, just return nil."
2223 ;; Bind this in case the user sets it to nil.
2224 (let ((case-fold-search t
))
2226 (goto-char (point-min))
2227 (let ((bound (point)))
2229 (cond ((re-search-backward
2230 (concat name
":" (Info-following-node-name-re)) bound t
)
2231 (match-string-no-properties 1))
2232 ((not (eq errorname t
))
2233 (user-error "Node has no %s"
2234 (capitalize (or errorname name
)))))))))
2236 (defun Info-following-node-name-re (&optional allowedchars
)
2237 "Return a regexp matching a node name.
2238 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2239 saying which chars may appear in the node name.
2240 Submatch 1 is the complete node name.
2241 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2242 Submatch 3 is the local part of the node name.
2243 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2244 (concat "[ \t\n]*" ;Skip leading space.
2245 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2246 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2247 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2248 "\\|\\)\\)")) ;Allow empty node names.
2250 ;; For compatibility; other files have used this name.
2251 (defun Info-following-node-name ()
2252 (and (looking-at (Info-following-node-name-re))
2253 (match-string-no-properties 1)))
2256 "Go to the next node of this node."
2258 ;; In case another window is currently selected
2259 (save-window-excursion
2260 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2261 (Info-goto-node (Info-extract-pointer "next"))))
2264 "Go to the previous node of this node."
2266 ;; In case another window is currently selected
2267 (save-window-excursion
2268 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2269 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2271 (defun Info-up (&optional same-file
)
2272 "Go to the superior node of this node.
2273 If SAME-FILE is non-nil, do not move to a different Info file."
2275 ;; In case another window is currently selected
2276 (save-window-excursion
2277 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2278 (let ((old-node Info-current-node
)
2279 (old-file Info-current-file
)
2280 (node (Info-extract-pointer "up")) p
)
2282 (string-match "^(" node
)
2283 (error "Up node is in another Info file"))
2284 (Info-goto-node node
)
2286 (goto-char (point-min))
2287 (if (and (stringp old-file
)
2288 (search-forward "\n* Menu:" nil t
)
2290 (if (string-equal old-node
"Top")
2291 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2292 (concat "\n\\* +\\(" (regexp-quote old-node
)
2293 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2295 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2297 (Info-restore-point Info-history
)))))
2299 (defun Info-history-back ()
2300 "Go back in the history to the last node visited."
2303 (user-error "This is the first Info node you looked at"))
2304 (let ((history-forward
2305 (cons (list Info-current-file Info-current-node
(point))
2306 Info-history-forward
))
2307 filename nodename opoint
)
2308 (setq filename
(car (car Info-history
)))
2309 (setq nodename
(car (cdr (car Info-history
))))
2310 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2311 (setq Info-history
(cdr Info-history
))
2312 (Info-find-node filename nodename
)
2313 (setq Info-history
(cdr Info-history
))
2314 (setq Info-history-forward history-forward
)
2315 (goto-char opoint
)))
2317 (defalias 'Info-last
'Info-history-back
)
2319 (defun Info-history-forward ()
2320 "Go forward in the history of visited nodes."
2322 (or Info-history-forward
2323 (user-error "This is the last Info node you looked at"))
2324 (let ((history-forward (cdr Info-history-forward
))
2325 filename nodename opoint
)
2326 (setq filename
(car (car Info-history-forward
)))
2327 (setq nodename
(car (cdr (car Info-history-forward
))))
2328 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2329 (Info-find-node filename nodename
)
2330 (setq Info-history-forward history-forward
)
2331 (goto-char opoint
)))
2333 (add-to-list 'Info-virtual-files
2335 (toc-nodes . Info-directory-toc-nodes
)
2336 (find-file . Info-directory-find-file
)
2337 (find-node . Info-directory-find-node
)
2340 (defun Info-directory-toc-nodes (filename)
2341 "Directory-specific implementation of `Info-toc-nodes'."
2343 ("Top" nil nil nil
)))
2345 (defun Info-directory-find-file (filename &optional _noerror
)
2346 "Directory-specific implementation of `Info-find-file'."
2349 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2350 "Directory-specific implementation of `Info-find-node-2'."
2354 (defun Info-directory ()
2355 "Go to the Info directory node."
2357 (Info-find-node "dir" "top"))
2359 (add-to-list 'Info-virtual-files
2360 '("\\`\\*History\\*\\'"
2361 (toc-nodes . Info-history-toc-nodes
)
2362 (find-file . Info-history-find-file
)
2363 (find-node . Info-history-find-node
)
2366 (defun Info-history-toc-nodes (filename)
2367 "History-specific implementation of `Info-toc-nodes'."
2369 ("Top" nil nil nil
)))
2371 (defun Info-history-find-file (filename &optional _noerror
)
2372 "History-specific implementation of `Info-find-file'."
2375 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2376 "History-specific implementation of `Info-find-node-2'."
2377 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2378 (or filename Info-current-file
) nodename
))
2379 (insert "History of Visited Nodes\n")
2380 (insert "************************\n\n")
2381 (insert "* Menu:\n\n")
2382 (let ((hl (remove '("*History*" "Top") Info-history-list
)))
2384 (let ((file (nth 0 (car hl
)))
2385 (node (nth 1 (car hl
))))
2387 (insert "* " node
": ("
2388 (propertize (or (file-name-directory file
) "") 'invisible t
)
2389 (file-name-nondirectory file
)
2391 (setq hl
(cdr hl
)))))
2393 (defun Info-history ()
2394 "Go to a node with a menu of visited nodes."
2396 (Info-find-node "*History*" "Top")
2397 (Info-next-reference)
2398 (Info-next-reference))
2400 (add-to-list 'Info-virtual-nodes
2402 (find-node . Info-toc-find-node
)
2405 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2406 "Toc-specific implementation of `Info-find-node-2'."
2407 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2408 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2409 (node-list (Info-toc-nodes curr-file
)))
2410 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2411 curr-file curr-node
))
2412 (insert "Table of Contents\n")
2413 (insert "*****************\n\n")
2414 (insert "*Note Top::\n")
2416 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2417 node-list
0 curr-file
)
2419 (let ((Info-hide-note-references 'hide
)
2420 (Info-fontify-visited-nodes nil
))
2421 (setq Info-current-file filename Info-current-node
"*TOC*")
2422 (goto-char (point-min))
2423 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2430 "Go to a node with table of contents of the current Info file.
2431 Table of contents is created from the tree structure of menus."
2433 (Info-find-node Info-current-file
"*TOC*")
2434 (let ((prev-node (nth 1 (car Info-history
))) p
)
2435 (goto-char (point-min))
2436 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2437 (setq p
(- p
(length prev-node
) 2)))
2438 (goto-char (or p
(point-min)))))
2440 (defun Info-toc-insert (nodes node-list level curr-file
)
2441 "Insert table of contents with references to nodes."
2442 (let ((section "Top"))
2444 (let ((node (assoc (car nodes
) node-list
)))
2445 (unless (member (nth 2 node
) (list nil section
))
2446 (insert (setq section
(nth 2 node
)) "\n"))
2447 (insert (make-string level ?
\t))
2448 (insert "*Note " (car nodes
) ":: \n")
2449 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2450 (setq nodes
(cdr nodes
))))))
2452 (defun Info-toc-build (file)
2453 "Build table of contents from menus of Info FILE and its subfiles."
2455 (let* ((file (and (stringp file
) (Info-find-file file
)))
2456 (default-directory (or (and (stringp file
)
2457 (file-name-directory file
))
2459 (main-file (and (stringp file
) file
))
2460 (sections '(("Top" "Top")))
2462 (while (or main-file subfiles
)
2463 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2465 (info-insert-file-contents (or main-file
(car subfiles
)))
2466 (goto-char (point-min))
2467 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2468 (search-forward "Node: " nil
'move
))
2469 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2470 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2472 (upnode (and (re-search-forward
2473 (concat "Up:" (Info-following-node-name-re))
2475 (match-string-no-properties 1)))
2478 (when (and upnode
(string-match "(" upnode
)) (setq upnode nil
))
2479 (when (and (not (Info-index-node nodename file
))
2480 (re-search-forward "^\\* Menu:" bound t
))
2483 (setq bound
(or (and (equal nodename
"Top")
2486 "^[ \t-]*The Detailed Node Listing" nil t
)))
2488 (while (< (point) bound
)
2491 ((looking-at "^\\* +[^:]+:")
2494 (let ((menu-node-name (substring-no-properties
2495 (Info-extract-menu-node-name))))
2496 (setq menu-items
(cons menu-node-name menu-items
))
2497 (if (equal nodename
"Top")
2499 (cons (list menu-node-name section
) sections
)))))
2500 ;; Other non-empty strings in the Top node are section names
2501 ((and (equal nodename
"Top")
2502 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2503 (setq section
(match-string-no-properties 1))))
2505 (beginning-of-line)))
2506 (setq nodes
(cons (list nodename upnode
2507 (cadr (assoc nodename sections
))
2508 (nreverse menu-items
))
2513 (goto-char (point-min))
2514 (if (search-forward "\n\^_\nIndirect:" nil t
)
2515 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2516 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2517 (setq subfiles
(cons (match-string-no-properties 1)
2519 (setq subfiles
(nreverse subfiles
)
2521 (setq subfiles
(cdr subfiles
))))
2525 (defun Info-toc-nodes (filename)
2526 "Return a node list of Info FILENAME with parent-children information.
2527 This information is cached in the variable `Info-toc-nodes' with the help
2528 of the function `Info-toc-build'."
2531 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2534 (or filename
(setq filename Info-current-file
))
2535 (or (assoc filename Info-toc-nodes
)
2536 ;; Skip virtual Info files
2537 (and (or (not (stringp filename
))
2538 (Info-virtual-file-p filename
))
2539 (push (cons filename nil
) Info-toc-nodes
))
2540 ;; Scan the entire manual and cache the result in Info-toc-nodes
2541 (let ((nodes (Info-toc-build filename
)))
2542 (push (cons filename nodes
) Info-toc-nodes
)
2544 ;; If there is an error, still add nil to the cache
2545 (push (cons filename nil
) Info-toc-nodes
))
2546 (cdr (assoc filename Info-toc-nodes
)))))
2549 (defun Info-follow-reference (footnotename &optional fork
)
2550 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2551 FOOTNOTENAME may be an abbreviation of the reference name.
2552 If FORK is non-nil (interactively with a prefix arg), show the node in
2553 a new Info buffer. If FORK is a string, it is the name to use for the
2556 (let ((completion-ignore-case t
)
2557 (case-fold-search t
)
2558 completions default alt-default
(start-point (point)) str i bol eol
)
2560 ;; Store end and beginning of line.
2561 (setq eol
(line-end-position)
2562 bol
(line-beginning-position))
2563 (goto-char (point-min))
2564 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2565 (setq str
(match-string-no-properties 1))
2566 ;; See if this one should be the default.
2568 (<= (match-beginning 0) start-point
)
2569 (<= start-point
(point))
2571 ;; See if this one should be the alternate default.
2572 (and (null alt-default
)
2573 (and (<= bol
(match-beginning 0))
2575 (setq alt-default t
))
2577 (while (setq i
(string-match "[ \n\t]+" str i
))
2578 (setq str
(concat (substring str
0 i
) " "
2579 (substring str
(match-end 0))))
2581 ;; Record as a completion and perhaps as default.
2582 (if (eq default t
) (setq default str
))
2583 (if (eq alt-default t
) (setq alt-default str
))
2584 ;; Don't add this string if it's a duplicate.
2585 (or (assoc-string str completions t
)
2586 (push str completions
))))
2587 ;; If no good default was found, try an alternate.
2589 (setq default alt-default
))
2590 ;; If only one cross-reference found, then make it default.
2591 (if (eq (length completions
) 1)
2592 (setq default
(car completions
)))
2594 (let ((input (completing-read (if default
2596 "Follow reference named (default "
2598 "Follow reference named: ")
2599 completions nil t
)))
2600 (list (if (equal input
"")
2602 current-prefix-arg
))
2603 (user-error "No cross-references in this node"))))
2605 (unless footnotename
2606 (error "No reference was specified"))
2608 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2609 (case-fold-search t
))
2610 (while (setq i
(string-match " " str i
))
2611 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2614 ;; Move point to the beginning of reference if point is on reference
2615 (or (looking-at "\\*note[ \n\t]+")
2616 (and (looking-back "\\*note[ \n\t]+"
2617 (save-excursion (skip-chars-backward " \n\t")
2618 (line-beginning-position)))
2619 (goto-char (match-beginning 0)))
2620 (if (and (save-excursion
2621 (goto-char (+ (point) 5)) ; skip a possible *note
2622 (re-search-backward "\\*note[ \n\t]+" nil t
)
2624 (<= (point) (match-end 0)))
2625 (goto-char (match-beginning 0))))
2626 ;; Go to the reference closest to point
2627 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2628 (+ (match-beginning 0) 5))))
2629 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2630 (+ (match-beginning 0) 5)))))
2631 (goto-char (cond ((and next-ref prev-ref
)
2632 (if (< (abs (- next-ref
(point)))
2633 (abs (- prev-ref
(point))))
2635 ((or next-ref prev-ref
))
2636 ((user-error "No cross-reference named %s"
2638 (setq target
(Info-extract-menu-node-name t
))))
2639 (while (setq i
(string-match "[ \t\n]+" target i
))
2640 (setq target
(concat (substring target
0 i
) " "
2641 (substring target
(match-end 0))))
2643 (Info-goto-node target fork
)))
2645 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2646 ;; We allow newline because this is also used in Info-follow-reference,
2647 ;; where the xref name might be wrapped over two lines.
2648 "Regexp that matches a menu entry name upto but not including the colon.
2649 Because of ambiguities, this should be concatenated with something like
2650 `:' and `Info-following-node-name-re'.")
2652 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2653 (skip-chars-forward " \t\n")
2654 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2655 (Info-following-node-name-re
2657 (index-node "^,\t\n")
2658 (multi-line "^.,\t")
2662 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2665 (setq Info-point-loc
2666 (if (match-beginning 5)
2667 (string-to-number (match-string 5))
2668 (buffer-substring-no-properties
2669 (match-beginning 0) (1- (match-beginning 1)))))
2670 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2671 ;;; (setq Info-point-loc
2672 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2674 (replace-regexp-in-string
2676 (or (and (not (equal (match-string-no-properties 2) ""))
2677 (match-string-no-properties 2))
2678 ;; If the node name is the menu entry name (using `entry::').
2679 (buffer-substring-no-properties
2680 (match-beginning 0) (1- (match-beginning 1)))))))
2682 ;; No one calls this.
2683 ;;(defun Info-menu-item-sequence (list)
2685 ;; (Info-menu (car list))
2686 ;; (setq list (cdr list))))
2688 (defvar Info-complete-menu-buffer
)
2689 (defvar Info-complete-next-re nil
)
2690 (defvar Info-complete-nodes nil
)
2691 (defvar-local Info-complete-cache nil
)
2693 (defconst Info-node-spec-re
2694 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2695 "Regexp to match the text after a : until the terminating `.'.")
2697 (defun Info-complete-menu-item (string predicate action
)
2698 ;; This uses two dynamically bound variables:
2699 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2700 ;; is the menu of items we're trying to complete.
2701 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2702 ;; also look for menu items in subsequent nodes as long as those
2703 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2705 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2706 ;; also look for menu items in these nodes. This feature is currently
2707 ;; only used for completion in Info-index.
2709 ;; Note that `Info-complete-menu-buffer' could be current already,
2710 ;; so we want to save point.
2711 (with-current-buffer Info-complete-menu-buffer
2713 (let ((completion-ignore-case t
)
2714 (case-fold-search t
)
2715 (orignode Info-current-node
)
2717 (goto-char (point-min))
2718 (unless (search-forward "\n* Menu:" nil t
)
2719 (user-error "No menu in this node"))
2721 ((eq (car-safe action
) 'boundaries
) nil
)
2722 ((eq action
'metadata
) `(metadata (category . info-menu
)))
2723 ((eq action
'lambda
)
2725 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2727 (let ((pattern (concat "\n\\* +\\("
2728 (regexp-quote string
)
2729 Info-menu-entry-name-re
"\\):"
2732 (complete-nodes Info-complete-nodes
))
2734 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2735 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2736 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2737 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2738 (string-prefix-p (nth 3 Info-complete-cache
) string
) t
)
2739 ;; We can reuse the previous list.
2740 (setq completions
(nth 4 Info-complete-cache
))
2741 ;; The cache can't be used.
2744 (while (re-search-forward pattern nil t
)
2745 (push (match-string-no-properties 1)
2747 (setq completions
(delete-dups completions
))
2748 ;; Check subsequent nodes if applicable.
2749 (or (and Info-complete-next-re
2750 (setq nextnode
(Info-extract-pointer "next" t
))
2751 (string-match Info-complete-next-re nextnode
))
2753 (setq complete-nodes
(cdr complete-nodes
)
2754 nextnode
(car complete-nodes
)))))
2755 (Info-goto-node nextnode
))
2756 ;; Go back to the start node (for the next completion).
2757 (unless (equal Info-current-node orignode
)
2758 (Info-goto-node orignode
))
2759 ;; Update the cache.
2760 (setq Info-complete-cache
2761 (list Info-current-file Info-current-node
2762 Info-complete-next-re string completions
2763 Info-complete-nodes
)))
2764 (complete-with-action action completions string predicate
))))))))
2767 (defun Info-menu (menu-item &optional fork
)
2768 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2769 The menu item should one of those listed in the current node's menu.
2770 Completion is allowed, and the default menu item is the one point is on.
2771 If FORK is non-nil (interactively with a prefix arg), show the node in
2772 a new Info buffer. If FORK is a string, it is the name to use for the
2775 (let (;; If point is within a menu item, use that item as the default
2779 (case-fold-search t
))
2781 (goto-char (point-min))
2782 (if (not (search-forward "\n* menu:" nil t
))
2783 (user-error "No menu in this node"))
2789 (if (re-search-backward (concat "\n\\* +\\("
2790 Info-menu-entry-name-re
2793 (setq default
(match-string-no-properties 1))))))
2796 (setq item
(let ((completion-ignore-case t
)
2797 (Info-complete-menu-buffer (current-buffer)))
2798 (completing-read (if default
2799 (format "Menu item (default %s): "
2802 #'Info-complete-menu-item nil t nil nil
2804 (list item current-prefix-arg
))))
2805 ;; there is a problem here in that if several menu items have the same
2806 ;; name you can only go to the node of the first with this command.
2807 (Info-goto-node (Info-extract-menu-item menu-item
)
2809 (if (stringp fork
) fork menu-item
))))
2811 (defun Info-extract-menu-item (menu-item)
2812 (setq menu-item
(regexp-quote menu-item
))
2813 (let ((case-fold-search t
))
2815 (let ((case-fold-search t
))
2816 (goto-char (point-min))
2817 (or (search-forward "\n* menu:" nil t
)
2818 (user-error "No menu in this node"))
2819 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2820 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2821 (user-error "No such item in menu"))
2824 (Info-extract-menu-node-name nil
(Info-index-node))))))
2826 ;; If COUNT is nil, use the last item in the menu.
2827 (defun Info-extract-menu-counting (count &optional no-detail
)
2828 (let ((case-fold-search t
))
2830 (let ((case-fold-search t
)
2831 (bound (when (and no-detail
2833 "^[ \t-]*The Detailed Node Listing" nil t
))
2834 (match-beginning 0))))
2835 (goto-char (point-min))
2836 (or (search-forward "\n* menu:" bound t
)
2837 (user-error "No menu in this node"))
2839 (or (search-forward "\n* " bound t count
)
2840 (error "Too few items in menu"))
2841 (while (search-forward "\n* " bound t
)
2843 (Info-extract-menu-node-name nil
(Info-index-node))))))
2845 (defun Info-nth-menu-item ()
2846 "Go to the node of the Nth menu item.
2847 N is the digit argument used to invoke this command."
2850 (Info-extract-menu-counting
2851 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2853 (defun Info-top-node ()
2854 "Go to the Top node of this file."
2856 (Info-goto-node "Top"))
2858 (defun Info-final-node ()
2859 "Go to the final node in this file."
2861 (Info-goto-node "Top")
2862 (let ((Info-history nil
)
2863 (case-fold-search t
))
2864 ;; Go to the last node in the menu of Top. But don't delve into
2865 ;; detailed node listings.
2866 (Info-goto-node (Info-extract-menu-counting nil t
))
2867 ;; If the last node in the menu is not last in pointer structure,
2868 ;; move forward (but not down- or upward - see bug#1116) until we
2869 ;; can't go any farther.
2870 (while (Info-forward-node t t t
) nil
)
2871 ;; Then keep moving down to last subnode, unless we reach an index.
2872 (while (and (not (Info-index-node))
2873 (save-excursion (search-forward "\n* Menu:" nil t
)))
2874 (Info-goto-node (Info-extract-menu-counting nil
)))))
2876 (defun Info-forward-node (&optional not-down not-up no-error
)
2877 "Go forward one node, considering all nodes as forming one sequence."
2879 (goto-char (point-min))
2881 (let ((case-fold-search t
))
2882 ;; three possibilities, in order of priority:
2883 ;; 1. next node is in a menu in this node (but not in an index)
2884 ;; 2. next node is next at same level
2885 ;; 3. next node is up and next
2886 (cond ((and (not not-down
)
2887 (save-excursion (search-forward "\n* menu:" nil t
))
2888 (not (Info-index-node)))
2889 (Info-goto-node (Info-extract-menu-counting 1))
2891 ((save-excursion (search-backward "next:" nil t
))
2895 (save-excursion (search-backward "up:" nil t
))
2896 ;; Use string-equal, not equal, to ignore text props.
2897 (not (string-equal (downcase (Info-extract-pointer "up"))
2899 (let ((old-node Info-current-node
))
2901 (let ((old-history Info-history
)
2904 (setq success
(Info-forward-node t nil no-error
))
2905 (or success
(Info-goto-node old-node
)))
2906 (if Info-history-skip-intermediate-nodes
2907 (setq Info-history old-history
)))))
2909 (t (user-error "No pointer forward from this node")))))
2911 (defun Info-backward-node ()
2912 "Go backward one node, considering all nodes as forming one sequence."
2914 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2915 (upnode (Info-extract-pointer "up" t
))
2916 (case-fold-search t
))
2917 (cond ((and upnode
(string-match "(" upnode
))
2918 (user-error "First node in file"))
2919 ((and upnode
(or (null prevnode
)
2920 ;; Use string-equal, not equal,
2921 ;; to ignore text properties.
2922 (string-equal (downcase prevnode
)
2923 (downcase upnode
))))
2926 ;; If we move back at the same level,
2927 ;; go down to find the last subnode*.
2929 (let ((old-history Info-history
))
2930 (while (and (not (Info-index-node))
2931 (save-excursion (search-forward "\n* Menu:" nil t
)))
2932 (Info-goto-node (Info-extract-menu-counting nil
)))
2933 (if Info-history-skip-intermediate-nodes
2934 (setq Info-history old-history
))))
2936 (user-error "No pointer backward from this node")))))
2939 "Exit Info by selecting some other buffer."
2942 (save-buffers-kill-emacs)
2945 (defun Info-next-menu-item ()
2946 "Go to the node of the next menu item."
2948 ;; Bind this in case the user sets it to nil.
2949 (let* ((case-fold-search t
)
2953 (search-forward "\n* menu:" nil t
)
2954 (and (search-forward "\n* " nil t
)
2955 (Info-extract-menu-node-name)))))
2956 (if node
(Info-goto-node node
)
2957 (user-error "No more items in menu"))))
2959 (defun Info-last-menu-item ()
2960 "Go to the node of the previous menu item."
2964 ;; Bind this in case the user sets it to nil.
2965 (let* ((case-fold-search t
)
2966 (beg (save-excursion
2967 (and (search-backward "\n* menu:" nil t
)
2969 (or (and beg
(search-backward "\n* " beg t
))
2970 (user-error "No previous items in menu")))
2971 (Info-goto-node (save-excursion
2972 (goto-char (match-end 0))
2973 (Info-extract-menu-node-name)))))
2975 (defmacro Info-no-error
(&rest body
)
2976 `(condition-case nil
(progn ,@body t
) (error nil
)))
2978 (defun Info-next-preorder ()
2979 "Go to the next subnode or the next node, or go up a level."
2981 (cond ((Info-no-error (Info-next-menu-item)))
2982 ((Info-no-error (Info-next)))
2983 ((Info-no-error (Info-up t
))
2984 ;; Since we have already gone thru all the items in this menu,
2985 ;; go up to the end of this node.
2986 (goto-char (point-max))
2987 ;; Since logically we are done with the node with that menu,
2988 ;; move on from it. But don't add intermediate nodes
2989 ;; to the history on recursive calls.
2990 (let ((old-history Info-history
))
2991 (Info-next-preorder)
2992 (if Info-history-skip-intermediate-nodes
2993 (setq Info-history old-history
))))
2995 (user-error "No more nodes"))))
2997 (defun Info-last-preorder ()
2998 "Go to the last node, popping up a level if there is none."
3000 (cond ((and Info-scroll-prefer-subnodes
3002 (Info-last-menu-item)
3003 ;; If we go down a menu item, go to the end of the node
3004 ;; so we can scroll back through it.
3005 (goto-char (point-max))))
3006 ;; Keep going down, as long as there are nested menu nodes.
3007 (let ((old-history Info-history
))
3008 (while (Info-no-error
3009 (Info-last-menu-item)
3010 ;; If we go down a menu item, go to the end of the node
3011 ;; so we can scroll back through it.
3012 (goto-char (point-max))))
3013 (if Info-history-skip-intermediate-nodes
3014 (setq Info-history old-history
)))
3016 ((and (Info-no-error (Info-extract-pointer "prev"))
3017 (not (equal (Info-extract-pointer "up")
3018 (Info-extract-pointer "prev"))))
3019 (Info-no-error (Info-prev))
3020 (goto-char (point-max))
3021 (let ((old-history Info-history
))
3022 (while (Info-no-error
3023 (Info-last-menu-item)
3024 ;; If we go down a menu item, go to the end of the node
3025 ;; so we can scroll back through it.
3026 (goto-char (point-max))))
3027 (if Info-history-skip-intermediate-nodes
3028 (setq Info-history old-history
)))
3030 ((Info-no-error (Info-up t
))
3031 (goto-char (point-min))
3032 (let ((case-fold-search t
))
3033 (or (search-forward "\n* Menu:" nil t
)
3034 (goto-char (point-max)))))
3035 (t (user-error "No previous nodes"))))
3037 (defun Info-scroll-up ()
3038 "Scroll one screenful forward in Info, considering all nodes as one sequence.
3039 Once you scroll far enough in a node that its menu appears on the screen
3040 but after point, the next scroll moves into its first subnode, unless
3041 `Info-scroll-prefer-subnodes' is nil.
3043 When you scroll past the end of a node, that goes to the next node if
3044 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3045 if this node has no successor, it moves to the parent node's successor,
3046 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3047 the menu of a node, it moves to subnode indicated by the following menu
3048 item. (That case won't normally result from this command, but can happen
3052 (if (or (< (window-start) (point-min))
3053 (> (window-start) (point-max)))
3054 (set-window-start (selected-window) (point)))
3055 (let* ((case-fold-search t
)
3056 (virtual-end (save-excursion
3057 (goto-char (point-min))
3058 (if (and Info-scroll-prefer-subnodes
3059 (search-forward "\n* Menu:" nil t
))
3062 (if (or (< virtual-end
(window-start))
3063 (pos-visible-in-window-p virtual-end
))
3065 (Info-scroll-prefer-subnodes (Info-next-preorder))
3066 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3067 (t (Info-next-preorder)))
3070 (defun Info-mouse-scroll-up (e)
3071 "Scroll one screenful forward in Info, using the mouse.
3072 See `Info-scroll-up'."
3074 (save-selected-window
3076 (select-window (posn-window (event-start e
))))
3079 (defun Info-scroll-down ()
3080 "Scroll one screenful back in Info, considering all nodes as one sequence.
3081 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3082 is non-nil, this goes to its last subnode. When you scroll past the
3083 beginning of a node, that goes to the previous node or back up to the
3086 (if (or (< (window-start) (point-min))
3087 (> (window-start) (point-max)))
3088 (set-window-start (selected-window) (point)))
3089 (let* ((case-fold-search t
)
3090 (current-point (point))
3092 (and Info-scroll-prefer-subnodes
3094 (setq current-point
(line-beginning-position))
3095 (goto-char (point-min))
3096 (search-forward "\n* Menu:" current-point t
)))))
3098 (pos-visible-in-window-p (point-min) nil t
))
3099 (Info-last-preorder)
3102 (defun Info-mouse-scroll-down (e)
3103 "Scroll one screenful backward in Info, using the mouse.
3104 See `Info-scroll-down'."
3106 (save-selected-window
3108 (select-window (posn-window (event-start e
))))
3109 (Info-scroll-down)))
3111 (defun Info-next-reference-or-link (pat prop
)
3112 "Move point to the next pattern-based cross-reference or property-based link.
3113 The next cross-reference is searched using the regexp PAT, and the next link
3114 is searched using the text property PROP. Move point to the closest found position
3115 of either a cross-reference found by `re-search-forward' or a link found by
3116 `next-single-char-property-change'. Return the new position of point, or nil."
3117 (let ((pxref (save-excursion (re-search-forward pat nil t
)))
3118 (plink (next-single-char-property-change (point) prop
)))
3119 (when (and (< plink
(point-max)) (not (get-char-property plink prop
)))
3120 (setq plink
(next-single-char-property-change plink prop
)))
3121 (if (< plink
(point-max))
3122 (if (and pxref
(<= pxref plink
))
3123 (goto-char (or (match-beginning 1) (match-beginning 0)))
3125 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3127 (defun Info-prev-reference-or-link (pat prop
)
3128 "Move point to the previous pattern-based cross-reference or property-based link.
3129 The previous cross-reference is searched using the regexp PAT, and the previous link
3130 is searched using the text property PROP. Move point to the closest found position
3131 of either a cross-reference found by `re-search-backward' or a link found by
3132 `previous-single-char-property-change'. Return the new position of point, or nil."
3133 (let ((pxref (save-excursion (re-search-backward pat nil t
)))
3134 (plink (previous-single-char-property-change (point) prop
)))
3135 (when (and (> plink
(point-min)) (not (get-char-property plink prop
)))
3136 (setq plink
(previous-single-char-property-change plink prop
)))
3137 (if (> plink
(point-min))
3138 (if (and pxref
(>= pxref plink
))
3139 (goto-char (or (match-beginning 1) (match-beginning 0)))
3141 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3143 (defun Info-next-reference (&optional recur count
)
3144 "Move cursor to the next cross-reference or menu item in the node.
3145 If COUNT is non-nil (interactively with a prefix arg), jump over
3146 COUNT cross-references."
3147 (interactive "i\np")
3151 (Info-prev-reference recur
(- count
))
3152 (while (unless (zerop count
) (setq count
(1- count
)))
3153 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3155 (case-fold-search t
))
3156 (or (eobp) (forward-char 1))
3157 (or (Info-next-reference-or-link pat
'link
)
3159 (goto-char (point-min))
3160 (or (Info-next-reference-or-link pat
'link
)
3163 (user-error "No cross references in this node")))))
3164 (if (looking-at "\\* Menu:")
3166 (user-error "No cross references in this node")
3167 (Info-next-reference t
))
3168 (if (looking-at "^\\* ")
3169 (forward-char 2)))))))
3171 (defun Info-prev-reference (&optional recur count
)
3172 "Move cursor to the previous cross-reference or menu item in the node.
3173 If COUNT is non-nil (interactively with a prefix arg), jump over
3174 COUNT cross-references."
3175 (interactive "i\np")
3179 (Info-next-reference recur
(- count
))
3180 (while (unless (zerop count
) (setq count
(1- count
)))
3181 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3183 (case-fold-search t
))
3184 (or (Info-prev-reference-or-link pat
'link
)
3186 (goto-char (point-max))
3187 (or (Info-prev-reference-or-link pat
'link
)
3190 (user-error "No cross references in this node")))))
3191 (if (looking-at "\\* Menu:")
3193 (user-error "No cross references in this node")
3194 (Info-prev-reference t
))
3195 (if (looking-at "^\\* ")
3196 (forward-char 2)))))))
3198 (defun Info-index-nodes (&optional file
)
3199 "Return a list of names of all index nodes in Info FILE.
3200 If FILE is omitted, it defaults to the current Info file.
3201 First look in a list of cached index node names. Then scan Info
3202 file and its subfiles for nodes with the index cookie. Then try
3203 to find index nodes starting from the first node in the top level
3204 menu whose name contains the word \"Index\", plus any immediately
3205 following nodes whose names also contain the word \"Index\"."
3206 (or file
(setq file Info-current-file
))
3207 (or (assoc file Info-index-nodes
)
3208 ;; Skip virtual Info files
3209 (and (or (not (stringp file
))
3210 (Info-virtual-file-p file
))
3211 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3212 (if (Info-file-supports-index-cookies file
)
3213 ;; Find nodes with index cookie
3214 (let* ((default-directory (or (and (stringp file
)
3215 (file-name-directory
3216 (setq file
(Info-find-file file
))))
3218 Info-history Info-history-list Info-fontify-maximum-menu-size
3219 (main-file file
) subfiles nodes
)
3222 (while (or main-file subfiles
)
3224 (info-insert-file-contents (or main-file
(car subfiles
)))
3225 (goto-char (point-min))
3226 (while (search-forward "\0\b[index\0\b]" nil
'move
)
3228 (re-search-backward "^\^_")
3229 (search-forward "Node: ")
3230 (setq nodes
(cons (Info-following-node-name) nodes
))))
3233 (goto-char (point-min))
3234 (if (search-forward "\n\^_\nIndirect:" nil t
)
3235 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
3236 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
3237 (setq subfiles
(cons (match-string-no-properties 1)
3239 (setq subfiles
(nreverse subfiles
)
3241 (setq subfiles
(cdr subfiles
)))))
3244 (setq nodes
(nreverse nodes
)
3245 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3247 ;; Else find nodes with the word "Index" in the node name
3248 (let ((case-fold-search t
)
3249 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3254 (Info-find-node file
"Top")
3255 (when (and (search-forward "\n* menu:" nil t
)
3256 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
3257 (goto-char (match-beginning 1))
3258 (setq nodes
(list (Info-extract-menu-node-name)))
3259 (Info-goto-node (car nodes
))
3260 (while (and (setq node
(Info-extract-pointer "next" t
))
3261 (string-match "\\<Index\\>" node
))
3263 (Info-goto-node node
))))
3266 (setq nodes
(nreverse nodes
)
3267 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3269 ;; If file has no index nodes, still add it to the cache
3270 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3271 (cdr (assoc file Info-index-nodes
)))
3273 (defun Info-index-node (&optional node file
)
3274 "Return non-nil value if NODE is an index node.
3275 If NODE is nil, check the current Info node.
3276 If FILE is nil, check the current Info file."
3277 (or file
(setq file Info-current-file
))
3278 (if (and (or (and node
(not (equal node Info-current-node
)))
3279 (assoc file Info-index-nodes
))
3280 (not Info-current-node-virtual
))
3281 (member (or node Info-current-node
) (Info-index-nodes file
))
3282 ;; Don't search all index nodes if request is only for the current node
3283 ;; and file is not in the cache of index nodes
3285 (if (Info-file-supports-index-cookies file
)
3287 (goto-char (+ (or (save-excursion
3288 (search-backward "\n\^_" nil t
))
3290 (search-forward "\0\b[index\0\b]"
3292 (search-forward "\n\^_" nil t
))
3294 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3296 (defun Info-goto-index ()
3297 "Go to the first index node."
3298 (let ((node (car (Info-index-nodes))))
3299 (or node
(error "No index"))
3300 (Info-goto-node node
)))
3303 (defun Info-index (topic)
3304 "Look up a string TOPIC in the index for this manual and go to that entry.
3305 If there are no exact matches to the specified topic, this chooses
3306 the first match which is a case-insensitive substring of a topic.
3307 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3308 Give an empty topic name to go to the Index node itself."
3311 (let ((completion-ignore-case t
)
3312 (Info-complete-menu-buffer (clone-buffer))
3313 (Info-complete-nodes (Info-index-nodes))
3314 (Info-history-list nil
))
3315 (if (equal Info-current-file
"dir")
3316 (error "The Info directory node has no index; use m to select a manual"))
3318 (with-current-buffer Info-complete-menu-buffer
3320 (completing-read "Index topic: " #'Info-complete-menu-item
))
3321 (kill-buffer Info-complete-menu-buffer
)))))
3322 (if (equal Info-current-file
"dir")
3323 (error "The Info directory node has no index; use m to select a manual"))
3324 ;; Strip leading colon in topic; index format does not allow them.
3325 (if (and (stringp topic
)
3326 (> (length topic
) 0)
3327 (= (aref topic
0) ?
:))
3328 (setq topic
(substring topic
1)))
3329 (let ((orignode Info-current-node
)
3330 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3331 (regexp-quote topic
)))
3332 node
(nodes (Info-index-nodes))
3333 (ohist-list Info-history-list
)
3334 (case-fold-search t
))
3336 (or (equal topic
"")
3339 ;; We bind Info-history to nil for internal node-switches so
3340 ;; that we don't put junk in the history. In the first
3341 ;; Info-goto-index call, above, we do update the history
3342 ;; because that is what the user's previous node choice into it.
3347 (goto-char (point-min))
3348 (while (re-search-forward pattern nil t
)
3349 (let ((entry (match-string-no-properties 1))
3350 (nodename (match-string-no-properties 3))
3351 (line (string-to-number (concat "0" (match-string 4)))))
3352 (add-text-properties
3353 (- (match-beginning 2) (match-beginning 1))
3354 (- (match-end 2) (match-beginning 1))
3355 '(face info-index-match
) entry
)
3356 (push (list entry nodename Info-current-node line
) matches
)))
3357 (setq nodes
(cdr nodes
) node
(car nodes
)))
3358 (Info-goto-node node
))
3361 (Info-goto-node orignode
)
3362 (user-error "No `%s' in index" topic
)))
3363 ;; Here it is a feature that assoc is case-sensitive.
3364 (while (setq found
(assoc topic matches
))
3365 (setq exact
(cons found exact
)
3366 matches
(delq found matches
)))
3367 (setq Info-history-list ohist-list
)
3368 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3369 (Info-index-next 0)))))
3371 (defun Info-index-next (num)
3372 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3374 (or Info-index-alternatives
3375 (user-error "No previous `i' command"))
3377 (setq num
(+ num
(length Info-index-alternatives
))))
3379 (setq Info-index-alternatives
3380 (nconc (cdr Info-index-alternatives
)
3381 (list (car Info-index-alternatives
)))
3383 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3384 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3385 ;; Forward 2 lines less because `Info-find-node-2' initially
3386 ;; puts point to the 2nd line.
3387 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3388 (forward-line 3) ; don't search in headers
3389 (let ((name (car (car Info-index-alternatives
))))
3390 (Info-find-index-name name
)))
3391 (message "Found `%s' in %s. %s"
3392 (car (car Info-index-alternatives
))
3393 (nth 2 (car Info-index-alternatives
))
3394 (if (cdr Info-index-alternatives
)
3396 "(%s total; use `%s' for next)"
3397 (length Info-index-alternatives
)
3398 (key-description (where-is-internal
3399 'Info-index-next overriding-local-map t
)))
3402 (defun Info-find-index-name (name)
3403 "Move point to the place within the current node where NAME is defined."
3404 (let ((case-fold-search t
))
3405 (if (or (re-search-forward (format
3406 "[a-zA-Z]+: %s\\( \\|$\\)"
3407 (regexp-quote name
)) nil t
)
3408 ;; Find a function definition with a return type.
3409 (re-search-forward (format
3410 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3411 (regexp-quote name
)) nil t
)
3412 (search-forward (format "['`‘]%s['’]" name
) nil t
)
3413 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3415 (format "['`‘]%s['’]" (substring name
0 (match-beginning 1)))
3417 (search-forward name nil t
)
3418 ;; Try again without the " <1>" makeinfo can append
3419 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3420 (Info-find-index-name (match-string 1 name
))))
3421 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3422 (goto-char (point-min)))))
3424 (add-to-list 'Info-virtual-nodes
3425 '("\\`\\*Index.*\\*\\'"
3426 (find-node . Info-virtual-index-find-node
)
3430 (defvar Info-virtual-index-nodes nil
3431 "Alist of cached matched index search nodes.
3432 Each element is ((FILENAME . TOPIC) MATCHES) where
3433 FILENAME is the file name of the manual,
3434 TOPIC is the search string given as an argument to `Info-virtual-index',
3435 MATCHES is a list of index matches found by `Info-index'.")
3437 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3438 "Index-specific implementation of `Info-find-node-2'."
3439 ;; Generate Index-like menu of matches
3440 (if (string-match "^\\*Index for ‘\\(.+\\)’\\*$" nodename
)
3441 ;; Generate Index-like menu of matches
3442 (let* ((topic (match-string 1 nodename
))
3443 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3444 Info-virtual-index-nodes
))))
3445 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3446 (or filename Info-current-file
) nodename
))
3447 (insert "Info Virtual Index\n")
3448 (insert "******************\n\n")
3449 (insert "Index entries that match ‘" topic
"’:\n\n")
3450 (insert "\0\b[index\0\b]\n")
3452 (insert "No matches found.\n")
3453 (insert "* Menu:\n\n")
3454 (dolist (entry matches
)
3455 (insert (format "* %-38s %s.%s\n"
3456 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3459 (format " (line %s)" (nth 3 entry
))
3461 ;; Else, Generate a list of previous search results
3462 (let ((nodes (reverse Info-virtual-index-nodes
)))
3463 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3464 (or filename Info-current-file
) nodename
))
3465 (insert "Info Virtual Index\n")
3466 (insert "******************\n\n")
3467 (insert "This is a list of search results produced by\n"
3468 "‘Info-virtual-index’ for the current manual.\n\n")
3469 (insert "* Menu:\n\n")
3470 (dolist (nodeinfo nodes
)
3471 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3473 (format "* %-20s %s.\n"
3474 (format "*Index for ‘%s’*::" (cdr (nth 0 nodeinfo
)))
3475 (cdr (nth 0 nodeinfo
)))))))))
3477 (defun Info-virtual-index (topic)
3478 "Show a node with all lines in the index containing a string TOPIC.
3479 Like `Info-index' but displays a node with index search results.
3480 Give an empty topic name to go to the node with links to previous
3482 ;; `interactive' is a copy from `Info-index'
3485 (let ((completion-ignore-case t
)
3486 (Info-complete-menu-buffer (clone-buffer))
3487 (Info-complete-nodes (Info-index-nodes))
3488 (Info-history-list nil
))
3489 (if (equal Info-current-file
"dir")
3490 (error "The Info directory node has no index; use m to select a manual"))
3492 (with-current-buffer Info-complete-menu-buffer
3494 (completing-read "Index topic: " #'Info-complete-menu-item
))
3495 (kill-buffer Info-complete-menu-buffer
)))))
3496 (if (equal topic
"")
3497 (Info-find-node Info-current-file
"*Index*")
3498 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3499 (let ((orignode Info-current-node
)
3500 (ohist-list Info-history-list
))
3501 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3503 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3504 Info-virtual-index-nodes
)
3505 ;; Clean up unnecessary side-effects of `Info-index'.
3506 (setq Info-history-list ohist-list
)
3507 (Info-goto-node orignode
)
3509 (Info-find-node Info-current-file
3510 (format "*Index for ‘%s’*" topic
))))
3512 (add-to-list 'Info-virtual-files
3513 '("\\`\\*Apropos\\*\\'"
3514 (toc-nodes . Info-apropos-toc-nodes
)
3515 (find-file . Info-apropos-find-file
)
3516 (find-node . Info-apropos-find-node
)
3520 (defvar Info-apropos-file
"*Apropos*"
3521 "Info file name of the virtual manual for matches of `info-apropos'.")
3523 (defvar Info-apropos-nodes nil
3524 "Alist of cached apropos matched nodes.
3525 Each element is (NODENAME STRING MATCHES) where
3526 NODENAME is the name of the node that holds the search result,
3527 STRING is the search string given as an argument to `info-apropos',
3528 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3530 (defun Info-apropos-toc-nodes (filename)
3531 "Apropos-specific implementation of `Info-toc-nodes'."
3532 (let ((nodes (mapcar #'car
(reverse Info-apropos-nodes
))))
3534 ("Top" nil nil
,nodes
)
3535 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3537 (defun Info-apropos-find-file (filename &optional _noerror
)
3538 "Apropos-specific implementation of `Info-find-file'."
3541 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3542 "Apropos-specific implementation of `Info-find-node-2'."
3543 (if (equal nodename
"Top")
3544 ;; Generate Top menu
3545 (let ((nodes (reverse Info-apropos-nodes
)))
3546 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3547 Info-apropos-file nodename
))
3548 (insert "Apropos Index\n")
3549 (insert "*************\n\n")
3550 (insert "This is a list of search results produced by ‘info-apropos’.\n\n")
3551 (insert "* Menu:\n\n")
3552 (dolist (nodeinfo nodes
)
3553 (insert (format "* %-20s %s.\n"
3554 (format "%s::" (nth 0 nodeinfo
))
3555 (nth 1 nodeinfo
)))))
3556 ;; Else, Generate Index-like menu of matches
3557 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3558 (matches (nth 2 nodeinfo
)))
3560 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3561 Info-apropos-file nodename
))
3562 (insert "Apropos Index\n")
3563 (insert "*************\n\n")
3564 (insert "Index entries that match ‘" (nth 1 nodeinfo
) "’:\n\n")
3565 (insert "\0\b[index\0\b]\n")
3567 (insert "No matches found.\n")
3568 (insert "* Menu:\n\n")
3569 (dolist (entry matches
)
3570 (insert (format "* %-38s (%s)%s.%s\n"
3571 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3575 (format " (line %s)" (nth 3 entry
))
3578 (defun Info-apropos-matches (string)
3579 "Collect STRING matches from all known Info files on your system.
3580 Return a list of matches where each element is in the format
3581 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3582 (unless (string= string
"")
3583 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3584 (regexp-quote string
)))
3585 (ohist Info-history
)
3586 (ohist-list Info-history-list
)
3587 (current-node Info-current-node
)
3588 (current-file Info-current-file
)
3589 manuals matches node nodes
)
3590 (let ((Info-fontify-maximum-menu-size nil
))
3592 ;; current-node and current-file are nil when they invoke info-apropos
3593 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3594 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3595 ;; the search is complete.
3596 (when (null current-node
)
3597 (setq current-file Info-current-file
)
3598 (setq current-node Info-current-node
))
3599 (message "Searching indices...")
3600 (goto-char (point-min))
3601 (re-search-forward "\\* Menu: *\n" nil t
)
3602 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3603 ;; Make sure we don't have duplicates in `manuals',
3604 ;; so that the following dolist loop runs faster.
3605 (cl-pushnew (match-string 1) manuals
:test
#'equal
))
3606 (dolist (manual (nreverse manuals
))
3607 (message "Searching %s" manual
)
3609 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3611 (Info-find-node manual
(car nodes
))
3614 (goto-char (point-min))
3615 (while (re-search-forward pattern nil t
)
3616 (let ((entry (match-string-no-properties 1))
3617 (nodename (match-string-no-properties 3))
3618 (line (match-string-no-properties 4)))
3619 (add-text-properties
3620 (- (match-beginning 2) (match-beginning 1))
3621 (- (match-end 2) (match-beginning 1))
3622 '(face info-index-match
) entry
)
3623 (setq matches
(cons (list manual entry nodename line
)
3625 (setq nodes
(cdr nodes
) node
(car nodes
)))
3626 (Info-goto-node node
))))
3628 (message "%s" (if (eq (car-safe err
) 'error
)
3631 (Info-find-node current-file current-node
)
3632 (setq Info-history ohist
3633 Info-history-list ohist-list
)
3634 (message "Searching indices...done")
3635 (or (nreverse matches
) t
))))
3638 (defun info-apropos (string)
3639 "Grovel indices of all known Info files on your system for STRING.
3640 Build a menu of the possible matches."
3641 (interactive "sIndex apropos: ")
3642 (if (equal string
"")
3643 (Info-find-node Info-apropos-file
"Top")
3644 (let* ((nodes Info-apropos-nodes
) nodename
)
3645 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3646 (setq nodes
(cdr nodes
)))
3648 (Info-find-node Info-apropos-file
(car (car nodes
)))
3649 (setq nodename
(format "Index for ‘%s’" string
))
3650 (push (list nodename string
(Info-apropos-matches string
))
3652 (Info-find-node Info-apropos-file nodename
)))))
3654 (add-to-list 'Info-virtual-files
3655 '("\\`\\*Finder.*\\*\\'"
3656 (find-file . Info-finder-find-file
)
3657 (find-node . Info-finder-find-node
)
3660 (defvar Info-finder-file
"*Finder*"
3661 "Info file name of the virtual Info keyword finder manual.")
3663 (defun Info-finder-find-file (filename &optional _noerror
)
3664 "Finder-specific implementation of `Info-find-file'."
3667 (defvar finder-known-keywords
)
3668 (declare-function find-library-name
"find-func" (library))
3669 (declare-function finder-unknown-keywords
"finder" ())
3670 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3671 (defvar finder-keywords-hash
)
3672 (defvar package--builtins
) ; finder requires package
3674 (defun info--prettify-description (desc)
3677 (insert (substitute-command-keys desc
))
3678 (if (equal ?.
(char-before))
3680 (goto-char (point-min))
3681 (or (let (case-fold-search) (looking-at-p "\\.\\|[[:upper:]]"))
3682 (capitalize-word 1))
3686 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3687 "Finder-specific implementation of `Info-find-node-2'."
3690 ((equal nodename
"Top")
3691 ;; Display Top menu with descriptions of the keywords
3692 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3693 Info-finder-file nodename
))
3694 (insert "Finder Keywords\n")
3695 (insert "***************\n\n")
3696 (insert "* Menu:\n\n")
3697 (dolist (assoc (append '((all .
"All package info")
3698 (unknown .
"Unknown keywords"))
3699 finder-known-keywords
))
3700 (let ((keyword (car assoc
)))
3701 (insert (format "* %s %s.\n"
3702 (concat (symbol-name keyword
) ": "
3703 "Keyword " (symbol-name keyword
) ".")
3704 (info--prettify-description (cdr assoc
)))))))
3705 ((equal nodename
"Keyword unknown")
3706 ;; Display unknown keywords
3707 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3708 Info-finder-file nodename
))
3709 (insert "Finder Unknown Keywords\n")
3710 (insert "***********************\n\n")
3711 (insert "* Menu:\n\n")
3714 (insert (format "* %-14s %s.\n"
3715 (concat (symbol-name (car assoc
)) ": "
3716 "Keyword " (symbol-name (car assoc
)) ".")
3718 (finder-unknown-keywords)))
3719 ((equal nodename
"Keyword all")
3720 ;; Display all package info.
3721 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3722 Info-finder-file nodename
))
3723 (insert "Finder Package Info\n")
3724 (insert "*******************\n\n")
3725 (insert "* Menu:\n\n")
3727 (dolist (package package--builtins
)
3728 (setq desc
(cdr-safe package
))
3729 (when (vectorp desc
)
3730 (insert (format "* %-16s %s.\n"
3731 (concat (symbol-name (car package
)) "::")
3732 (info--prettify-description (aref desc
2))))))))
3733 ((string-match "\\`Keyword " nodename
)
3734 (setq nodename
(substring nodename
(match-end 0)))
3735 ;; Display packages that match the keyword
3736 ;; or the list of keywords separated by comma.
3737 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3738 Info-finder-file nodename
))
3739 (insert "Finder Packages\n")
3740 (insert "***************\n\n")
3742 "The following packages match the keyword ‘" nodename
"’:\n\n")
3743 (insert "* Menu:\n\n")
3745 (mapcar #'intern
(if (string-match-p "," nodename
)
3746 (split-string nodename
",[ \t\n]*" t
)
3749 (dolist (keyword keywords
)
3750 (push (copy-tree (gethash keyword finder-keywords-hash
)) hits
))
3751 (setq hits
(delete-dups (apply #'append hits
))
3752 ;; Not a meaningful package.
3753 hits
(delete 'emacs hits
)
3754 hits
(sort hits
(lambda (a b
) (string< (symbol-name a
)
3756 (dolist (package hits
)
3757 (setq desc
(cdr-safe (assq package package--builtins
)))
3758 (when (vectorp desc
)
3759 (insert (format "* %-16s %s.\n"
3760 (concat (symbol-name package
) "::")
3761 (info--prettify-description (aref desc
2))))))))
3763 ;; Display commentary section
3764 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3765 Info-finder-file nodename
))
3766 (insert "Package Description\n")
3767 (insert "*******************\n\n")
3769 "Description of the package ‘" nodename
"’:\n\n")
3770 ;; This assumes that a file named package.el exists,
3771 ;; which is not always true. E.g. for the nxml package,
3772 ;; there is no "nxml.el" (it's nxml-mode.el).
3773 ;; But package.el makes the same assumption.
3774 ;; I think nxml is the only exception - maybe it should be just be renamed.
3775 (let ((str (ignore-errors (lm-commentary (find-library-name nodename
)))))
3777 (insert "Can’t find package description.\n\n")
3781 (goto-char (point-min))
3782 (delete-blank-lines)
3783 (goto-char (point-max))
3784 (delete-blank-lines)
3785 (goto-char (point-min))
3786 (while (re-search-forward "^;+ ?" nil t
)
3787 (replace-match "" nil nil
))
3788 (buffer-string))))))))
3791 (defun info-finder (&optional keywords
)
3792 "Display descriptions of the keywords in the Finder virtual manual.
3793 In interactive use, a prefix argument directs this command to read
3794 a list of keywords separated by comma. After that, it displays a node
3795 with a list of packages that contain all specified keywords."
3797 (when current-prefix-arg
3800 (completing-read-multiple
3801 "Keywords (separated by comma): "
3802 (mapcar #'symbol-name
(mapcar #'car
(append finder-known-keywords
3803 (finder-unknown-keywords))))
3807 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3808 (Info-find-node Info-finder-file
"Top")))
3811 (defun Info-undefined ()
3812 "Make command be undefined in Info."
3817 "Enter the Info tutorial."
3819 (delete-other-windows)
3820 (Info-find-node "info"
3821 (if (< (window-height) 23)
3825 (defun Info-summary ()
3826 "Display a brief summary of all Info commands."
3828 (save-window-excursion
3829 (switch-to-buffer "*Help*")
3830 (setq buffer-read-only nil
)
3832 (insert (documentation 'Info-mode
))
3834 (goto-char (point-min))
3836 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3837 (message (if flag
"Type Space to see more"
3838 "Type Space to return to Info"))
3839 (if (not (eq ?\s
(setq ch
(read-event))))
3840 (progn (push ch unread-command-events
) nil
)
3843 (bury-buffer "*Help*")))
3845 (defun Info-get-token (pos start all
&optional errorstring
)
3846 "Return the token around POS.
3847 POS must be somewhere inside the token.
3848 START is a regular expression which will match the
3849 beginning of the tokens delimited string.
3850 ALL is a regular expression with a single
3851 parenthesized subpattern which is the token to be
3852 returned. E.g. `{(.*)}' would return any string
3853 enclosed in braces around POS.
3854 ERRORSTRING optional fourth argument, controls action on no match:
3857 a string: signal an error, using that string."
3858 (let ((case-fold-search t
))
3861 ;; First look for a match for START that goes across POS.
3862 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3863 (not (looking-at start
)))
3865 ;; If we did not find one, search back for START
3866 ;; (this finds only matches that end at or before POS).
3867 (or (looking-at start
)
3870 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3872 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3873 (not (setq found
(and (<= (match-beginning 0) pos
)
3874 (> (match-end 0) pos
))))))
3875 (if (and found
(<= (match-beginning 0) pos
)
3876 (> (match-end 0) pos
))
3877 (match-string-no-properties 1)
3878 (cond ((null errorstring
)
3884 (error "No %s around position %d" errorstring pos
))))))))
3886 (defun Info-mouse-follow-nearest-node (click)
3887 "\\<Info-mode-map>Follow a node reference near point.
3888 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3889 At end of the node's text, moves to the next node, or up if none."
3891 (mouse-set-point click
)
3892 (and (not (Info-follow-nearest-node))
3893 (save-excursion (forward-line 1) (eobp))
3894 (Info-next-preorder)))
3896 (defun Info-follow-nearest-node (&optional fork
)
3897 "Follow a node reference near point.
3898 If point is on a reference, follow that reference. Otherwise,
3899 if point is in a menu item description, follow that menu item.
3901 If FORK is non-nil (interactively with a prefix arg), show the node in
3903 If FORK is a string, it is the name to use for the new buffer."
3905 (or (Info-try-follow-nearest-node fork
)
3906 (when (save-excursion
3907 (search-backward "\n* menu:" nil t
))
3910 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3911 (beginning-of-line 0))
3912 (when (looking-at "\\* +\\([^\t\n]*\\):")
3914 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3916 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3917 ;; Don't raise an error when mouse-1 is bound to this - it's
3918 ;; often used to simply select the window or frame.
3919 (eq 'mouse-1
(event-basic-type last-input-event
)))
3920 (user-error "Point neither on reference nor in menu item description")))
3922 ;; Common subroutine.
3923 (defun Info-try-follow-nearest-node (&optional fork
)
3924 "Follow a node reference near point. Return non-nil if successful.
3925 If FORK is non-nil, it is passed to `Info-goto-node'."
3928 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3929 "\\([hf]t?tps?://[^ \t\n\"`‘({<>})’']+\\)"))
3932 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3933 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3934 (Info-follow-reference node fork
))
3936 ((setq node
(Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3937 (let ((old-point (point)) new-point
)
3939 (goto-char (point-min))
3940 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t
)
3941 (setq new-point
(if (< old-point
(point))
3942 ;; Go to footnote reference
3943 (and (search-forward node nil t
)
3944 ;; Put point at beginning of link
3945 (match-beginning 0))
3946 ;; Go to footnote definition
3947 (search-backward node nil t
)))))
3950 (goto-char new-point
)
3953 ;; menu item: node name
3954 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3955 (Info-goto-node node fork
))
3956 ;; menu item: node name or index entry
3957 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3960 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3961 (Info-goto-node node fork
))
3962 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3963 (Info-goto-node node fork
))
3964 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3965 (Info-goto-node node fork
))
3966 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3967 (Info-goto-node "Top" fork
))
3968 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3969 (Info-goto-node node fork
)))
3972 (defun Info-mouse-follow-link (click)
3973 "Follow a link where you click."
3975 (let* ((position (event-start click
))
3976 (posn-string (and position
(posn-string position
)))
3977 (link-args (if posn-string
3978 (get-text-property (cdr posn-string
)
3981 (get-char-property (posn-point position
)
3983 (cond ((stringp link-args
)
3984 (Info-goto-node link-args
))
3985 ;; These special values of the `link-args' property are used
3986 ;; for navigation; see `Info-fontify-node'.
3987 ((eq link-args
'prev
) (Info-prev))
3988 ((eq link-args
'next
) (Info-next))
3989 ((eq link-args
'up
) (Info-up)))))
3992 (defvar Info-mode-map
3993 (let ((map (make-keymap)))
3994 (suppress-keymap map
)
3995 (define-key map
"." 'beginning-of-buffer
)
3996 (define-key map
" " 'Info-scroll-up
)
3997 (define-key map
[?\S-\
] 'Info-scroll-down
)
3998 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3999 (define-key map
"\t" 'Info-next-reference
)
4000 (define-key map
"\e\t" 'Info-prev-reference
)
4001 (define-key map
[backtab] 'Info-prev-reference)
4002 (define-key map "1" 'Info-nth-menu-item)
4003 (define-key map "2" 'Info-nth-menu-item)
4004 (define-key map "3" 'Info-nth-menu-item)
4005 (define-key map "4" 'Info-nth-menu-item)
4006 (define-key map "5" 'Info-nth-menu-item)
4007 (define-key map "6" 'Info-nth-menu-item)
4008 (define-key map "7" 'Info-nth-menu-item)
4009 (define-key map "8" 'Info-nth-menu-item)
4010 (define-key map "9" 'Info-nth-menu-item)
4011 (define-key map "0" 'undefined)
4012 (define-key map "?" 'Info-summary)
4013 (define-key map "]" 'Info-forward-node)
4014 (define-key map "[" 'Info-backward-node)
4015 (define-key map "<" 'Info-top-node)
4016 (define-key map ">" 'Info-final-node)
4017 (define-key map "b" 'beginning-of-buffer)
4018 (put 'beginning-of-buffer :advertised-binding "b")
4019 (define-key map "d" 'Info-directory)
4020 (define-key map "e" 'end-of-buffer)
4021 (define-key map "f" 'Info-follow-reference)
4022 (define-key map "g" 'Info-goto-node)
4023 (define-key map "h" 'Info-help)
4024 ;; This is for compatibility with standalone info (>~ version 5.2).
4025 ;; Though for some time, standalone info had H and h reversed.
4026 ;; See <https://debbugs.gnu.org/16455>.
4027 (define-key map "H" 'describe-mode)
4028 (define-key map "i" 'Info-index)
4029 (define-key map "I" 'Info-virtual-index)
4030 (define-key map "l" 'Info-history-back)
4031 (define-key map "L" 'Info-history)
4032 (define-key map "m" 'Info-menu)
4033 (define-key map "n" 'Info-next)
4034 (define-key map "p" 'Info-prev)
4035 (define-key map "q" 'Info-exit)
4036 (define-key map "r" 'Info-history-forward)
4037 (define-key map "s" 'Info-search)
4038 (define-key map "S" 'Info-search-case-sensitively)
4039 (define-key map "\M-n" 'clone-buffer)
4040 (define-key map "t" 'Info-top-node)
4041 (define-key map "T" 'Info-toc)
4042 (define-key map "u" 'Info-up)
4043 ;; `w' for consistency with `dired-copy-filename-as-kill'.
4044 (define-key map "w" 'Info-copy-current-node-name)
4045 (define-key map "c" 'Info-copy-current-node-name)
4046 ;; `^' for consistency with `dired-up-directory'.
4047 (define-key map "^" 'Info-up)
4048 (define-key map "," 'Info-index-next)
4049 (define-key map "\177" 'Info-scroll-down)
4050 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
4051 (define-key map [follow-link] 'mouse-face)
4052 (define-key map [XF86Back] 'Info-history-back)
4053 (define-key map [XF86Forward] 'Info-history-forward)
4055 "Keymap containing Info commands.")
4058 (defun Info-check-pointer (item)
4059 "Non-nil if ITEM is present in this node."
4061 (Info-extract-pointer item)
4065 Info-mode-menu Info-mode-map
4066 "Menu for Info files."
4068 ["Up" Info-up :active (Info-check-pointer "up")
4069 :help "Go up in the Info tree"]
4070 ["Next" Info-next :active (Info-check-pointer "next")
4071 :help "Go to the next node"]
4072 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4073 :help "Go to the previous node"]
4074 ["Backward" Info-backward-node
4075 :help "Go backward one node, considering all as a sequence"]
4076 ["Forward" Info-forward-node
4077 :help "Go forward one node, considering all as a sequence"]
4078 ["Beginning" beginning-of-buffer
4079 :help "Go to beginning of this node"]
4080 ["Top" Info-top-node
4081 :help "Go to top node of file"]
4082 ["Final Node" Info-final-node
4083 :help "Go to final node in this file"]
4084 ("Menu Item" ["You should never see this" report-emacs-bug t])
4085 ("Reference" ["You should never see this" report-emacs-bug t])
4086 ["Search..." Info-search
4087 :help "Search for regular expression in this Info file"]
4088 ["Search Next" Info-search-next
4089 :help "Search for another occurrence of regular expression"]
4090 ["Go to Node..." Info-goto-node
4091 :help "Go to a named node"]
4092 ["Back in history" Info-history-back :active Info-history
4093 :help "Go back in history to the last node you were at"]
4094 ["Forward in history" Info-history-forward :active Info-history-forward
4095 :help "Go forward in history"]
4096 ["History" Info-history :active Info-history-list
4097 :help "Go to menu of visited nodes"]
4098 ["Table of Contents" Info-toc
4099 :help "Go to table of contents"]
4101 ["Lookup a String..." Info-index
4102 :help "Look for a string in the index items"]
4103 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4104 :help "Look for another occurrence of previous item"]
4105 ["Lookup a string and display index of results..." Info-virtual-index
4106 :help "Look for a string in the index items and display node with results"]
4107 ["Lookup a string in all indices..." info-apropos
4108 :help "Look for a string in the indices of all manuals"])
4109 ["Copy Node Name" Info-copy-current-node-name
4110 :help "Copy the name of the current node into the kill ring"]
4111 ["Clone Info buffer" clone-buffer
4112 :help "Create a twin copy of the current Info buffer."]
4113 ["Exit" Info-exit :help "Stop reading Info"]))
4116 (defvar info-tool-bar-map
4117 (let ((map (make-sparse-keymap)))
4118 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4122 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4126 (define-key-after map [separator-1] menu-bar-separator)
4127 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4129 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4131 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4133 (define-key-after map [separator-2] menu-bar-separator)
4134 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4136 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4137 (define-key-after map [separator-3] menu-bar-separator)
4138 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4140 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4142 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4146 (defvar Info-menu-last-node nil)
4147 ;; Last node the menu was created for.
4148 ;; Value is a list, (FILE-NAME NODE-NAME).
4150 (defun Info-menu-update ()
4151 "Update the Info menu for the current node."
4153 (if (or (not (derived-mode-p 'Info-mode))
4154 (equal (list Info-current-file Info-current-node)
4155 Info-menu-last-node))
4157 ;; Update menu menu.
4158 (let* ((Info-complete-menu-buffer (current-buffer))
4159 (items (nreverse (condition-case nil
4160 (Info-complete-menu-item "" nil t)
4164 (while (and items (< number 9))
4165 (setq current (car items)
4168 (setq entries (cons `[,current
4169 (Info-menu ,current)
4170 :keys ,(format "%d" number)]
4173 (setq entries (cons ["Other..." Info-menu t] entries)))
4175 (setq entries (list ["No menu" nil nil] nil :active)))
4176 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4177 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4179 str i entries current
4181 (case-fold-search t))
4183 (goto-char (point-min))
4184 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4185 (setq str (match-string 1))
4187 (while (setq i (string-match "[ \n\t]+" str i))
4188 (setq str (concat (substring str 0 i) " "
4189 (substring str (match-end 0))))
4193 (while (and items (< number 9))
4194 (setq current (car items)
4197 (setq entries (cons `[,current
4198 (Info-follow-reference ,current)
4202 (setq entries (cons ["Other..." Info-follow-reference t]
4205 (setq entries (list ["No references" nil nil] nil :active)))
4206 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4207 ;; Update last seen node.
4208 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4209 ;; Try to avoid entering infinite beep mode in case of errors.
4213 (defun Info-copy-current-node-name (&optional arg)
4214 "Put the name of the current Info node into the kill ring.
4215 The name of the Info file is prepended to the node name in parentheses.
4216 With a zero prefix arg, put the name inside a function call to `info'."
4218 (unless Info-current-node
4219 (user-error "No current Info node"))
4220 (let ((node (if (stringp Info-current-file)
4221 (concat "(" (file-name-sans-extension
4222 (file-name-nondirectory Info-current-file))
4224 Info-current-node))))
4225 (if (zerop (prefix-numeric-value arg))
4226 (setq node (concat "(info \"" node "\")")))
4227 (unless (stringp Info-current-file)
4228 (setq node (format "(Info-find-node '%S '%S)"
4229 Info-current-file Info-current-node)))
4231 (message "%s" node)))
4234 ;; Info mode is suitable only for specially formatted data.
4235 (put 'Info-mode 'mode-class 'special)
4236 (put 'Info-mode 'no-clone-indirect t)
4238 (defvar tool-bar-map)
4239 (defvar bookmark-make-record-function)
4241 (defvar Info-mode-syntax-table
4242 (let ((st (copy-syntax-table text-mode-syntax-table)))
4243 ;; Use punctuation syntax for apostrophe because of
4244 ;; extensive use of quotes like `this' in Info manuals.
4245 (modify-syntax-entry ?' "." st)
4247 "Syntax table used in `Info-mode'.")
4249 (defface Info-quoted
4250 '((t :inherit fixed-pitch-serif))
4251 "Face used for quoted elements.")
4253 ;; We deliberately fontify only ‘..’ quoting, and not `..', because
4254 ;; the former can be done much more reliably, i.e. without risking
4256 (defvar Info-mode-font-lock-keywords
4257 '(("‘\\([^’]*\\)’" (1 'Info-quoted))))
4259 ;; Autoload cookie needed by desktop.el
4261 (define-derived-mode Info-mode nil "Info" ;FIXME: Derive from special-mode?
4262 "Info mode provides commands for browsing through the Info documentation tree.
4263 Documentation in Info is divided into \"nodes\", each of which discusses
4264 one topic and contains references to other nodes which discuss related
4265 topics. Info has commands to follow the references and show you other nodes.
4268 \\[Info-help] Invoke the Info tutorial.
4269 \\[Info-exit] Quit Info: reselect previously selected buffer.
4271 Selecting other nodes:
4272 \\[Info-mouse-follow-nearest-node]
4273 Follow a node reference you click on.
4274 This works with menu items, cross references, and
4275 the \"next\", \"previous\" and \"up\", depending on where you click.
4276 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4277 \\[Info-next] Move to the \"next\" node of this node.
4278 \\[Info-prev] Move to the \"previous\" node of this node.
4279 \\[Info-up] Move \"up\" from this node.
4280 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4281 Picking a menu item causes another node to be selected.
4282 \\[Info-directory] Go to the Info directory node.
4283 \\[Info-top-node] Go to the Top node of this file.
4284 \\[Info-final-node] Go to the final node in this file.
4285 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4286 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4287 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4288 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4289 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4290 \\[Info-history-back] Move back in history to the last node you were at.
4291 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4292 \\[Info-history] Go to menu of visited nodes.
4293 \\[Info-toc] Go to table of contents of the current Info file.
4295 Moving within a node:
4296 \\[Info-scroll-up] Normally, scroll forward a full screen.
4297 Once you scroll far enough in a node that its menu appears on the
4298 screen but after point, the next scroll moves into its first
4299 subnode. When after all menu items (or if there is no menu),
4300 move up to the parent node.
4301 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4302 already visible, try to go to the previous menu entry, or up
4304 \\[beginning-of-buffer] Go to beginning of node.
4307 \\[Info-search] Search through this Info file for specified regexp,
4308 and select the node in which the next occurrence is found.
4309 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4310 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4311 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4312 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4313 \\[Info-virtual-index] Look for a string and display the index node with results.
4314 \\[info-apropos] Look for a string in the indices of all manuals.
4315 \\[Info-goto-node] Move to node specified by name.
4316 You may include a filename as well, as (FILENAME)NODENAME.
4317 1 .. 9 Pick first ... ninth item in node's menu.
4318 Every third `*' is highlighted to help pick the right number.
4319 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4320 \\[clone-buffer] Select a new cloned Info buffer in another window.
4321 \\[universal-argument] \\[info] Move to new Info file with completion.
4322 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4323 :syntax-table Info-mode-syntax-table
4324 :abbrev-table text-mode-abbrev-table
4326 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4327 (setq case-fold-search t)
4328 (setq buffer-read-only t)
4329 (setq Info-tag-table-marker (make-marker))
4330 (if Info-use-header-line ; do not override global header lines
4331 (setq header-line-format
4332 '(:eval (get-text-property (point-min) 'header-line))))
4333 (setq-local tool-bar-map info-tool-bar-map)
4334 ;; This is for the sake of the invisible text we use handling titles.
4335 (setq-local line-move-ignore-invisible t)
4336 (setq-local desktop-save-buffer 'Info-desktop-buffer-misc-data)
4337 (setq-local widen-automatically nil)
4338 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4339 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4340 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4341 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4342 (setq-local isearch-search-fun-function #'Info-isearch-search)
4343 (setq-local isearch-wrap-function #'Info-isearch-wrap)
4344 (setq-local isearch-push-state-function #'Info-isearch-push-state)
4345 (setq-local isearch-filter-predicate #'Info-isearch-filter)
4346 (setq-local revert-buffer-function #'Info-revert-buffer-function)
4347 (setq-local font-lock-defaults '(Info-mode-font-lock-keywords t t))
4348 (Info-set-mode-line)
4349 (setq-local bookmark-make-record-function #'Info-bookmark-make-record))
4351 ;; When an Info buffer is killed, make sure the associated tags buffer
4353 (defun Info-kill-buffer ()
4354 (and (derived-mode-p 'Info-mode)
4355 Info-tag-table-buffer
4356 (kill-buffer Info-tag-table-buffer)))
4358 ;; Placed on `clone-buffer-hook'.
4359 (defun Info-clone-buffer ()
4360 (when (bufferp Info-tag-table-buffer)
4361 (setq Info-tag-table-buffer
4362 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4363 (let ((m Info-tag-table-marker))
4365 (setq Info-tag-table-marker
4366 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4367 (with-current-buffer Info-tag-table-buffer
4368 (copy-marker (marker-position m)))
4371 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4372 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4373 (set-keymap-parent map text-mode-map)
4374 (define-key map "\C-c\C-c" 'Info-cease-edit)
4376 "Local keymap used within `e' command of Info.")
4378 (make-obsolete-variable 'Info-edit-mode-map
4379 "editing Info nodes by hand is not recommended."
4382 ;; Info-edit mode is suitable only for specially formatted data.
4383 (put 'Info-edit-mode 'mode-class 'special)
4385 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4386 "Major mode for editing the contents of an Info node.
4387 Like text mode with the addition of `Info-cease-edit'
4388 which returns to Info mode for browsing."
4389 (setq buffer-read-only nil)
4390 (force-mode-line-update)
4391 (buffer-enable-undo (current-buffer)))
4393 (make-obsolete 'Info-edit-mode
4394 "editing Info nodes by hand is not recommended." "24.4")
4397 "Edit the contents of this Info node."
4400 (message "%s" (substitute-command-keys
4401 "Editing: Type \\<Info-edit-mode-map>\\[Info-cease-edit] to return to info")))
4403 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4404 This feature will be removed in future.")
4406 (make-obsolete 'Info-edit
4407 "editing Info nodes by hand is not recommended." "24.4")
4409 (defun Info-cease-edit ()
4410 "Finish editing Info node; switch back to Info proper."
4412 ;; Do this first, so nothing has changed if user C-g's at query.
4413 (and (buffer-modified-p)
4414 (y-or-n-p "Save the file? ")
4417 (force-mode-line-update)
4418 (and (marker-position Info-tag-table-marker)
4420 (message "Tags may have changed. Use Info-tagify if necessary")))
4422 (make-obsolete 'Info-cease-edit
4423 "editing Info nodes by hand is not recommended." "24.4")
4425 (defvar Info-file-list-for-emacs
4426 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4427 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4428 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4429 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4430 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4431 ("copyright" . "autotype") ("executable" . "autotype")
4432 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4433 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4434 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4435 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4436 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4437 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4438 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4439 ("rfc2045" . "emacs-mime")
4440 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4441 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4442 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4443 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4444 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4445 ("mml" . "emacs-mime")
4447 "List of Info files that describe Emacs commands.
4448 An element can be a file name, or a list of the form (PREFIX . FILE)
4449 where PREFIX is a name prefix and FILE is the file to look in.
4450 If the element is just a file name, the file name also serves as the prefix.")
4452 (defun Info-find-emacs-command-nodes (command)
4453 "Return a list of locations documenting COMMAND.
4454 The `info-file' property of COMMAND says which Info manual to search.
4455 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4456 defines heuristics for which Info manual to try.
4457 The locations are of the format used in the variable `Info-history', i.e.
4458 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4459 in the first element of the returned list (which is treated specially in
4460 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4461 (let ((where '()) line-number
4462 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4463 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4464 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4465 (info-file "emacs")) ;default
4466 ;; Determine which Info file this command is documented in.
4467 (if (get command 'info-file)
4468 (setq info-file (get command 'info-file))
4469 ;; If it doesn't say explicitly, test its name against
4470 ;; various prefixes that we know.
4471 (let ((file-list Info-file-list-for-emacs))
4473 (let* ((elt (car file-list))
4474 (name (if (consp elt)
4477 (file (if (consp elt) (cdr elt) elt))
4478 (case-fold-search nil)
4479 (regexp (concat "\\`" (regexp-quote name)
4481 (if (string-match regexp (symbol-name command))
4482 (setq info-file file file-list nil))
4483 (setq file-list (cdr file-list))))))
4484 (Info-find-node info-file "Top")
4485 ;; Bind Info-history to nil, to prevent the index nodes from
4486 ;; getting into the node history.
4487 (let ((Info-history nil)
4488 (Info-history-list nil)
4489 node (nodes (Info-index-nodes)))
4490 (Info-goto-node (car nodes))
4493 (goto-char (point-min))
4494 (while (re-search-forward cmd-desc nil t)
4496 (cons (list Info-current-file
4497 (match-string-no-properties 2)
4500 (setq line-number (and (match-beginning 3)
4501 (string-to-number (match-string 3)))))
4502 (and (setq nodes (cdr nodes) node (car nodes))))
4503 (Info-goto-node node)))
4504 (if (and line-number where)
4505 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4509 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4511 (defun Info-goto-emacs-command-node (command)
4512 "Go to the Info node in the Emacs manual for command COMMAND.
4513 The command is found by looking up in Emacs manual's indices
4514 or in another manual found via COMMAND's `info-file' property or
4515 the variable `Info-file-list-for-emacs'.
4516 COMMAND must be a symbol or string."
4517 (interactive "CFind documentation for command: ")
4518 ;; If command is given as a string, convert it to a symbol.
4519 (if (stringp command)
4520 (setq command (intern command)))
4521 (or (commandp command)
4522 (signal 'wrong-type-argument (list 'commandp command)))
4523 (let ((where (Info-find-emacs-command-nodes command)))
4525 (let ((num-matches (length where)))
4526 ;; Get Info running, and pop to it in another window.
4527 (save-window-excursion
4529 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4530 ;; Bind Info-history to nil, to prevent the last Index node
4531 ;; visited by Info-find-emacs-command-nodes from being
4532 ;; pushed onto the history.
4533 (let ((Info-history nil) (Info-history-list nil)
4534 (line-number (nth 2 (car where))))
4535 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4536 (if (and (integerp line-number) (> line-number 0))
4537 (forward-line (1- line-number))))
4538 (if (> num-matches 1)
4540 ;; (car where) will be pushed onto Info-history
4541 ;; when/if they go to another node. Put the other
4542 ;; nodes that were found on the history.
4543 (setq Info-history (nconc (cdr where) Info-history))
4544 (message "Found %d other entr%s. Use %s to see %s."
4546 (if (> num-matches 2) "ies" "y")
4547 (substitute-command-keys "\\[Info-history-back]")
4548 (if (> num-matches 2) "them" "it")))))
4549 (error "Couldn't find documentation for %s" command))))
4551 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4553 (defun Info-goto-emacs-key-command-node (key)
4554 "Go to the node in the Emacs manual which describes the command bound to KEY.
4556 Interactively, if the binding is `execute-extended-command', a command is read.
4557 The command is found by looking up in Emacs manual's indices
4558 or in another manual found via COMMAND's `info-file' property or
4559 the variable `Info-file-list-for-emacs'."
4560 (interactive "kFind documentation for key: ")
4561 (let ((command (key-binding key)))
4562 (cond ((null command)
4563 (message "%s is undefined" (key-description key)))
4564 ((and (called-interactively-p 'interactive)
4565 (eq command 'execute-extended-command))
4566 (Info-goto-emacs-command-node
4567 (read-command "Find documentation for command: ")))
4569 (Info-goto-emacs-command-node command)))))
4571 (defvar Info-link-keymap
4572 (let ((keymap (make-sparse-keymap)))
4573 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4574 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4575 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4576 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4577 (define-key keymap [follow-link] 'mouse-face)
4579 "Keymap to put on Info links.
4580 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4581 first line or header line, and for breadcrumb links.")
4583 (defun Info-breadcrumbs ()
4584 (let ((nodes (Info-toc-nodes Info-current-file))
4585 (node Info-current-node)
4587 (depth Info-breadcrumbs-depth)
4590 ;; Get ancestors from the cached parent-children node info
4591 (while (and (not (equal "Top" node)) (> depth 0))
4592 (setq node (nth 1 (assoc node nodes)))
4593 (if node (push node crumbs))
4594 (setq depth (1- depth)))
4597 (when Info-use-header-line
4598 ;; Let it disappear if crumbs is nil.
4599 (nconc crumbs (list Info-current-node)))
4600 (when (or Info-use-header-line crumbs)
4601 ;; Add top node (and continuation if needed).
4603 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4604 crumbs (cons nil crumbs))))
4605 ;; Eliminate duplicate.
4607 (dolist (node crumbs)
4609 (if (not (equal node "Top")) node
4611 (if (stringp Info-current-file)
4612 (file-name-sans-extension
4613 (file-name-nondirectory Info-current-file))
4614 ;; Some legacy code can still use a symbol.
4615 Info-current-file)))))
4618 (if (null line) "" " > ")
4621 ((equal node Info-current-node)
4622 ;; No point linking to ourselves.
4623 (propertize text 'font-lock-face 'info-header-node))
4626 'mouse-face 'highlight
4627 'font-lock-face 'info-header-xref
4628 'help-echo "mouse-2: Go to node"
4629 'keymap Info-link-keymap
4630 'link-args text)))))))
4631 (setq line (concat line "\n")))
4632 ;; (font-lock-append-text-property 0 (length line)
4633 ;; 'font-lock-face 'header-line line)
4636 (defun Info-fontify-node ()
4639 (let* ((inhibit-read-only t)
4640 (case-fold-search t)
4642 (not-fontified-p ; the node hasn't already been fontified
4643 (not (let ((where (next-single-property-change (point-min)
4645 (and where (not (= where (point-max)))))))
4646 (fontify-visited-p ; visited nodes need to be re-fontified
4647 (and Info-fontify-visited-nodes
4648 ;; Don't take time to refontify visited nodes in huge nodes
4649 Info-fontify-maximum-menu-size
4650 (or (eq Info-fontify-maximum-menu-size t)
4651 (< (- (point-max) (point-min))
4652 Info-fontify-maximum-menu-size))))
4655 ;; Fontify header line
4656 (goto-char (point-min))
4657 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4658 (goto-char (match-end 0))
4659 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4660 (goto-char (match-end 0))
4661 (let* ((nbeg (match-beginning 2))
4662 (nend (match-end 2))
4663 (tbeg (match-beginning 1))
4664 (tag (match-string 1)))
4665 (if (string-equal (downcase tag) "node")
4666 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4667 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4668 (put-text-property tbeg nend 'mouse-face 'header-line-highlight)
4669 (put-text-property tbeg nend
4671 (concat "mouse-2: Go to node "
4672 (buffer-substring nbeg nend)))
4673 ;; Set up the text property keymap. Depending on
4674 ;; `Info-use-header-line', it is either used in the
4675 ;; buffer, or copied to the header line. A symbol value
4676 ;; of the `link-args' property is handled specially by
4677 ;; `Info-mouse-follow-link'.
4678 (put-text-property tbeg nend 'keymap Info-link-keymap)
4679 (put-text-property tbeg nend 'link-args
4680 (intern (downcase tag))))))
4682 ;; (when (> Info-breadcrumbs-depth 0)
4683 ;; (insert (Info-breadcrumbs)))
4685 ;; Treat header line.
4686 (when Info-use-header-line
4687 (goto-char (point-min))
4688 (let* ((header-end (line-end-position))
4690 ;; If we find neither Next: nor Prev: link, show the entire
4691 ;; node header. Otherwise, don't show the File: and Node:
4692 ;; parts, to avoid wasting precious space on information that
4693 ;; is available in the mode line.
4694 (if (re-search-forward
4695 "\\(next\\|up\\|prev[ious]*\\): "
4698 (goto-char (match-beginning 1))
4699 (buffer-substring (point) header-end))
4700 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4702 (concat "No next, prev or up links -- "
4703 (buffer-substring (point) header-end))
4704 (buffer-substring (point) header-end)))))
4705 (put-text-property (point-min) (1+ (point-min))
4707 (replace-regexp-in-string
4709 ;; Preserve text properties on duplicated `%'.
4710 (lambda (s) (concat s s)) header))
4711 ;; Hide the part of the first line
4712 ;; that is in the header, if it is just part.
4714 ((> Info-breadcrumbs-depth 0)
4715 (let ((ov (make-overlay (point-min) (1+ header-end))))
4716 (overlay-put ov 'display (Info-breadcrumbs))
4717 (overlay-put ov 'evaporate t)))
4719 ;; Hide the punctuation at the end, too.
4720 (skip-chars-backward " \t,")
4721 (put-text-property (point) header-end 'invisible t)
4722 ;; Hide the suffix of the Info file name.
4724 (if (re-search-forward
4725 (format "File: %s\\([^,\n\t]+\\),"
4726 (if (stringp Info-current-file)
4727 (file-name-sans-extension
4728 (file-name-nondirectory Info-current-file))
4731 (put-text-property (match-beginning 1) (match-end 1)
4735 (goto-char (point-min))
4736 (when (and font-lock-mode not-fontified-p)
4737 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4739 ;; Only consider it as an underlined title if the ASCII
4740 ;; underline has the same size as the text. A typical
4741 ;; counter example is when a continuation "..." is alone
4743 (when (= (string-width (match-string 1))
4744 (string-width (match-string 2)))
4745 (let* ((c (preceding-char))
4747 (cond ((= c ?*) 'info-title-1)
4748 ((= c ?=) 'info-title-2)
4749 ((= c ?-) 'info-title-3)
4750 (t 'info-title-4))))
4751 (put-text-property (match-beginning 1) (match-end 1)
4752 'font-lock-face face))
4753 ;; This is a serious problem for trying to handle multiple
4754 ;; frame types at once. We want this text to be invisible
4755 ;; on frames that can display the font above.
4756 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4757 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4758 '(invisible t front-sticky nil rear-nonsticky t))))))
4760 ;; Fontify cross references
4761 (goto-char (point-min))
4762 (when (or not-fontified-p fontify-visited-p)
4763 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4764 (let ((start (match-beginning 0))
4767 (when not-fontified-p
4768 (when Info-hide-note-references
4769 (when (and (not (eq Info-hide-note-references 'hide))
4770 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4771 ;; *Note is often used where *note should have been
4773 (skip-syntax-backward " ")
4774 (when (memq (char-before) '(?\( ?\[ ?\{))
4775 ;; Check whether the paren is preceded by
4776 ;; an end of sentence
4777 (skip-syntax-backward " ("))
4779 (cond ((save-match-data (looking-back "\\<see"
4782 ((save-match-data (looking-back "\\<in"
4785 ((memq (char-before) '(nil ?\. ?! ??))
4789 (search-forward "\n\n" start t)))
4793 (add-text-properties
4795 (or (save-match-data
4796 ;; Don't hide \n after *Note
4797 (let ((start1 (match-beginning 1)))
4798 (if (string-match "\n" (match-string 1))
4799 (+ start1 (match-beginning 0)))))
4802 `(display ,other-tag front-sticky nil rear-nonsticky t)
4803 '(invisible t front-sticky nil rear-nonsticky t))))
4804 (add-text-properties
4805 (match-beginning 2) (match-end 2)
4807 'help-echo (if (or (match-end 5)
4808 (not (equal (match-string 4) "")))
4809 (concat "mouse-2: go to " (or (match-string 5)
4811 "mouse-2: go to this node")
4812 'mouse-face 'highlight)))
4813 (when (or not-fontified-p fontify-visited-p)
4814 (setq rbeg (match-beginning 2)
4819 ;; Display visited nodes in a different face
4820 (if (and Info-fontify-visited-nodes
4822 (let* ((node (replace-regexp-in-string
4824 (replace-regexp-in-string
4826 (or (match-string-no-properties 5)
4827 (and (not (equal (match-string 4) ""))
4828 (match-string-no-properties 4))
4829 (match-string-no-properties 2)))))
4831 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4832 (file (if external-link-p
4833 (file-name-nondirectory
4834 (match-string-no-properties 1 node))
4836 (hl Info-history-list)
4839 (setq node (if (equal (match-string 2 node) "")
4841 (match-string-no-properties 2 node))))
4843 (if (and (string-equal node (nth 1 (car hl)))
4845 (if (and external-link-p
4846 (stringp (caar hl)))
4847 (file-name-nondirectory
4850 (setq res (car hl) hl nil)
4851 (setq hl (cdr hl))))
4852 res))) 'info-xref-visited 'info-xref))
4853 ;; For multiline ref, unfontify newline and surrounding whitespace
4857 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4858 (remove-text-properties (match-beginning 0)
4860 '(font-lock-face t))))))
4861 (when not-fontified-p
4862 (when (memq Info-hide-note-references '(t hide))
4863 (add-text-properties (match-beginning 3) (match-end 3)
4864 '(invisible t front-sticky nil rear-nonsticky t))
4865 ;; Unhide the file name of the external reference in parens
4866 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4867 (remove-text-properties (match-beginning 6) (match-end 6)
4868 '(invisible t front-sticky nil rear-nonsticky t)))
4869 ;; Unhide newline because hidden newlines cause too long lines
4871 (let ((beg3 (match-beginning 3))
4872 (end3 (match-end 3)))
4873 (if (and (string-match "\n[ \t]*" (match-string 3))
4874 (not (save-match-data
4876 (goto-char (1+ end3))
4877 (looking-at "[.)]*$")))))
4878 (remove-text-properties (+ beg3 (match-beginning 0))
4879 (+ beg3 (match-end 0))
4880 '(invisible t front-sticky nil rear-nonsticky t))))))
4881 (when (and Info-refill-paragraphs Info-hide-note-references)
4882 (push (set-marker (make-marker) start)
4883 paragraph-markers))))))
4885 ;; Refill paragraphs (experimental feature)
4886 (when (and not-fontified-p
4887 Info-refill-paragraphs
4889 (let ((fill-nobreak-invisible t)
4890 (fill-individual-varying-indent nil)
4891 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4892 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4893 (adaptive-fill-mode nil))
4894 (goto-char (point-max))
4895 (dolist (m paragraph-markers)
4899 (let ((beg (point)))
4900 (when (zerop (forward-paragraph))
4901 (fill-individual-paragraphs beg (point) nil nil)
4903 (set-marker m nil))))
4905 ;; Fontify menu items
4906 (goto-char (point-min))
4907 (when (and (or not-fontified-p fontify-visited-p)
4908 (search-forward "\n* Menu:" nil t)
4909 ;; Don't take time to annotate huge menus
4910 Info-fontify-maximum-menu-size
4911 (or (eq Info-fontify-maximum-menu-size t)
4912 (< (- (point-max) (point))
4913 Info-fontify-maximum-menu-size)))
4916 (while (re-search-forward
4917 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4918 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4920 (when (match-beginning 1)
4921 (when not-fontified-p
4923 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4924 (put-text-property (match-beginning 0)
4925 (1+ (match-beginning 0))
4926 'font-lock-face 'info-menu-star)))
4927 (when not-fontified-p
4928 (add-text-properties
4929 (match-beginning 1) (match-end 1)
4931 'help-echo (if (and (match-end 3)
4932 (not (equal (match-string 3) "")))
4933 (concat "mouse-2: go to " (match-string 3))
4934 "mouse-2: go to this node")
4935 'mouse-face 'highlight)))
4936 (when (or not-fontified-p fontify-visited-p)
4938 (match-beginning 1) (match-end 1)
4940 ;; Display visited menu items in a different face
4941 (if (and Info-fontify-visited-nodes
4943 (let* ((node (if (equal (match-string 3) "")
4944 (match-string-no-properties 1)
4945 (match-string-no-properties 3)))
4947 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4948 (file (if external-link-p
4949 (file-name-nondirectory
4950 (match-string-no-properties 1 node))
4952 (hl Info-history-list)
4955 (setq node (if (equal (match-string 2 node) "")
4957 (match-string-no-properties 2 node))))
4959 (if (and (string-equal node (nth 1 (car hl)))
4961 (if (and external-link-p
4962 (stringp (caar hl)))
4963 (file-name-nondirectory
4966 (setq res (car hl) hl nil)
4967 (setq hl (cdr hl))))
4968 res))) 'info-xref-visited 'info-xref)))
4969 (when (and not-fontified-p
4970 (memq Info-hide-note-references '(t hide))
4971 (not (Info-index-node)))
4972 (put-text-property (match-beginning 2) (1- (match-end 6))
4974 ;; Unhide the file name in parens
4975 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4976 (remove-text-properties (match-beginning 4) (match-end 4)
4978 ;; We need a stretchable space like :align-to but with
4980 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4981 (if (>= 22 (- (match-end 1)
4982 (match-beginning 0)))
4983 '(space :align-to 24)
4985 (setq cont (looking-at "."))
4986 (while (and (= (forward-line 1) 0)
4987 (looking-at "\\([ \t]+\\)[^*\n]"))
4988 (put-text-property (match-beginning 1) (1- (match-end 1))
4990 (put-text-property (1- (match-end 1)) (match-end 1)
4993 '(space :align-to 26)
4994 '(space :align-to 24)))
4997 ;; Fontify menu headers
4998 ;; Add the face `info-menu-header' to any header before a menu entry
4999 (goto-char (point-min))
5000 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
5001 (put-text-property (match-beginning 0) (match-end 0)
5002 'font-lock-face 'info-menu-header)
5003 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
5004 (put-text-property (match-beginning 1) (match-end 1)
5005 'font-lock-face 'info-menu-header)))
5007 ;; Hide index line numbers
5008 (goto-char (point-min))
5009 (when (and not-fontified-p (Info-index-node))
5010 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
5011 (put-text-property (match-beginning 0) (match-end 0)
5014 ;; Fontify http and ftp references
5015 (goto-char (point-min))
5016 (when not-fontified-p
5017 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`‘({<>})’']+"
5019 (add-text-properties (match-beginning 0) (match-end 0)
5020 '(font-lock-face info-xref
5021 mouse-face highlight
5022 help-echo "mouse-2: go to this URL"))))
5024 ;; Fontify footnotes
5025 (goto-char (point-min))
5026 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
5027 (let ((limit (point))
5029 ;; How many footnotes do we have in this node?
5030 (while (re-search-forward "^ [ \t]*([0-9]+) " nil t)
5031 (setq fncount (1+ fncount)))
5032 (goto-char (point-min))
5033 (while (re-search-forward "\\((\\([0-9]+\\))\\)" nil t)
5034 (let ((footnote-num (string-to-number (match-string 2))))
5035 ;; Don't fontify parenthesized numbers that cannot
5036 ;; possibly be one of this node's footnotes. This still
5037 ;; doesn't catch unrelated numbers that happen to be
5038 ;; small enough, but in that case they should use
5039 ;; "@footnotestyle separate" in the Texinfo sources.
5040 (when (and (> footnote-num 0)
5041 (<= footnote-num fncount))
5042 (add-text-properties (match-beginning 0) (match-end 0)
5043 `(font-lock-face info-xref
5045 mouse-face highlight
5047 ,(if (< (point) limit)
5048 "mouse-2: go to footnote definition"
5049 "mouse-2: go to footnote reference"))))))))
5051 ;; Hide empty lines at the end of the node.
5052 (goto-char (point-max))
5053 (skip-chars-backward "\n")
5054 (when (< (point) (1- (point-max)))
5055 (put-text-property (point) (1- (point-max)) 'invisible t))
5057 (set-buffer-modified-p nil))))
5059 ;;; Speedbar support:
5060 ;; These functions permit speedbar to display the "tags" in the
5061 ;; current Info node.
5062 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
5064 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
5065 (declare-function speedbar-center-buffer-smartly "speedbar" ())
5066 (declare-function speedbar-change-expand-button-char "speedbar" (char))
5067 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
5068 (declare-function speedbar-delete-subblock "speedbar" (indent))
5069 (declare-function speedbar-make-specialized-keymap "speedbar" ())
5070 (declare-function speedbar-make-tag-line "speedbar"
5071 (exp-button-type exp-button-char exp-button-function
5072 exp-button-data tag-button tag-button-function
5073 tag-button-data tag-button-face depth))
5075 (defvar Info-speedbar-key-map nil
5076 "Keymap used when in the Info display mode.")
5078 (defun Info-install-speedbar-variables ()
5079 "Install those variables used by speedbar to enhance Info."
5080 (if Info-speedbar-key-map
5082 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5084 ;; Basic tree features
5085 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5086 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5087 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5088 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5091 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5092 Info-speedbar-key-map
5093 Info-speedbar-hierarchy-buttons)))
5095 (defvar Info-speedbar-menu-items
5096 '(["Browse Node" speedbar-edit-line t]
5097 ["Expand Node" speedbar-expand-line
5098 (save-excursion (beginning-of-line)
5099 (looking-at "[0-9]+: *.\\+. "))]
5100 ["Contract Node" speedbar-contract-line
5101 (save-excursion (beginning-of-line)
5102 (looking-at "[0-9]+: *.-. "))]
5104 "Additional menu-items to add to speedbar frame.")
5106 ;; Make sure our special speedbar major mode is loaded
5107 (if (featurep 'speedbar)
5108 (Info-install-speedbar-variables)
5109 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5111 ;;; Info hierarchy display method
5113 (defun Info-speedbar-browser ()
5114 "Initialize speedbar to display an Info node browser.
5115 This will add a speedbar major display mode."
5118 ;; Make sure that speedbar is active
5119 (speedbar-frame-mode 1)
5120 ;; Now, throw us into Info mode on speedbar.
5121 (speedbar-change-initial-expansion-list "Info")
5124 ;; speedbar loads dframe at runtime.
5125 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5126 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5128 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5129 "Display an Info directory hierarchy in speedbar.
5130 DIRECTORY is the current directory in the attached frame.
5131 DEPTH is the current indentation depth.
5132 NODE is an optional argument that is used to represent the
5133 specific node to expand."
5135 (save-excursion (goto-char (point-min))
5136 (let ((case-fold-search t))
5137 (looking-at "Info Nodes:"))))
5138 ;; Update our "current node" maybe?
5140 ;; We cannot use the generic list code, that depends on all leaves
5141 ;; being known at creation time.
5143 (speedbar-with-writable (insert "Info Nodes:\n")))
5144 (let ((completions nil))
5145 (speedbar-select-attached-frame)
5146 (save-window-excursion
5148 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5149 (select-frame (speedbar-current-frame))
5151 (speedbar-with-writable
5152 (dolist (completion completions)
5153 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5156 'Info-speedbar-goto-node
5162 (defun Info-speedbar-goto-node (_text node _indent)
5163 "When user clicks on TEXT, go to an info NODE.
5164 The INDENT level is ignored."
5165 (speedbar-select-attached-frame)
5166 (let* ((buff (or (get-buffer "*info*")
5167 (progn (info) (get-buffer "*info*"))))
5168 (bwin (get-buffer-window buff 0)))
5171 (select-window bwin)
5172 (raise-frame (window-frame bwin)))
5173 (if speedbar-power-click
5174 (switch-to-buffer-other-frame buff)
5175 (speedbar-select-attached-frame)
5176 (switch-to-buffer buff)))
5177 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5178 (error "Invalid node %s" node)
5179 (Info-find-node (match-string 1 node) (match-string 2 node))
5180 ;; If we do a find-node, and we were in info mode, restore
5181 ;; the old default method. Once we are in info mode, it makes
5182 ;; sense to return to whatever method the user was using before.
5183 (if (string= speedbar-initial-expansion-list-name "Info")
5184 (speedbar-change-initial-expansion-list
5185 speedbar-previously-used-expansion-list-name)))))
5187 (defun Info-speedbar-expand-node (text token indent)
5188 "Expand the node the user clicked on.
5189 TEXT is the text of the button we clicked on, a + or - item.
5190 TOKEN is data related to this node (NAME . FILE).
5191 INDENT is the current indentation depth."
5192 (cond ((string-match "+" text) ;we have to expand this file
5193 (speedbar-change-expand-button-char ?-)
5194 (if (speedbar-with-writable
5196 (end-of-line) (forward-char 1)
5197 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5198 (speedbar-change-expand-button-char ?-)
5199 (speedbar-change-expand-button-char ??)))
5200 ((string-match "-" text) ;we have to contract this node
5201 (speedbar-change-expand-button-char ?+)
5202 (speedbar-delete-subblock indent))
5203 (t (error "Ooops... not sure what to do")))
5204 (speedbar-center-buffer-smartly))
5206 (defun Info-speedbar-fetch-file-nodes (nodespec)
5207 "Fetch the subnodes from the info NODESPEC.
5208 NODESPEC is a string of the form: (file)node."
5209 ;; Set up a buffer we can use to fake-out Info.
5210 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5211 (if (not (derived-mode-p 'Info-mode))
5213 ;; Get the node into this buffer
5214 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5215 (error "Invalid node specification %s" nodespec)
5216 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5217 ;; Scan the created buffer
5218 (goto-char (point-min))
5219 (let ((completions nil)
5220 (case-fold-search t)
5221 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5222 (match-string 1 nodespec))))
5223 ;; Always skip the first one...
5224 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5225 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5226 (let ((name (match-string 1)))
5228 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5230 (if (looking-at " *\\(([^)]+)\\)\\.")
5231 (concat (match-string 1) "Top")
5232 (concat "(" thisfile ")"
5233 (if (looking-at " \\([^.]+\\).")
5237 (nreverse completions))))
5239 ;;; Info mode node listing
5240 ;; This is called by `speedbar-add-localized-speedbar-support'
5241 (defun Info-speedbar-buttons (_buffer)
5242 "Create a speedbar display to help navigation in an Info file.
5243 BUFFER is the buffer speedbar is requesting buttons for."
5244 (if (save-excursion (goto-char (point-min))
5245 (let ((case-fold-search t))
5246 (not (looking-at "Info Nodes:"))))
5248 (Info-speedbar-hierarchy-buttons nil 0))
5250 ;;;; Desktop support
5252 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5253 "Auxiliary information to be saved in desktop file."
5254 (list Info-current-file
5256 ;; Additional data as an association list.
5259 (cons 'history Info-history))
5260 (and (Info-virtual-fun
5261 'slow Info-current-file Info-current-node)
5264 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5266 desktop-buffer-misc)
5267 "Restore an Info buffer specified in a desktop file."
5268 (let* ((file (nth 0 desktop-buffer-misc))
5269 (node (nth 1 desktop-buffer-misc))
5270 (data (nth 2 desktop-buffer-misc))
5271 (hist (assq 'history data))
5272 (slow (assq 'slow data)))
5273 ;; Don't restore nodes slow to regenerate.
5275 (when (and file node)
5276 (when desktop-buffer-name
5277 (set-buffer (get-buffer-create desktop-buffer-name))
5279 (Info-find-node file node)
5281 (setq Info-history (cdr hist)))
5282 (current-buffer)))))
5284 (add-to-list 'desktop-buffer-mode-handlers
5285 '(Info-mode . Info-restore-desktop-buffer))
5287 ;;;; Bookmark support
5288 (declare-function bookmark-make-record-default
5289 "bookmark" (&optional no-file no-context posn))
5290 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5291 (declare-function bookmark-default-handler "bookmark" (bmk))
5292 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5294 (defun Info-bookmark-make-record ()
5295 "This implements the `bookmark-make-record-function' type (which see)
5297 (let* ((file (and (stringp Info-current-file)
5298 (file-name-sans-extension
5299 (file-name-nondirectory Info-current-file))))
5300 (bookmark-name (if file
5301 (concat "(" file ") " Info-current-node)
5303 (defaults (delq nil (list bookmark-name file Info-current-node))))
5305 ,@(bookmark-make-record-default 'no-file)
5306 (filename . ,Info-current-file)
5307 (info-node . ,Info-current-node)
5308 (handler . Info-bookmark-jump)
5309 (defaults . ,defaults))))
5312 (defun Info-bookmark-jump (bmk)
5313 "This implements the `handler' function interface for the record
5314 type returned by `Info-bookmark-make-record', which see."
5315 (let* ((file (bookmark-prop-get bmk 'filename))
5316 (info-node (bookmark-prop-get bmk 'info-node))
5317 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5318 (Info-find-node file info-node) (current-buffer))))
5319 ;; Use bookmark-default-handler to move to the appropriate location
5321 (bookmark-default-handler
5322 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5326 (defun info-display-manual (manual)
5327 "Display an Info buffer displaying MANUAL.
5328 If there is an existing Info buffer for MANUAL, display it.
5329 Otherwise, visit the manual in a new Info buffer. In interactive
5330 use, a prefix argument directs this command to limit the
5331 completion alternatives to currently visited manuals."
5336 (completing-read "Manual name: "
5337 (info--manual-names current-prefix-arg)
5339 (let ((blist (buffer-list))
5340 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5341 (case-fold-search t)
5343 (dolist (buffer blist)
5344 (with-current-buffer buffer
5345 (when (and (eq major-mode 'Info-mode)
5346 (stringp Info-current-file)
5347 (string-match manual-re Info-current-file))
5351 (switch-to-buffer found)
5353 (info (Info-find-file manual)
5354 (generate-new-buffer-name "*info*")))))
5356 (defun info--manual-names (visited-only)
5358 (dolist (buffer (buffer-list))
5359 (with-current-buffer buffer
5360 (and (eq major-mode 'Info-mode)
5361 (stringp Info-current-file)
5362 (not (string= (substring (buffer-name) 0 1) " "))
5363 (push (file-name-sans-extension
5364 (file-name-nondirectory Info-current-file))
5366 (delete-dups (append (nreverse names)
5367 (when (not visited-only)
5370 (apply-partially #'Info-read-node-name-2
5372 (mapcar #'car Info-suffix-list))))))))
5376 ;;; info.el ends here