1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2014 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Note that nowadays we expect Info files to be made using makeinfo.
26 ;; In particular we make these assumptions:
27 ;; - a menu item MAY contain colons but not colon-space ": "
28 ;; - a menu item ending with ": " (but not ":: ") is an index entry
29 ;; - a node name MAY NOT contain a colon
30 ;; This distinction is to support indexing of computer programming
31 ;; language terms that may contain ":" but not ": ".
41 (defvar Info-history nil
42 "Stack of Info nodes user has visited.
43 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
45 (defvar Info-history-forward nil
46 "Stack of Info nodes user has visited with `Info-history-back' command.
47 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
49 (defvar Info-history-list nil
50 "List of all Info nodes user has visited.
51 Each element of the list is a list (FILENAME NODENAME).")
53 (defcustom Info-history-skip-intermediate-nodes t
54 "Non-nil means don't record intermediate Info nodes to the history.
55 Intermediate Info nodes are nodes visited by Info internally in the process of
56 searching the node to display. Intermediate nodes are not presented
62 (defvar Info-enable-active-nodes nil
63 "Non-nil allows Info to execute Lisp code associated with nodes.
64 The Lisp code is executed when the node is selected.")
65 (put 'Info-enable-active-nodes
'risky-local-variable t
)
68 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
69 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
70 (t :weight bold
:slant italic
))
71 "Face for Info node names."
75 '((((type tty pc
) (class color
) (background light
))
76 :foreground
"green" :weight bold
)
77 (((type tty pc
) (class color
) (background dark
))
78 :foreground
"yellow" :weight bold
)
79 (t :height
1.2 :inherit info-title-2
))
80 "Face for info titles at level 1."
82 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
85 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
86 (t :height
1.2 :inherit info-title-3
))
87 "Face for info titles at level 2."
89 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
92 '((((type tty pc
) (class color
)) :weight bold
)
93 (t :height
1.2 :inherit info-title-4
))
94 "Face for info titles at level 3."
96 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
99 '((((type tty pc
) (class color
)) :weight bold
)
100 (t :weight bold
:inherit variable-pitch
))
101 "Face for info titles at level 4."
103 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
105 (defface info-menu-header
110 :inherit variable-pitch
112 "Face for headers in Info menus."
115 (defface info-menu-star
116 '((((class color
)) :foreground
"red1")
118 "Face for every third `*' in an Info menu."
120 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
124 "Face for unvisited Info cross-references."
127 (defface info-xref-visited
128 '((t :inherit
(link-visited info-xref
)))
129 "Face for visited Info cross-references."
133 (defcustom Info-fontify-visited-nodes t
134 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
139 (defcustom Info-fontify-maximum-menu-size
100000
140 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
141 Set to nil to disable node fontification."
145 (defcustom Info-use-header-line t
146 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
147 A header-line does not scroll with the rest of the buffer."
151 (defface info-header-xref
152 '((t :inherit info-xref
))
153 "Face for Info cross-references in a node header."
156 (defface info-header-node
157 '((t :inherit info-node
))
158 "Face for Info nodes in a node header."
161 (defface info-index-match
162 '((t :inherit match
))
163 "Face used to highlight matches in an index entry."
167 ;; This is a defcustom largely so that we can get the benefit
168 ;; of custom-initialize-delay. Perhaps it would work to make it a
169 ;; defvar and explicitly give it a standard-value property, and
170 ;; call custom-initialize-delay on it.
171 ;; The progn forces the autoloader to include the whole thing, not
172 ;; just an abbreviated version.
175 (defcustom Info-default-directory-list
177 (file-name-as-directory
178 ;; Self-contained NS build with info/ in the app-bundle.
179 (or (and (featurep 'ns
)
180 (let ((dir (expand-file-name "../info" data-directory
)))
181 (if (file-directory-p dir
) dir
)))
182 configure-info-directory
)))
184 ;; Directory trees in which to look for info subdirectories
185 (prune-directory-list '("/usr/local/" "/usr/" "/opt/" "/")))
187 ;; Subdirectories in each directory tree that may contain info
188 ;; directories. Most of these are rather outdated.
189 ;; It ought to be fine to stop checking the "emacs" ones now,
190 ;; since this is Emacs and we have not installed info files
191 ;; into such directories for a looong time...
192 '("share/" "" "gnu/" "gnu/lib/" "gnu/lib/emacs/"
193 "emacs/" "lib/" "lib/emacs/"))
196 (mapcar (lambda (pfx)
198 (mapcar (lambda (sfx)
199 (concat pfx sfx
"info/"))
201 (prune-directory-list dirs
)))
203 ;; If $(prefix)/share/info is not one of the standard info
204 ;; directories, they are probably installing an experimental
205 ;; version of Emacs, so make sure that experimental version's Info
206 ;; files override the ones in standard directories.
208 (if (member config-dir standard-info-dirs
)
209 ;; FIXME? What is the point of adding it again at the end
210 ;; when it is already present earlier in the list?
211 (nconc standard-info-dirs
(list config-dir
))
212 (cons config-dir standard-info-dirs
))))
213 (if (not (eq system-type
'windows-nt
))
215 ;; Include the info directory near where Emacs executable was installed.
216 (let* ((instdir (file-name-directory invocation-directory
))
217 (dir1 (expand-file-name "../info/" instdir
))
218 (dir2 (expand-file-name "../../../info/" instdir
)))
219 (cond ((file-exists-p dir1
) (append dirs
(list dir1
)))
220 ((file-exists-p dir2
) (append dirs
(list dir2
)))
223 "Default list of directories to search for Info documentation files.
224 They are searched in the order they are given in the list.
225 Therefore, the directory of Info files that come with Emacs
226 normally should come last (so that local files override standard ones),
227 unless Emacs is installed into a non-standard directory. In the latter
228 case, the directory of Info files that come with Emacs should be
231 Once Info is started, the list of directories to search
232 comes from the variable `Info-directory-list'.
233 This variable `Info-default-directory-list' is used as the default
234 for initializing `Info-directory-list' when Info is started, unless
235 the environment variable INFOPATH is set.
237 Although this is a customizable variable, that is mainly for technical
238 reasons. Normally, you should either set INFOPATH or customize
239 `Info-additional-directory-list', rather than changing this variable."
240 :initialize
'custom-initialize-delay
241 :type
'(repeat directory
)
244 (defvar Info-directory-list nil
245 "List of directories to search for Info documentation files.
246 If nil, meaning not yet initialized, Info uses the environment
247 variable INFOPATH to initialize it, or `Info-default-directory-list'
248 if there is no INFOPATH variable in the environment, or the
249 concatenation of the two if INFOPATH ends with a `path-separator'.
251 When `Info-directory-list' is initialized from the value of
252 `Info-default-directory-list', and Emacs is installed in one of the
253 standard directories, the directory of Info files that come with Emacs
254 is put last (so that local Info files override standard ones).
256 When `Info-directory-list' is initialized from the value of
257 `Info-default-directory-list', and Emacs is not installed in one
258 of the standard directories, the first element of the resulting
259 list is the directory where Emacs installs the Info files that
260 come with it. This is so that Emacs's own manual, which suits the
261 version of Emacs you are using, will always be found first. This
262 is useful when you install an experimental version of Emacs without
263 removing the standard installation.
265 If you want to override the order of directories in
266 `Info-default-directory-list', set INFOPATH in the environment.
268 If you run the Emacs executable from the `src' directory in the Emacs
269 source tree, and INFOPATH is not defined, the `info' directory in the
270 source tree is used as the first element of `Info-directory-list', in
271 place of the installation Info directory. This is useful when you run
272 a version of Emacs without installing it.")
274 (defcustom Info-additional-directory-list nil
275 "List of additional directories to search for Info documentation files.
276 These directories are searched after those in `Info-directory-list'."
277 :type
'(repeat directory
)
280 (defcustom Info-scroll-prefer-subnodes nil
281 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
283 If this is non-nil, and you scroll far enough in a node that its menu
284 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
285 moves to a subnode indicated by the following menu item. This means
286 that you visit a subnode before getting to the end of the menu.
288 Setting this option to nil results in behavior similar to the stand-alone
289 Info reader program, which visits the first subnode from the menu only
290 when you hit the end of the current node."
295 (defcustom Info-hide-note-references t
296 "If non-nil, hide the tag and section reference in *note and * menu items.
297 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
298 If value is non-nil but not t or `hide', the reference section is still shown.
299 `nil' completely disables this feature. If this is non-nil, you might
300 want to set `Info-refill-paragraphs'."
302 :type
'(choice (const :tag
"No hiding" nil
)
303 (const :tag
"Replace tag and hide reference" t
)
304 (const :tag
"Hide tag and reference" hide
)
305 (other :tag
"Only replace tag" tag
))
306 :set
(lambda (sym val
)
308 (dolist (buffer (buffer-list))
309 (with-current-buffer buffer
310 (when (eq major-mode
'Info-mode
)
311 (revert-buffer t t
)))))
314 (defcustom Info-refill-paragraphs nil
315 "If non-nil, attempt to refill paragraphs with hidden references.
316 This refilling may accidentally remove explicit line breaks in the Info
317 file, so be prepared for a few surprises if you enable this feature.
318 This only has an effect if `Info-hide-note-references' is non-nil."
323 (defcustom Info-breadcrumbs-depth
4
324 "Depth of breadcrumbs to display.
325 0 means do not display breadcrumbs."
330 (defcustom Info-search-whitespace-regexp
"\\s-+"
331 "If non-nil, regular expression to match a sequence of whitespace chars.
332 This applies to Info search for regular expressions.
333 You might want to use something like \"[ \\t\\r\\n]+\" instead.
334 In the Customization buffer, that is `[' followed by a space,
335 a tab, a carriage return (control-M), a newline, and `]+'."
339 (defcustom Info-isearch-search t
340 "If non-nil, isearch in Info searches through multiple nodes.
341 Before leaving the initial Info node, where isearch was started,
342 it fails once with the error message [end of node], and with
343 subsequent C-s/C-r continues through other nodes without failing
344 with this error message in other nodes. When isearch fails for
345 the rest of the manual, it displays the error message [end of manual],
346 wraps around the whole manual and restarts the search from the top/final
347 node depending on search direction.
349 Setting this option to nil restores the default isearch behavior
350 with wrapping around the current Info node."
355 (defvar Info-isearch-initial-node nil
)
356 (defvar Info-isearch-initial-history nil
)
357 (defvar Info-isearch-initial-history-list nil
)
359 (defcustom Info-mode-hook
360 ;; Try to obey obsolete Info-fontify settings.
361 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
362 '(turn-on-font-lock))
363 "Hooks run when `Info-mode' is called."
367 (defcustom Info-selection-hook nil
368 "Hooks run when `Info-select-node' is called."
372 (defvar Info-edit-mode-hook nil
373 "Hooks run when `Info-edit-mode' is called.")
375 (make-obsolete-variable 'Info-edit-mode-hook
376 "editing Info nodes by hand is not recommended." "24.4")
378 (defvar Info-current-file nil
379 "Info file that Info is now looking at, or nil.
380 This is the name that was specified in Info, not the actual file name.
381 It doesn't contain directory names or file name extensions added by Info.")
383 (defvar Info-current-subfile nil
384 "Info subfile that is actually in the *info* buffer now.
385 It is nil if current Info file is not split into subfiles.")
387 (defvar Info-current-node nil
388 "Name of node that Info is now looking at, or nil.")
390 (defvar Info-tag-table-marker nil
391 "Marker pointing at beginning of current Info file's tag table.
392 Marker points nowhere if file has no tag table.")
394 (defvar Info-tag-table-buffer nil
395 "Buffer used for indirect tag tables.")
397 (defvar Info-current-file-completions nil
398 "Cached completion list for current Info file.")
400 (defvar Info-file-completions nil
401 "Cached completion alist of visited Info files.
402 Each element of the alist is (FILE . COMPLETIONS)")
404 (defvar Info-file-supports-index-cookies nil
405 "Non-nil if current Info file supports index cookies.")
407 (defvar Info-file-supports-index-cookies-list nil
408 "List of Info files with information about index cookies support.
409 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
410 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
412 (defvar Info-index-alternatives nil
413 "List of possible matches for last `Info-index' command.")
415 (defvar Info-point-loc nil
416 "Point location within a selected node.
417 If string, the point is moved to the proper occurrence of the
418 name of the followed cross reference within a selected node.
419 If number, the point is moved to the corresponding line.")
421 (defvar Info-standalone nil
422 "Non-nil if Emacs was started solely as an Info browser.")
424 (defvar Info-file-attributes nil
425 "Alist of file attributes of visited Info files.
426 Each element is a list (FILE-NAME FILE-ATTRIBUTES...).")
428 (defvar Info-toc-nodes nil
429 "Alist of cached parent-children node information in visited Info files.
430 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
431 where PARENT is the parent node extracted from the Up pointer,
432 SECTION is the section name in the Top node where this node is placed,
433 CHILDREN is a list of child nodes extracted from the node menu.")
435 (defvar Info-index-nodes nil
436 "Alist of cached index node names of visited Info files.
437 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
439 (defvar Info-virtual-files nil
440 "List of definitions of virtual Info files.
441 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
442 where FILENAME is a regexp that matches a class of virtual Info file names.
443 It should be carefully chosen to not cause file name clashes with
444 existing file names. OPERATION is one of the following operation
445 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
446 function to call instead of calling the default corresponding function
449 (defvar Info-virtual-nodes nil
450 "List of definitions of virtual Info nodes.
451 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
452 where NODENAME is a regexp that matches a class of virtual Info node names.
453 It should be carefully chosen to not cause node name clashes with
454 existing node names. OPERATION is one of the following operation
455 symbols `find-node' that define what HANDLER function to call instead
456 of calling the default corresponding function to override it.")
458 (defvar Info-current-node-virtual nil
459 "Non-nil if the current Info node is virtual.")
461 (defun Info-virtual-file-p (filename)
462 "Check if Info file FILENAME is virtual."
463 (Info-virtual-fun 'find-file filename nil
))
465 (defun Info-virtual-fun (op filename nodename
)
466 "Find a function that handles operations on virtual manuals.
467 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
468 FILENAME is a virtual Info file name, NODENAME is a virtual Info
469 node name. Return a function found either in `Info-virtual-files'
470 or `Info-virtual-nodes'."
471 (or (and (stringp filename
) ; some legacy code can still use a symbol
472 (cdr-safe (assoc op
(assoc-default filename
475 (and (stringp nodename
) ; some legacy code can still use a symbol
476 (cdr-safe (assoc op
(assoc-default nodename
480 (defun Info-virtual-call (virtual-fun &rest args
)
481 "Call a function that handles operations on virtual manuals."
482 (when (functionp virtual-fun
)
483 (or (apply virtual-fun args
) t
)))
486 (defvar Info-suffix-list
487 ;; The MS-DOS list should work both when long file names are
488 ;; supported (Windows 9X), and when only 8+3 file names are available.
489 (if (eq system-type
'ms-dos
)
490 '( (".gz" .
"gunzip")
492 (".bz2" .
("bzip2" "-dc"))
495 (".info.Z" .
"gunzip")
496 (".info.gz" .
"gunzip")
497 ("-info.Z" .
"gunzip")
498 ("-info.gz" .
"gunzip")
499 ("/index.gz" .
"gunzip")
500 ("/index.z" .
"gunzip")
506 '( (".info.Z" .
"uncompress")
507 (".info.Y" .
"unyabba")
508 (".info.gz" .
"gunzip")
509 (".info.z" .
"gunzip")
510 (".info.bz2" .
("bzip2" "-dc"))
511 (".info.xz" .
"unxz")
513 ("-info.Z" .
"uncompress")
514 ("-info.Y" .
"unyabba")
515 ("-info.gz" .
"gunzip")
516 ("-info.bz2" .
("bzip2" "-dc"))
517 ("-info.z" .
"gunzip")
518 ("-info.xz" .
"unxz")
520 ("/index.Z" .
"uncompress")
521 ("/index.Y" .
"unyabba")
522 ("/index.gz" .
"gunzip")
523 ("/index.z" .
"gunzip")
524 ("/index.bz2" .
("bzip2" "-dc"))
525 ("/index.xz" .
"unxz")
527 (".Z" .
"uncompress")
531 (".bz2" .
("bzip2" "-dc"))
534 "List of file name suffixes and associated decoding commands.
535 Each entry should be (SUFFIX . STRING); the file is given to
536 the command as standard input.
538 STRING may be a list of strings. In that case, the first element is
539 the command name, and the rest are arguments to that command.
541 If STRING is nil, no decoding is done.
542 Because the SUFFIXes are tried in order, the empty string should
543 be last in the list.")
545 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
546 ;; First, on MS-DOS with no long file names support, delete some of
547 ;; the extension in FILENAME to make room.
548 (defun info-insert-file-contents-1 (filename suffix lfn
)
549 (if lfn
; long file names are supported
550 (concat filename suffix
)
551 (let* ((sans-exts (file-name-sans-extension filename
))
552 ;; How long is the extension in FILENAME (not counting the dot).
553 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
555 ;; SUFFIX starts with a dot. If FILENAME already has one,
556 ;; get rid of the one in SUFFIX (unless suffix is empty).
557 (or (and (<= ext-len
0)
558 (not (eq (aref filename
(1- (length filename
))) ?.
)))
559 (= (length suffix
) 0)
560 (setq suffix
(substring suffix
1)))
561 ;; How many chars of that extension should we keep?
562 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
563 ;; Get rid of the rest of the extension, and add SUFFIX.
564 (concat (substring filename
0 (- (length filename
)
565 (- ext-len ext-left
)))
568 (defun info-file-exists-p (filename)
569 (and (file-exists-p filename
)
570 (not (file-directory-p filename
))))
572 (defun info-insert-file-contents (filename &optional visit
)
573 "Insert the contents of an Info file in the current buffer.
574 Do the right thing if the file has been compressed or zipped."
575 (let* ((tail Info-suffix-list
)
576 (jka-compr-verbose nil
)
577 (lfn (if (fboundp 'msdos-long-file-names
)
578 (msdos-long-file-names)
580 (check-short (and (fboundp 'msdos-long-file-names
)
582 fullname decoder done
)
583 (if (info-file-exists-p filename
)
584 ;; FILENAME exists--see if that name contains a suffix.
585 ;; If so, set DECODE accordingly.
589 (concat (regexp-quote (car (car tail
))) "$")
591 (setq tail
(cdr tail
)))
592 (setq fullname filename
593 decoder
(cdr (car tail
))))
594 ;; Try adding suffixes to FILENAME and see if we can find something.
595 (while (and tail
(not done
))
596 (setq fullname
(info-insert-file-contents-1 filename
597 (car (car tail
)) lfn
))
598 (if (info-file-exists-p fullname
)
600 ;; If we found a file with a suffix, set DECODER
601 ;; according to the suffix.
602 decoder
(cdr (car tail
)))
603 ;; When the MS-DOS port runs on Windows, we need to check
604 ;; the short variant of a long file name as well.
606 (setq fullname
(info-insert-file-contents-1 filename
607 (car (car tail
)) nil
))
608 (if (info-file-exists-p fullname
)
610 decoder
(cdr (car tail
))))))
611 (setq tail
(cdr tail
)))
613 (error "Can't find %s or any compressed version of it" filename
)))
614 ;; check for conflict with jka-compr
615 (if (and (jka-compr-installed-p)
616 (jka-compr-get-compression-info fullname
))
620 (insert-file-contents-literally fullname visit
)
621 (let ((inhibit-read-only t
)
622 (coding-system-for-write 'no-conversion
)
623 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
624 (default-directory (or (file-name-directory fullname
)
627 (setq decoder
(list decoder
)))
628 (apply 'call-process-region
(point-min) (point-max)
629 (car decoder
) t t nil
(cdr decoder
))))
630 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
631 (insert-file-contents fullname visit
)))
633 ;; Clear the caches of modified Info files.
634 (let* ((attribs-old (cdr (assoc fullname Info-file-attributes
)))
635 (modtime-old (and attribs-old
(nth 5 attribs-old
)))
636 (attribs-new (and (stringp fullname
) (file-attributes fullname
)))
637 (modtime-new (and attribs-new
(nth 5 attribs-new
))))
638 (when (and modtime-old modtime-new
639 (> (float-time modtime-new
) (float-time modtime-old
)))
640 (setq Info-index-nodes
(remove (assoc (or Info-current-file filename
)
643 (setq Info-toc-nodes
(remove (assoc (or Info-current-file filename
)
646 ;; Add new modtime to `Info-file-attributes'.
647 (setq Info-file-attributes
648 (cons (cons fullname attribs-new
)
649 (remove (assoc fullname Info-file-attributes
)
650 Info-file-attributes
))))))
652 (defun Info-file-supports-index-cookies (&optional file
)
653 "Return non-nil value if FILE supports Info index cookies.
654 Info index cookies were first introduced in 4.7, and all later
655 makeinfo versions output them in index nodes, so we can rely
656 solely on the makeinfo version. This function caches the information
657 in `Info-file-supports-index-cookies-list'."
658 (or file
(setq file Info-current-file
))
659 (or (assoc file Info-file-supports-index-cookies-list
)
660 ;; Skip virtual Info files
661 (and (or (not (stringp file
))
662 (Info-virtual-file-p file
))
663 (setq Info-file-supports-index-cookies-list
664 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
667 (goto-char (point-min))
669 (if (and (re-search-forward
670 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
671 (line-beginning-position 4) t
)
672 (not (version< (match-string 1) "4.7")))
675 (setq Info-file-supports-index-cookies-list
676 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
677 (cdr (assoc file Info-file-supports-index-cookies-list
)))
680 (defun Info-default-dirs ()
681 (let ((source (expand-file-name "info/" source-directory
))
682 (sibling (if installation-directory
683 (expand-file-name "info/" installation-directory
)
684 (if invocation-directory
685 (let ((infodir (expand-file-name
687 invocation-directory
)))
688 (if (file-exists-p infodir
)
690 (setq infodir
(expand-file-name
691 "../../../share/info/"
692 invocation-directory
))
693 (and (file-exists-p infodir
)
697 (if (and sibling
(file-exists-p sibling
))
698 ;; Uninstalled, Emacs builddir != srcdir.
700 ;; Uninstalled, builddir == srcdir
702 (if (or (member alternative Info-default-directory-list
)
703 ;; On DOS/NT, we use movable executables always,
704 ;; and we must always find the Info dir at run time.
705 (if (memq system-type
'(ms-dos windows-nt
))
707 ;; Use invocation-directory for Info
708 ;; only if we used it for exec-directory also.
709 (not (string= exec-directory
710 (expand-file-name "lib-src/"
711 installation-directory
))))
712 (not (file-exists-p alternative
)))
713 Info-default-directory-list
714 ;; `alternative' contains the Info files that came with this
715 ;; version, so we should look there first. `Info-insert-dir'
716 ;; currently expects to find `alternative' first on the list.
718 ;; Don't drop the last part, it might contain non-Emacs stuff.
719 ;; (reverse (cdr (reverse
720 Info-default-directory-list
)))) ;; )))
722 (defun info-initialize ()
723 "Initialize `Info-directory-list', if that hasn't been done yet."
724 (unless Info-directory-list
725 (let ((path (getenv "INFOPATH"))
726 (sep (regexp-quote path-separator
)))
727 (setq Info-directory-list
728 (prune-directory-list
730 (if (string-match-p (concat sep
"\\'") path
)
731 (append (split-string (substring path
0 -
1) sep
)
733 (split-string path sep
))
734 (Info-default-dirs))))
735 ;; If we are running uninstalled, our own Info files should
736 ;; always come first. If INFOPATH was set, they might not.
738 installation-directory
739 (let ((dir (expand-file-name "info/" installation-directory
)))
740 (when (file-directory-p dir
)
741 (setq Info-directory-list
(delete dir Info-directory-list
))
742 (push dir Info-directory-list
))))
743 ;; For a self-contained (ie relocatable) NS build, AFAICS we
744 ;; always want the included info directory to be at the head of
745 ;; the search path, unless it's already in INFOPATH somewhere.
746 ;; It's at the head of Info-default-directory-list,
747 ;; but there's no way to get it at the head of Info-directory-list
748 ;; except by doing it here.
751 (let ((dir (expand-file-name "../info" data-directory
)))
752 (and (file-directory-p dir
)
753 (not (member dir
(split-string path
":" t
)))
754 (push dir Info-directory-list
)))))))
757 (defun info-other-window (&optional file-or-node buffer
)
758 "Like `info' but show the Info buffer in another window."
760 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
761 (read-file-name "Info file name: " nil nil t
))
762 (if (numberp current-prefix-arg
)
763 (format "*info*<%s>" current-prefix-arg
))))
764 (info-setup file-or-node
765 (switch-to-buffer-other-window (or buffer
"*info*"))))
767 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
769 (defun info (&optional file-or-node buffer
)
770 "Enter Info, the documentation browser.
771 Optional argument FILE-OR-NODE specifies the file to examine;
772 the default is the top-level directory of Info.
773 Called from a program, FILE-OR-NODE may specify an Info node of the form
774 \"(FILENAME)NODENAME\".
775 Optional argument BUFFER specifies the Info buffer name;
776 the default buffer name is *info*. If BUFFER exists,
777 just switch to BUFFER. Otherwise, create a new buffer
778 with the top-level Info directory.
780 In interactive use, a non-numeric prefix argument directs
781 this command to read a file name from the minibuffer.
783 A numeric prefix argument N selects an Info buffer named
786 The search path for Info files is in the variable `Info-directory-list'.
787 The top-level Info directory is made by combining all the files named `dir'
788 in all the directories in that path.
790 See a list of available Info commands in `Info-mode'."
792 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
793 (read-file-name "Info file name: " nil nil t
))
794 (if (numberp current-prefix-arg
)
795 (format "*info*<%s>" current-prefix-arg
))))
796 (info-setup file-or-node
797 (pop-to-buffer-same-window (or buffer
"*info*"))))
799 (defun info-setup (file-or-node buffer
)
800 "Display Info node FILE-OR-NODE in BUFFER."
801 (if (and buffer
(not (derived-mode-p 'Info-mode
)))
804 ;; If argument already contains parentheses, don't add another set
805 ;; since the argument will then be parsed improperly. This also
806 ;; has the added benefit of allowing node names to be included
807 ;; following the parenthesized filename.
809 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
811 (concat "(" file-or-node
")")))
812 (if (and (zerop (buffer-size))
814 ;; If we just created the Info buffer, go to the directory.
818 (defun info-emacs-manual ()
819 "Display the Emacs manual in Info mode."
824 (defun info-emacs-bug ()
825 "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
827 (info "(emacs)Bugs"))
830 (defun info-standalone ()
831 "Run Emacs as a standalone Info reader.
832 Usage: emacs -f info-standalone [filename]
833 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
834 (setq Info-standalone t
)
835 (if (and command-line-args-left
836 (not (string-match "^-" (car command-line-args-left
))))
839 (info (car command-line-args-left
))
840 (setq command-line-args-left
(cdr command-line-args-left
)))
841 (error (send-string-to-terminal
842 (format "%s\n" (if (eq (car-safe err
) 'error
)
844 (save-buffers-kill-emacs)))
847 ;; See if the accessible portion of the buffer begins with a node
848 ;; delimiter, and the node header line which follows matches REGEXP.
849 ;; Typically, this test will be followed by a loop that examines the
850 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
851 ;; to have the overhead of this special test inside the loop.
853 ;; This function changes match-data, but supposedly the caller might
854 ;; want to use the results of re-search-backward.
856 ;; The return value is the value of point at the beginning of matching
857 ;; REGEXP, if the function succeeds, nil otherwise.
858 (defun Info-node-at-bob-matching (regexp)
859 (and (bobp) ; are we at beginning of buffer?
860 (looking-at "\^_") ; does it begin with node delimiter?
864 (forward-line 1) ; does the line after delimiter match REGEXP?
865 (re-search-backward regexp beg t
))))
867 (defun Info-find-file (filename &optional noerror
)
868 "Return expanded FILENAME, or t if FILENAME is \"dir\".
869 Optional second argument NOERROR, if t, means if file is not found
870 just return nil (no error)."
871 ;; Convert filename to lower case if not found as specified.
875 (Info-virtual-fun 'find-file filename nil
)
878 (let (temp temp-downcase found
)
879 (setq filename
(substitute-in-file-name filename
))
880 (let ((dirs (if (string-match "^\\./" filename
)
881 ;; If specified name starts with `./'
882 ;; then just try current directory.
884 (if (file-name-absolute-p filename
)
885 ;; No point in searching for an
886 ;; absolute file name
888 (if Info-additional-directory-list
889 (append Info-directory-list
890 Info-additional-directory-list
)
891 Info-directory-list
)))))
892 ;; Fall back on the installation directory if we can't find
893 ;; the info node anywhere else.
894 (when installation-directory
895 (setq dirs
(append dirs
(list (expand-file-name
896 "info" installation-directory
)))))
897 ;; Search the directory list for file FILENAME.
898 (while (and dirs
(not found
))
899 (setq temp
(expand-file-name filename
(car dirs
)))
901 (expand-file-name (downcase filename
) (car dirs
)))
902 ;; Try several variants of specified name.
903 (let ((suffix-list Info-suffix-list
)
904 (lfn (if (fboundp 'msdos-long-file-names
)
905 (msdos-long-file-names)
907 (while (and suffix-list
(not found
))
908 (cond ((info-file-exists-p
909 (info-insert-file-contents-1
910 temp
(car (car suffix-list
)) lfn
))
913 (info-insert-file-contents-1
914 temp-downcase
(car (car suffix-list
)) lfn
))
915 (setq found temp-downcase
))
916 ((and (fboundp 'msdos-long-file-names
)
919 (info-insert-file-contents-1
920 temp
(car (car suffix-list
)) nil
)))
922 (setq suffix-list
(cdr suffix-list
))))
923 (setq dirs
(cdr dirs
))))
925 (setq filename found
)
928 (error "Info file %s does not exist" filename
)))
931 (defun Info-find-node (filename nodename
&optional no-going-back strict-case
)
932 "Go to an Info node specified as separate FILENAME and NODENAME.
933 NO-GOING-BACK is non-nil if recovering from an error in this function;
934 it says do not attempt further (recursive) error recovery.
936 This function first looks for a case-sensitive match for NODENAME;
937 if none is found it then tries a case-insensitive match (unless
938 STRICT-CASE is non-nil)."
940 (setq filename
(Info-find-file filename
))
941 ;; Go into Info buffer.
942 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
943 ;; Record the node we are leaving, if we were in one.
944 (and (not no-going-back
)
946 (push (list Info-current-file Info-current-node
(point))
948 (Info-find-node-2 filename nodename no-going-back strict-case
))
951 (defun Info-on-current-buffer (&optional nodename
)
952 "Use Info mode to browse the current Info buffer.
953 With a prefix arg, this queries for the node name to visit first;
954 otherwise, that defaults to `Top'."
956 (list (if current-prefix-arg
957 (completing-read "Node name: " (Info-build-node-completions)
959 (unless nodename
(setq nodename
"Top"))
962 (set (make-local-variable 'Info-current-file
)
964 ;; If called on a non-file buffer, make a fake file name.
965 (concat default-directory
(buffer-name))))
966 (Info-find-node-2 nil nodename
))
968 (defun Info-revert-find-node (filename nodename
)
969 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
970 When *info* is already displaying FILENAME and NODENAME, the window position
971 is preserved, if possible."
972 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
973 (let ((old-filename Info-current-file
)
974 (old-nodename Info-current-node
)
975 (window-selected (eq (selected-window) (get-buffer-window)))
976 (pcolumn (current-column))
977 (pline (count-lines (point-min) (line-beginning-position)))
978 (wline (count-lines (point-min) (window-start)))
979 (new-history (and Info-current-file
980 (list Info-current-file Info-current-node
(point)))))
981 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
982 (setq Info-current-file nil
)
983 (Info-find-node filename nodename
)
984 (if (and (equal old-filename Info-current-file
)
985 (equal old-nodename Info-current-node
))
987 ;; note goto-line is no good, we want to measure from point-min
988 (when window-selected
989 (goto-char (point-min))
991 (set-window-start (selected-window) (point)))
992 (goto-char (point-min))
994 (move-to-column pcolumn
))
995 ;; only add to the history when coming from a different file+node
997 (setq Info-history
(cons new-history Info-history
))))))
999 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
1000 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
1001 (Info-revert-find-node Info-current-file Info-current-node
)
1002 (message "Reverted %s" Info-current-file
)))
1004 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
1005 "Find a node in a tag table.
1006 MARKER specifies the buffer and position to start searching at.
1007 REGEXP is a regular expression matching nodes or references. Its first
1008 group should match `Node:' or `Ref:'.
1009 CASE-FOLD t means search for a case-insensitive match.
1010 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1011 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1012 where the match was found, and MODE is `major-mode' of the buffer in
1013 which the match was found."
1014 (let ((case-fold-search case-fold
))
1015 (with-current-buffer (marker-buffer marker
)
1020 (when (re-search-forward regexp nil t
)
1021 (list (string-equal "Ref:" (match-string 1))
1022 (+ (point-min) (read (current-buffer)))
1025 (defun Info-find-in-tag-table (marker regexp
&optional strict-case
)
1026 "Find a node in a tag table.
1027 MARKER specifies the buffer and position to start searching at.
1028 REGEXP is a regular expression matching nodes or references. Its first
1029 group should match `Node:' or `Ref:'.
1030 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1031 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1032 where the match was found, and MODE is `major-mode' of the buffer in
1033 which the match was found.
1034 This function tries to find a case-sensitive match first, then a
1035 case-insensitive match is tried (unless optional argument STRICT-CASE
1037 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
1038 (or strict-case
(car result
)
1039 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
1042 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
1043 "Find a node or anchor in the current buffer.
1044 REGEXP is a regular expression matching nodes or references. Its first
1045 group should match `Node:' or `Ref:'.
1046 CASE-FOLD t means search for a case-insensitive match.
1047 Value is the position at which a match was found, or nil if not found."
1048 (let ((case-fold-search case-fold
)
1051 (if (Info-node-at-bob-matching regexp
)
1052 (setq found
(point))
1053 (while (and (not found
)
1054 (search-forward "\n\^_" nil t
))
1056 (let ((beg (point)))
1058 (if (re-search-backward regexp beg t
)
1059 (setq found
(line-beginning-position)))))))
1062 (defun Info-find-node-in-buffer (regexp &optional strict-case
)
1063 "Find a node or anchor in the current buffer.
1064 REGEXP is a regular expression matching nodes or references. Its first
1065 group should match `Node:' or `Ref:'.
1066 Value is the position at which a match was found, or nil if not found.
1067 This function looks for a case-sensitive match first. If none is found,
1068 a case-insensitive match is tried (unless optional argument STRICT-CASE
1070 (or (Info-find-node-in-buffer-1 regexp nil
)
1071 (and (not strict-case
)
1072 (Info-find-node-in-buffer-1 regexp t
))))
1074 (defun Info-find-node-2 (filename nodename
&optional no-going-back strict-case
)
1075 (buffer-disable-undo (current-buffer))
1076 (or (derived-mode-p 'Info-mode
)
1079 (setq Info-current-node nil
)
1081 (let ((case-fold-search t
)
1082 (virtual-fun (Info-virtual-fun 'find-node
1083 (or filename Info-current-file
)
1087 ((functionp virtual-fun
)
1088 (let ((filename (or filename Info-current-file
)))
1089 (setq buffer-read-only nil
)
1090 (setq Info-current-file filename
1091 Info-current-subfile nil
1092 Info-current-file-completions nil
1093 buffer-file-name nil
)
1095 (Info-virtual-call virtual-fun filename nodename no-going-back
)
1096 (set-marker Info-tag-table-marker nil
)
1097 (setq buffer-read-only t
)
1098 (set-buffer-modified-p nil
)
1099 (set (make-local-variable 'Info-current-node-virtual
) t
)))
1101 ;; Reread a file when moving from a virtual node.
1102 (not Info-current-node-virtual
)
1104 (equal Info-current-file filename
))))
1105 ;; Switch files if necessary
1106 (let ((inhibit-read-only t
))
1107 (when Info-current-node-virtual
1108 ;; When moving from a virtual node.
1109 (set (make-local-variable 'Info-current-node-virtual
) nil
)
1111 (setq filename Info-current-file
)))
1112 (setq Info-current-file nil
1113 Info-current-subfile nil
1114 Info-current-file-completions nil
1115 buffer-file-name nil
)
1117 (info-insert-file-contents filename nil
)
1118 (setq default-directory
(file-name-directory filename
))
1119 (set-buffer-modified-p nil
)
1120 (set (make-local-variable 'Info-file-supports-index-cookies
)
1121 (Info-file-supports-index-cookies filename
))
1123 ;; See whether file has a tag table. Record the location if yes.
1124 (goto-char (point-max))
1126 ;; Use string-equal, not equal, to ignore text props.
1127 (if (not (or (string-equal nodename
"*")
1129 (search-forward "\^_\nEnd tag table\n" nil t
))))
1131 ;; We have a tag table. Find its beginning.
1132 ;; Is this an indirect file?
1133 (search-backward "\nTag table:\n")
1137 (looking-at "(Indirect)\n"))
1138 ;; It is indirect. Copy it to another buffer
1139 ;; and record that the tag table is in that buffer.
1140 (let ((buf (current-buffer))
1142 (or Info-tag-table-buffer
1143 (generate-new-buffer " *info tag table*"))))
1144 (setq Info-tag-table-buffer tagbuf
)
1145 (with-current-buffer tagbuf
1146 (buffer-disable-undo (current-buffer))
1147 (setq case-fold-search t
)
1149 (insert-buffer-substring buf
))
1150 (set-marker Info-tag-table-marker
1151 (match-end 0) tagbuf
))
1152 (set-marker Info-tag-table-marker pos
)))
1153 (set-marker Info-tag-table-marker nil
))
1154 (setq Info-current-file filename
)
1157 ;; Use string-equal, not equal, to ignore text props.
1158 (if (string-equal nodename
"*")
1159 (progn (setq Info-current-node nodename
)
1160 (Info-set-mode-line))
1163 ;; 1. Anchor found in tag table
1164 ;; 2. Anchor *not* in tag table
1166 ;; 3. Node found in tag table
1167 ;; 4. Node *not* found in tag table, but found in file
1168 ;; 5. Node *not* in tag table, and *not* in file
1170 ;; *Or* the same, but in an indirect subfile.
1172 ;; Search file for a suitable node.
1173 (let ((guesspos (point-min))
1174 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1175 (if (stringp nodename
)
1176 (regexp-quote nodename
)
1178 "\\) *[,\t\n\177]")))
1182 ;; First, search a tag table, if any
1183 (when (marker-position Info-tag-table-marker
)
1184 (let* ((m Info-tag-table-marker
)
1185 (found (Info-find-in-tag-table m regexp strict-case
)))
1188 ;; FOUND is (ANCHOR POS MODE).
1189 (setq guesspos
(nth 1 found
))
1191 ;; If this is an indirect file, determine which
1192 ;; file really holds this node and read it in.
1193 (unless (eq (nth 2 found
) 'Info-mode
)
1194 ;; Note that the current buffer must be the
1195 ;; *info* buffer on entry to
1196 ;; Info-read-subfile. Thus the hackery above.
1197 (setq guesspos
(Info-read-subfile guesspos
)))
1201 (goto-char (setq anchorpos guesspos
))
1204 ;; Else we may have a node, which we search for:
1205 (goto-char (max (point-min)
1206 (- (byte-to-position guesspos
) 1000)))
1208 ;; Now search from our advised position (or from beg of
1209 ;; buffer) to find the actual node. First, check
1210 ;; whether the node is right where we are, in case the
1211 ;; buffer begins with a node.
1212 (let ((pos (Info-find-node-in-buffer regexp strict-case
)))
1217 (when (string-match "\\([^.]+\\)\\." nodename
)
1218 (let (Info-point-loc)
1220 filename
(match-string 1 nodename
) no-going-back
))
1224 ;; No such anchor in tag table or node in tag table or file
1225 (user-error "No such node or anchor: %s" nodename
))
1228 (goto-char (point-min))
1229 (forward-line 1) ; skip header line
1230 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1231 ;; (forward-line 1))
1234 (let ((new-history (list Info-current-file
1235 (substring-no-properties nodename
))))
1236 ;; Add anchors to the history too
1237 (setq Info-history-list
1239 (remove new-history Info-history-list
))))
1240 (goto-char anchorpos
))
1241 ((numberp Info-point-loc
)
1242 (forward-line (- Info-point-loc
2))
1243 (setq Info-point-loc nil
))
1244 ((stringp Info-point-loc
)
1245 (Info-find-index-name Info-point-loc
)
1246 (setq Info-point-loc nil
))))))
1247 ;; If we did not finish finding the specified node,
1248 ;; go back to the previous one.
1249 (or Info-current-node no-going-back
(null Info-history
)
1250 (let ((hist (car Info-history
)))
1251 (setq Info-history
(cdr Info-history
))
1252 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1253 (goto-char (nth 2 hist
))))))
1255 ;; Cache the contents of the (virtual) dir file, once we have merged
1256 ;; it for the first time, so we can save time subsequently.
1257 (defvar Info-dir-contents nil
)
1259 ;; Cache for the directory we decided to use for the default-directory
1260 ;; of the merged dir text.
1261 (defvar Info-dir-contents-directory nil
)
1263 ;; Record the file attributes of all the files from which we
1264 ;; constructed Info-dir-contents.
1265 (defvar Info-dir-file-attributes nil
)
1267 (defvar Info-dir-file-name nil
)
1269 ;; Construct the Info directory node by merging the files named `dir'
1270 ;; from various directories. Set the *info* buffer's
1271 ;; default-directory to the first directory we actually get any text
1273 (defun Info-insert-dir ()
1274 (if (and Info-dir-contents Info-dir-file-attributes
1275 ;; Verify that none of the files we used has changed
1276 ;; since we used it.
1278 (mapcar (lambda (elt)
1279 (let ((curr (file-attributes
1281 (file-truename (car elt
)))))
1283 ;; Don't compare the access time.
1284 (if curr
(setcar (nthcdr 4 curr
) 0))
1285 (setcar (nthcdr 4 (cdr elt
)) 0)
1286 (equal (cdr elt
) curr
)))
1287 Info-dir-file-attributes
))))
1289 (insert Info-dir-contents
)
1290 (goto-char (point-min)))
1291 (let ((dirs (if Info-additional-directory-list
1292 (append Info-directory-list
1293 Info-additional-directory-list
)
1294 Info-directory-list
))
1295 (dir-file-attrs nil
)
1296 ;; Bind this in case the user sets it to nil.
1297 (case-fold-search t
)
1298 ;; This is set non-nil if we find a problem in some input files.
1300 buffers buffer others nodes dirs-done
)
1302 ;; Search the directory list for the directory file.
1304 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1305 (or (member truename dirs-done
)
1306 (member (directory-file-name truename
) dirs-done
)
1307 ;; Try several variants of specified name.
1308 ;; Try upcasing, appending `.info', or both.
1312 (progn (setq file
(expand-file-name "dir" truename
))
1313 (file-attributes file
))
1314 (progn (setq file
(expand-file-name "DIR" truename
))
1315 (file-attributes file
))
1316 (progn (setq file
(expand-file-name "dir.info" truename
))
1317 (file-attributes file
))
1318 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1319 (file-attributes file
))
1320 ;; Shouldn't really happen, but sometimes does,
1321 ;; eg on Debian systems with buggy packages;
1322 ;; so may as well try it.
1323 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1324 (progn (setq file
(expand-file-name "dir.gz" truename
))
1325 (file-attributes file
)))))
1328 (cons (directory-file-name truename
)
1331 (with-current-buffer (generate-new-buffer " info dir")
1333 (message "Composing main Info directory..."))
1335 ;; Index nodes include null bytes. DIR
1336 ;; files should not have indices, but who
1338 (let ((inhibit-null-byte-detection t
))
1339 (insert-file-contents file
)
1340 (set (make-local-variable 'Info-dir-file-name
)
1342 (push (current-buffer) buffers
)
1343 (push (cons file attrs
) dir-file-attrs
))
1344 (error (kill-buffer (current-buffer))))))))
1346 (set (make-local-variable 'Info-dir-contents-directory
)
1347 (file-name-as-directory (car dirs
))))
1348 (setq dirs
(cdr dirs
))))
1351 (error "Can't find the Info directory node"))
1353 ;; Distinguish the dir file that comes with Emacs from all the
1354 ;; others. Yes, that is really what this is supposed to do.
1355 ;; The definition of `Info-directory-list' puts it first on that
1356 ;; list and so last in `buffers' at this point.
1357 (setq buffer
(car (last buffers
))
1358 others
(delq buffer buffers
))
1360 ;; Insert the entire original dir file as a start; note that we've
1361 ;; already saved its default directory to use as the default
1362 ;; directory for the whole concatenation.
1363 (save-excursion (insert-buffer-substring buffer
))
1365 ;; Look at each of the other buffers one by one.
1366 (dolist (other others
)
1367 (let (this-buffer-nodes)
1368 ;; In each, find all the menus.
1369 (with-current-buffer other
1370 (goto-char (point-min))
1371 ;; Find each menu, and add an elt to NODES for it.
1372 (while (re-search-forward "^\\* Menu:" nil t
)
1373 (while (and (zerop (forward-line 1)) (eolp)))
1376 (re-search-backward "^\^_")
1377 (search-forward "Node: ")
1378 (setq nodename
(Info-following-node-name))
1379 (search-forward "\n\^_" nil
'move
)
1382 (push (list nodename other beg end
) this-buffer-nodes
)))
1383 (if (assoc-string "top" this-buffer-nodes t
)
1384 (setq nodes
(nconc this-buffer-nodes nodes
))
1386 (message "No `top' node in %s" Info-dir-file-name
)))))
1387 ;; Add to the main menu a menu item for each other node.
1388 (re-search-forward "^\\* Menu:")
1390 (let ((menu-items '("top"))
1391 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1392 (dolist (node nodes
)
1393 (let ((nodename (car node
)))
1395 (or (member (downcase nodename
) menu-items
)
1396 (re-search-forward (concat "^\\* +"
1397 (regexp-quote nodename
)
1401 (insert "* " nodename
"::" "\n")
1402 (push nodename menu-items
)))))))
1403 ;; Now take each node of each of the other buffers
1404 ;; and merge it into the main buffer.
1405 (dolist (node nodes
)
1406 (let ((case-fold-search t
)
1407 (nodename (car node
)))
1408 (goto-char (point-min))
1409 ;; Find the like-named node in the main buffer.
1410 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1411 (regexp-quote nodename
)
1415 (search-forward "\n\^_" nil
'move
)
1418 ;; If none exists, add one.
1419 (goto-char (point-max))
1420 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1421 ;; Merge the text from the other buffer's menu
1422 ;; into the menu in the like-named node in the main buffer.
1423 (apply 'insert-buffer-substring
(cdr node
))))
1424 (Info-dir-remove-duplicates)
1425 ;; Kill all the buffers we just made, including the special one excised.
1426 (mapc 'kill-buffer
(cons buffer buffers
))
1427 (goto-char (point-min))
1429 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1430 (message "Composing main Info directory...done"))
1431 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1432 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1433 (setq default-directory Info-dir-contents-directory
))
1435 (defvar Info-streamline-headings
1436 '(("Emacs" .
"Emacs")
1437 ("Programming" .
"Programming")
1438 ("Libraries" .
"Libraries")
1439 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1440 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1442 (defun Info-dir-remove-duplicates ()
1444 (goto-char (point-min))
1445 ;; Remove duplicate headings in the same menu.
1446 (while (search-forward "\n* Menu:" nil t
)
1447 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1448 ;; Look for the next heading to unify.
1449 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1450 (let ((name (match-string 1))
1451 (start (match-beginning 0))
1453 ;; Check whether this heading should be streamlined.
1455 (dolist (x Info-streamline-headings
)
1456 (when (string-match (car x
) name
)
1458 (setq re
(car x
)))))
1459 (if re
(replace-match name t t nil
1))
1460 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1462 (or limit
(point-max))))
1463 ;; Look for other headings of the same category and merge them.
1465 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1466 (when (if re
(save-match-data (string-match re
(match-string 1)))
1467 (equal name
(match-string 1)))
1469 ;; Delete redundant heading.
1470 (delete-region (match-beginning 0) (point))
1471 ;; Push the entries onto `text'.
1473 (delete-and-extract-region
1475 (if (re-search-forward "^[^* \n\t]" nil t
)
1477 (or limit
(point-max))))
1480 ;; Insert the entries just found.
1481 (while (= (line-beginning-position 0) (1- (point)))
1483 (dolist (entry (nreverse entries
))
1485 (while (= (line-beginning-position 0) (1- (point)))
1486 (delete-region (1- (point)) (point))))
1488 ;; Now remove duplicate entries under the same heading.
1491 (narrow-to-region start
(point))
1492 (goto-char (point-min))
1493 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1494 ;; Fold case straight away; `member-ignore-case' here wasteful.
1495 (let ((x (downcase (match-string 1))))
1499 (if (re-search-forward "^[^ \t]" nil
'move
)
1500 (goto-char (match-beginning 0))
1502 (push x seen
)))))))))))
1504 ;; Note that on entry to this function the current-buffer must be the
1505 ;; *info* buffer; not the info tags buffer.
1506 (defun Info-read-subfile (nodepos)
1507 ;; NODEPOS is either a position (in the Info file as a whole,
1508 ;; not relative to a subfile) or the name of a subfile.
1511 (if (numberp nodepos
)
1512 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1513 (goto-char (point-min))
1514 (or (looking-at "\^_")
1515 (search-forward "\n\^_"))
1518 (while (not (looking-at "\^_"))
1521 thisfilepos thisfilename
)
1522 (search-forward ": ")
1523 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1524 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1525 ;; read in version 19 stops at the end of number.
1526 ;; Advance to the next line.
1528 (if (> thisfilepos nodepos
)
1530 (setq lastfilename thisfilename
)
1531 (setq lastfilepos thisfilepos
))
1532 (forward-line 1)))))
1533 (setq lastfilename nodepos
)
1534 (setq lastfilepos
0))
1535 ;; Assume previous buffer is in Info-mode.
1536 ;; (set-buffer (get-buffer "*info*"))
1537 (or (equal Info-current-subfile lastfilename
)
1538 (let ((inhibit-read-only t
))
1539 (setq buffer-file-name nil
)
1542 (info-insert-file-contents lastfilename
)
1543 (set-buffer-modified-p nil
)
1544 (setq Info-current-subfile lastfilename
)))
1545 ;; Widen in case we are in the same subfile as before.
1547 (goto-char (point-min))
1548 ;; Skip the summary segment for `Info-search'.
1549 (if (looking-at "\^_")
1551 (search-forward "\n\^_"))
1552 ;; Don't add the length of the skipped summary segment to
1553 ;; the value returned to `Info-find-node-2'. (Bug#14125)
1554 (if (numberp nodepos
)
1555 (+ (- nodepos lastfilepos
) (point-min)))))
1557 (defun Info-unescape-quotes (value)
1558 "Unescape double quotes and backslashes in VALUE."
1561 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1562 (setq unquote
(replace-match "" t t unquote
1))
1563 (setq start
(- (match-end 0) 1)))
1566 ;; As of Texinfo 4.6, makeinfo writes constructs like
1567 ;; \0\h[image param=value ...\h\0]
1568 ;; into the Info file for handling images.
1569 (defun Info-split-parameter-string (parameter-string)
1570 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1571 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1572 If VALUE contains whitespace or double quotes, it must be quoted
1573 in double quotes and any double quotes or backslashes must be
1574 escaped (\\\",\\\\)."
1577 (while (string-match
1578 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1579 parameter-string start
)
1580 (setq start
(match-end 0))
1581 (push (cons (match-string 1 parameter-string
)
1582 (or (match-string 2 parameter-string
)
1583 (Info-unescape-quotes
1584 (match-string 3 parameter-string
))))
1588 (defun Info-display-images-node ()
1589 "Display images in current node."
1591 (let ((inhibit-read-only t
)
1592 (case-fold-search t
))
1593 (goto-char (point-min))
1594 (while (re-search-forward
1595 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1597 (let* ((start (match-beginning 1))
1598 (parameter-alist (Info-split-parameter-string (match-string 2)))
1599 (src (cdr (assoc-string "src" parameter-alist
))))
1600 (if (display-images-p)
1601 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1602 (concat default-directory src
))
1604 (image (if (file-exists-p image-file
)
1605 (create-image image-file
)
1606 (or (cdr (assoc-string "text" parameter-alist
))
1607 (and src
(concat "[broken image:" src
"]"))
1608 "[broken image]"))))
1609 (if (not (get-text-property start
'display
))
1610 (add-text-properties
1612 `(display ,image rear-nonsticky
(display)
1613 help-echo
,(cdr (assoc-string "alt" parameter-alist
))))))
1614 ;; text-only display, show alternative text if provided, or
1615 ;; otherwise a clue that there's meant to be a picture
1616 (delete-region start
(point))
1617 (insert (or (cdr (assoc-string "text" parameter-alist
))
1618 (cdr (assoc-string "alt" parameter-alist
))
1619 (and src
(concat "[image:" src
"]"))
1621 (set-buffer-modified-p nil
)))
1623 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1624 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1625 ;; including one optional trailing newline.
1626 (defun Info-hide-cookies-node ()
1627 "Hide unrecognized cookies in current node."
1629 (let ((inhibit-read-only t
)
1630 (case-fold-search t
))
1631 (goto-char (point-min))
1632 (while (re-search-forward
1633 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1635 (let* ((start (match-beginning 1)))
1636 (if (and (not (get-text-property start
'invisible
))
1637 (not (get-text-property start
'display
)))
1638 (put-text-property start
(point) 'invisible t
)))))
1639 (set-buffer-modified-p nil
)))
1641 (defun Info-select-node ()
1642 "Select the Info node that point is in."
1643 ;; Bind this in case the user sets it to nil.
1644 (let ((case-fold-search t
))
1646 ;; Find beginning of node.
1647 (if (search-backward "\n\^_" nil
'move
)
1649 (if (looking-at "\^_")
1651 (signal 'search-failed
(list "\n\^_"))))
1652 ;; Get nodename spelled as it is in the node.
1653 (re-search-forward "Node:[ \t]*")
1654 (setq Info-current-node
1655 (buffer-substring-no-properties (point)
1657 (skip-chars-forward "^,\t\n")
1659 (Info-set-mode-line)
1660 ;; Find the end of it, and narrow.
1662 (let (active-expression)
1663 ;; Narrow to the node contents
1664 (narrow-to-region (point)
1665 (if (re-search-forward "\n[\^_\f]" nil t
)
1668 (if (looking-at "[\n\^_\f]*execute: ")
1670 (goto-char (match-end 0))
1671 (setq active-expression
1672 (read (current-buffer))))))
1674 (if Info-enable-active-nodes
(eval active-expression
))
1675 ;; Add a new unique history item to full history list
1676 (let ((new-history (list Info-current-file Info-current-node
)))
1677 (setq Info-history-list
1678 (cons new-history
(remove new-history Info-history-list
)))
1679 (setq Info-history-forward nil
))
1680 (if (not (eq Info-fontify-maximum-menu-size nil
))
1681 (Info-fontify-node))
1682 (Info-display-images-node)
1683 (Info-hide-cookies-node)
1684 (run-hooks 'Info-selection-hook
)))))
1686 (defvar Info-mode-line-node-keymap
1687 (let ((map (make-sparse-keymap)))
1688 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1689 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1691 "Keymap to put on the Info node name in the mode line.")
1693 (defun Info-set-mode-line ()
1694 (setq mode-line-buffer-identification
1695 (nconc (propertized-buffer-identification "%b")
1699 (if (stringp Info-current-file
)
1700 (replace-regexp-in-string
1702 (file-name-sans-extension
1703 (file-name-nondirectory Info-current-file
)))
1704 (format "*%S*" Info-current-file
))
1706 (if Info-current-node
1707 (propertize (replace-regexp-in-string
1708 "%" "%%" Info-current-node
)
1709 'face
'mode-line-buffer-id
1711 "mouse-1: scroll forward, mouse-3: scroll back"
1712 'mouse-face
'mode-line-highlight
1713 'local-map Info-mode-line-node-keymap
)
1716 ;; Go to an Info node specified with a filename-and-nodename string
1717 ;; of the sort that is found in pointers in nodes.
1719 ;; Don't autoload this function: the correct entry point for other packages
1720 ;; to use is `info'. --Stef
1722 (defun Info-goto-node (nodename &optional fork strict-case
)
1723 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1724 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1725 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1727 Completion is available for node names in the current Info file as well as
1728 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1729 Empty NODENAME in (FILENAME) defaults to the Top node.
1730 If FORK is non-nil (interactively with a prefix arg), show the node in
1732 If FORK is a string, it is the name to use for the new buffer.
1734 This function first looks for a case-sensitive match for the node part
1735 of NODENAME; if none is found it then tries a case-insensitive match
1736 \(unless STRICT-CASE is non-nil)."
1737 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1741 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1743 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1745 (setq filename
(if (= (match-beginning 1) (match-end 1))
1747 (match-string 2 nodename
))
1748 nodename
(match-string 3 nodename
))
1749 (let ((trim (string-match "\\s +\\'" filename
)))
1750 (if trim
(setq filename
(substring filename
0 trim
))))
1751 (let ((trim (string-match "\\s +\\'" nodename
)))
1752 (if trim
(setq nodename
(substring nodename
0 trim
))))
1753 (if transient-mark-mode
(deactivate-mark))
1754 (Info-find-node (if (equal filename
"") nil filename
)
1755 (if (equal nodename
"") "Top" nodename
) nil strict-case
)))
1757 (defvar Info-read-node-completion-table
)
1759 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1760 "Internal function used to complete Info node names.
1761 Return a completion table for Info files---the FILENAME part of a
1762 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1763 directories to search if FILENAME is not absolute; SUFFIXES is a
1764 list of valid filename suffixes for Info files. See
1765 `try-completion' for a description of the remaining arguments."
1766 (setq suffixes
(remove "" suffixes
))
1767 (when (file-name-absolute-p string
)
1768 (setq dirs
(list (file-name-directory string
))))
1770 (names-sans-suffix nil
)
1771 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1772 (string-dir (file-name-directory string
)))
1775 (setq dir default-directory
))
1776 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1777 (when (file-directory-p dir
)
1778 (dolist (file (file-name-all-completions
1779 (file-name-nondirectory string
) dir
))
1780 ;; If the file name has no suffix or a standard suffix,
1782 (and (or (null (file-name-extension file
))
1783 (string-match suffix file
))
1784 ;; But exclude subfiles of split Info files.
1785 (not (string-match "-[0-9]+\\'" file
))
1786 ;; And exclude backup files.
1787 (not (string-match "~\\'" file
))
1788 (push (if string-dir
(concat string-dir file
) file
) names
))
1789 ;; If the file name ends in a standard suffix,
1790 ;; add the unsuffixed name as a completion option.
1791 (when (string-match suffix file
)
1792 (setq file
(substring file
0 (match-beginning 0)))
1793 (push (if string-dir
(concat string-dir file
) file
)
1794 names-sans-suffix
)))))
1795 ;; If there is just one file, don't duplicate it with suffixes,
1796 ;; so `Info-read-node-name-1' will be able to complete a single
1797 ;; candidate and to add the terminating ")".
1798 (if (and (= (length names
) 1) (= (length names-sans-suffix
) 1))
1799 (setq names names-sans-suffix
)
1800 (setq names
(append names-sans-suffix names
)))
1801 (complete-with-action action names string pred
)))
1803 (defun Info-read-node-name-1 (string predicate code
)
1804 "Internal function used by `Info-read-node-name'.
1805 See `completing-read' for a description of arguments and usage."
1807 ;; First complete embedded file names.
1808 ((string-match "\\`([^)]*\\'" string
)
1809 (completion-table-with-context
1811 (apply-partially 'completion-table-with-terminator
")"
1812 (apply-partially 'Info-read-node-name-2
1814 (mapcar 'car Info-suffix-list
)))
1815 (substring string
1)
1818 ;; If a file name was given, complete nodes in the file.
1819 ((string-match "\\`(\\([^)]+\\))" string
)
1820 (let ((file0 (match-string 0 string
))
1821 (file1 (match-string 1 string
))
1822 (nodename (substring string
(match-end 0))))
1823 (if (and (equal nodename
"") (eq code
'lambda
))
1824 ;; Empty node name is permitted that means "Top".
1826 (completion-table-with-context
1829 (lambda (string pred action
)
1830 (complete-with-action
1832 (Info-build-node-completions (Info-find-file file1
))
1834 nodename predicate code
))))
1835 ;; Otherwise use Info-read-node-completion-table.
1836 (t (complete-with-action
1837 code Info-read-node-completion-table string predicate
))))
1839 ;; Arrange to highlight the proper letters in the completion list buffer.
1840 (defun Info-read-node-name (prompt)
1841 "Read an Info node name with completion, prompting with PROMPT.
1842 A node name can have the form \"NODENAME\", referring to a node
1843 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1844 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1845 the Top node in FILENAME."
1846 (let* ((completion-ignore-case t
)
1847 (Info-read-node-completion-table (Info-build-node-completions))
1848 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1849 (if (equal nodename
"")
1850 (Info-read-node-name prompt
)
1853 (defun Info-build-node-completions (&optional filename
)
1855 (or (cdr (assoc filename Info-file-completions
))
1858 (Info-goto-node (format "(%s)Top" filename
))
1859 (Info-build-node-completions-1)
1860 (push (cons filename Info-current-file-completions
) Info-file-completions
)
1861 Info-current-file-completions
))
1862 (or Info-current-file-completions
1863 (Info-build-node-completions-1))))
1865 (defun Info-build-node-completions-1 ()
1867 ;; Bind this in case the user sets it to nil.
1868 (case-fold-search t
)
1869 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1872 (or Info-tag-table-marker
1873 (error "No Info tags found"))
1874 (if (marker-buffer Info-tag-table-marker
)
1875 (let ((marker Info-tag-table-marker
))
1876 (set-buffer (marker-buffer marker
))
1879 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1881 (cons (list (match-string-no-properties 2))
1884 (goto-char (point-min))
1885 ;; If the buffer begins with a node header, process that first.
1886 (if (Info-node-at-bob-matching node-regexp
)
1887 (setq compl
(list (match-string-no-properties 1))))
1888 ;; Now for the rest of the nodes.
1889 (while (search-forward "\n\^_" nil t
)
1891 (let ((beg (point)))
1893 (if (re-search-backward node-regexp beg t
)
1895 (cons (list (match-string-no-properties 1))
1897 (setq compl
(cons '("*") (nreverse compl
)))
1898 (set (make-local-variable 'Info-current-file-completions
) compl
)
1902 (defun Info-restore-point (hl)
1903 "If this node has been visited, restore the point value when we left."
1905 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1906 ;; Use string-equal, not equal, to ignore text props.
1907 (string-equal (nth 1 (car hl
)) Info-current-node
))
1909 (goto-char (nth 2 (car hl
)))
1910 (setq hl nil
)) ;terminate the while at next iter
1911 (setq hl
(cdr hl
)))))
1913 (defvar Info-search-history nil
1914 "The history list for `Info-search'.")
1916 (defvar Info-search-case-fold nil
1917 "The value of `case-fold-search' from previous `Info-search' command.")
1919 (defun Info--search-loop (regexp bound backward
)
1921 ;; Hide Info file header for backward search.
1922 (narrow-to-region (save-excursion
1923 (goto-char (point-min))
1924 (search-forward "\n\^_")
1930 (while (not (or give-up
1932 (funcall isearch-filter-predicate
1934 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1936 (if backward
#'re-search-backward
#'re-search-forward
)
1938 (setq found
(point) beg-found
(if backward
(match-end 0)
1939 (match-beginning 0)))
1940 (setq give-up t found nil
))))
1943 (defun Info-search (regexp &optional bound _noerror _count direction
)
1944 "Search for REGEXP, starting from point, and select node it's found in.
1945 If DIRECTION is `backward', search in the reverse direction."
1946 (interactive (list (read-string
1947 (if Info-search-history
1948 (format "Regexp search%s (default %s): "
1949 (if case-fold-search
"" " case-sensitively")
1950 (car Info-search-history
))
1951 (format "Regexp search%s: "
1952 (if case-fold-search
"" " case-sensitively")))
1953 nil
'Info-search-history
)))
1955 (when (equal regexp
"")
1956 (setq regexp
(car Info-search-history
)))
1958 (setq Info-search-case-fold case-fold-search
)
1959 (let* ((backward (eq direction
'backward
))
1960 (onode Info-current-node
)
1961 (ofile Info-current-file
)
1963 (opoint-min (point-min))
1964 (opoint-max (point-max))
1965 (ostart (window-start))
1966 (osubfile Info-current-subfile
)
1971 (Info--search-loop regexp bound backward
)))))
1973 (unless (or (not isearch-mode
) (not Info-isearch-search
)
1974 Info-isearch-initial-node
1976 (and found
(> found opoint-min
) (< found opoint-max
)))
1977 (signal 'search-failed
(list regexp
"end of node")))
1979 ;; If no subfiles, give error now.
1980 (unless (or found Info-current-subfile
)
1982 (signal 'search-failed
(list regexp
"end of manual"))
1983 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1985 (re-search-backward regexp
)
1986 (re-search-forward regexp
)))))
1988 (if (and bound
(not found
))
1989 (signal 'search-failed
(list regexp
)))
1991 (unless (or found bound
)
1993 ;; Try other subfiles.
1995 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1996 (goto-char (point-min))
1997 (search-forward "\n\^_\nIndirect:")
1999 (narrow-to-region (point)
2000 (progn (search-forward "\n\^_")
2002 (goto-char (point-min))
2003 ;; Find the subfile we just searched.
2004 (search-forward (concat "\n" osubfile
": "))
2006 (forward-line (if backward
0 1))
2007 (if backward
(forward-char -
1))
2008 ;; Make a list of all following subfiles.
2009 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2010 (while (not (if backward
(bobp) (eobp)))
2012 (re-search-backward "\\(^.*\\): [0-9]+$")
2013 (re-search-forward "\\(^.*\\): [0-9]+$"))
2014 (goto-char (+ (match-end 1) 2))
2015 (setq list
(cons (cons (+ (point-min)
2016 (read (current-buffer)))
2017 (match-string-no-properties 1))
2019 (goto-char (if backward
2020 (1- (match-beginning 0))
2021 (1+ (match-end 0)))))
2022 ;; Put in forward order
2023 (setq list
(nreverse list
))))
2025 (message "Searching subfile %s..." (cdr (car list
)))
2026 (Info-read-subfile (car (car list
)))
2027 (when backward
(goto-char (point-max)))
2028 (setq list
(cdr list
))
2029 (setq found
(Info--search-loop regexp nil backward
))
2034 (signal 'search-failed
(if isearch-mode
2035 (list regexp
"end of manual")
2038 (progn (Info-read-subfile osubfile
)
2041 (set-window-start (selected-window) ostart
)))))
2043 (if (and (string= osubfile Info-current-subfile
)
2044 (> found opoint-min
)
2045 (< found opoint-max
))
2046 ;; Search landed in the same node
2050 (save-match-data (Info-select-node)))
2052 ;; Use string-equal, not equal, to ignore text props.
2053 (or (and (string-equal onode Info-current-node
)
2054 (equal ofile Info-current-file
))
2055 (and isearch-mode isearch-wrapped
2056 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
2057 (setq Info-history
(cons (list ofile onode opoint
)
2060 (defun Info-search-case-sensitively ()
2061 "Search for a regexp case-sensitively."
2063 (let ((case-fold-search nil
))
2064 (call-interactively 'Info-search
)))
2066 (defun Info-search-next ()
2067 "Search for next regexp from a previous `Info-search' command."
2069 (let ((case-fold-search Info-search-case-fold
))
2070 (if Info-search-history
2071 (Info-search (car Info-search-history
))
2072 (call-interactively 'Info-search
))))
2074 (defun Info-search-backward (regexp &optional bound noerror count
)
2075 "Search for REGEXP in the reverse direction."
2076 (interactive (list (read-string
2077 (if Info-search-history
2078 (format "Regexp search%s backward (default %s): "
2079 (if case-fold-search
"" " case-sensitively")
2080 (car Info-search-history
))
2081 (format "Regexp search%s backward: "
2082 (if case-fold-search
"" " case-sensitively")))
2083 nil
'Info-search-history
)))
2084 (Info-search regexp bound noerror count
'backward
))
2086 (defun Info-isearch-search ()
2087 (if Info-isearch-search
2088 (lambda (string &optional bound noerror count
)
2089 (let ((Info-search-whitespace-regexp
2090 (if (if isearch-regexp
2091 isearch-regexp-lax-whitespace
2092 isearch-lax-whitespace
)
2093 search-whitespace-regexp
)))
2097 ;; Lax version of word search
2098 (let ((lax (not (or isearch-nonincremental
2100 (length (isearch--state-string
2101 (car isearch-cmds
))))))))
2102 (if (functionp isearch-word
)
2103 (funcall isearch-word string lax
)
2104 (word-search-regexp string lax
))))
2105 (isearch-regexp string
)
2106 (t (regexp-quote string
)))
2108 (unless isearch-forward
'backward
)))
2110 (isearch-search-fun-default)))
2112 (defun Info-isearch-wrap ()
2113 (if Info-isearch-search
2114 (if Info-isearch-initial-node
2116 (if isearch-forward
(Info-top-node) (Info-final-node))
2117 (goto-char (if isearch-forward
(point-min) (point-max))))
2118 (setq Info-isearch-initial-node Info-current-node
)
2119 (setq isearch-wrapped nil
))
2120 (goto-char (if isearch-forward
(point-min) (point-max)))))
2122 (defun Info-isearch-push-state ()
2124 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
2126 (defun Info-isearch-pop-state (_cmd file node
)
2127 (or (and (equal Info-current-file file
)
2128 (equal Info-current-node node
))
2129 (progn (Info-find-node file node
) (sit-for 0))))
2131 (defun Info-isearch-start ()
2132 (setq Info-isearch-initial-node
2133 ;; Don't stop at initial node for nonincremental search.
2134 ;; Otherwise this variable is set after first search failure.
2135 (and isearch-nonincremental Info-current-node
))
2136 (setq Info-isearch-initial-history Info-history
2137 Info-isearch-initial-history-list Info-history-list
)
2138 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
2140 (defun Info-isearch-end ()
2141 ;; Remove intermediate nodes (visited while searching)
2142 ;; from the history. Add only the last node (where Isearch ended).
2143 (if (> (length Info-history
)
2144 (length Info-isearch-initial-history
))
2146 (nthcdr (- (length Info-history
)
2147 (length Info-isearch-initial-history
)
2150 (if (> (length Info-history-list
)
2151 (length Info-isearch-initial-history-list
))
2152 (setq Info-history-list
2153 (cons (car Info-history-list
)
2154 Info-isearch-initial-history-list
)))
2155 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
2157 (defun Info-isearch-filter (beg-found found
)
2158 "Test whether the current search hit is a visible useful text.
2159 Return non-nil if the text from BEG-FOUND to FOUND is visible
2160 and is not in the header line or a tag table."
2162 (let ((backward (< found beg-found
)))
2165 (and (not search-invisible
)
2167 (or (text-property-not-all found beg-found
'invisible nil
)
2168 (text-property-not-all found beg-found
'display nil
))
2169 (or (text-property-not-all beg-found found
'invisible nil
)
2170 (text-property-not-all beg-found found
'display nil
))))
2171 ;; Skip node header line
2172 (and (save-excursion (forward-line -
1)
2174 (forward-line (if backward -
1 1)))
2175 ;; Skip Tag Table node
2177 (and (search-backward "\^_" nil t
)
2179 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2182 (defun Info-extract-pointer (name &optional errorname
)
2183 "Extract the value of the node-pointer named NAME.
2184 If there is none, use ERRORNAME in the error message;
2185 if ERRORNAME is nil, just return nil."
2186 ;; Bind this in case the user sets it to nil.
2187 (let ((case-fold-search t
))
2189 (goto-char (point-min))
2190 (let ((bound (point)))
2192 (cond ((re-search-backward
2193 (concat name
":" (Info-following-node-name-re)) bound t
)
2194 (match-string-no-properties 1))
2195 ((not (eq errorname t
))
2196 (user-error "Node has no %s"
2197 (capitalize (or errorname name
)))))))))
2199 (defun Info-following-node-name-re (&optional allowedchars
)
2200 "Return a regexp matching a node name.
2201 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2202 saying which chars may appear in the node name.
2203 Submatch 1 is the complete node name.
2204 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2205 Submatch 3 is the local part of the node name.
2206 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2207 (concat "[ \t\n]*" ;Skip leading space.
2208 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2209 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2210 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2211 "\\|\\)\\)")) ;Allow empty node names.
2213 ;;; For compatibility; other files have used this name.
2214 (defun Info-following-node-name ()
2215 (and (looking-at (Info-following-node-name-re))
2216 (match-string-no-properties 1)))
2219 "Go to the next node of this node."
2221 ;; In case another window is currently selected
2222 (save-window-excursion
2223 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2224 (Info-goto-node (Info-extract-pointer "next"))))
2227 "Go to the previous node of this node."
2229 ;; In case another window is currently selected
2230 (save-window-excursion
2231 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2232 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2234 (defun Info-up (&optional same-file
)
2235 "Go to the superior node of this node.
2236 If SAME-FILE is non-nil, do not move to a different Info file."
2238 ;; In case another window is currently selected
2239 (save-window-excursion
2240 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2241 (let ((old-node Info-current-node
)
2242 (old-file Info-current-file
)
2243 (node (Info-extract-pointer "up")) p
)
2245 (string-match "^(" node
)
2246 (error "Up node is in another Info file"))
2247 (Info-goto-node node
)
2249 (goto-char (point-min))
2250 (if (and (stringp old-file
)
2251 (search-forward "\n* Menu:" nil t
)
2253 (if (string-equal old-node
"Top")
2254 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2255 (concat "\n\\* +\\(" (regexp-quote old-node
)
2256 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2258 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2260 (Info-restore-point Info-history
)))))
2262 (defun Info-history-back ()
2263 "Go back in the history to the last node visited."
2266 (user-error "This is the first Info node you looked at"))
2267 (let ((history-forward
2268 (cons (list Info-current-file Info-current-node
(point))
2269 Info-history-forward
))
2270 filename nodename opoint
)
2271 (setq filename
(car (car Info-history
)))
2272 (setq nodename
(car (cdr (car Info-history
))))
2273 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2274 (setq Info-history
(cdr Info-history
))
2275 (Info-find-node filename nodename
)
2276 (setq Info-history
(cdr Info-history
))
2277 (setq Info-history-forward history-forward
)
2278 (goto-char opoint
)))
2280 (defalias 'Info-last
'Info-history-back
)
2282 (defun Info-history-forward ()
2283 "Go forward in the history of visited nodes."
2285 (or Info-history-forward
2286 (user-error "This is the last Info node you looked at"))
2287 (let ((history-forward (cdr Info-history-forward
))
2288 filename nodename opoint
)
2289 (setq filename
(car (car Info-history-forward
)))
2290 (setq nodename
(car (cdr (car Info-history-forward
))))
2291 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2292 (Info-find-node filename nodename
)
2293 (setq Info-history-forward history-forward
)
2294 (goto-char opoint
)))
2296 (add-to-list 'Info-virtual-files
2298 (toc-nodes . Info-directory-toc-nodes
)
2299 (find-file . Info-directory-find-file
)
2300 (find-node . Info-directory-find-node
)
2303 (defun Info-directory-toc-nodes (filename)
2304 "Directory-specific implementation of `Info-toc-nodes'."
2306 ("Top" nil nil nil
)))
2308 (defun Info-directory-find-file (filename &optional _noerror
)
2309 "Directory-specific implementation of `Info-find-file'."
2312 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2313 "Directory-specific implementation of `Info-find-node-2'."
2317 (defun Info-directory ()
2318 "Go to the Info directory node."
2320 (Info-find-node "dir" "top"))
2322 (add-to-list 'Info-virtual-files
2323 '("\\`\\*History\\*\\'"
2324 (toc-nodes . Info-history-toc-nodes
)
2325 (find-file . Info-history-find-file
)
2326 (find-node . Info-history-find-node
)
2329 (defun Info-history-toc-nodes (filename)
2330 "History-specific implementation of `Info-toc-nodes'."
2332 ("Top" nil nil nil
)))
2334 (defun Info-history-find-file (filename &optional _noerror
)
2335 "History-specific implementation of `Info-find-file'."
2338 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2339 "History-specific implementation of `Info-find-node-2'."
2340 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2341 (or filename Info-current-file
) nodename
))
2342 (insert "Recently Visited Nodes\n")
2343 (insert "**********************\n\n")
2344 (insert "* Menu:\n\n")
2345 (let ((hl (remove '("*History*" "Top") Info-history-list
)))
2347 (let ((file (nth 0 (car hl
)))
2348 (node (nth 1 (car hl
))))
2350 (insert "* " node
": ("
2351 (propertize (or (file-name-directory file
) "") 'invisible t
)
2352 (file-name-nondirectory file
)
2354 (setq hl
(cdr hl
)))))
2356 (defun Info-history ()
2357 "Go to a node with a menu of visited nodes."
2359 (Info-find-node "*History*" "Top")
2360 (Info-next-reference)
2361 (Info-next-reference))
2363 (add-to-list 'Info-virtual-nodes
2365 (find-node . Info-toc-find-node
)
2368 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2369 "Toc-specific implementation of `Info-find-node-2'."
2370 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2371 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2372 (node-list (Info-toc-nodes curr-file
)))
2373 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2374 curr-file curr-node
))
2375 (insert "Table of Contents\n")
2376 (insert "*****************\n\n")
2377 (insert "*Note Top::\n")
2379 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2380 node-list
0 curr-file
)
2382 (let ((Info-hide-note-references 'hide
)
2383 (Info-fontify-visited-nodes nil
))
2384 (setq Info-current-file filename Info-current-node
"*TOC*")
2385 (goto-char (point-min))
2386 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2393 "Go to a node with table of contents of the current Info file.
2394 Table of contents is created from the tree structure of menus."
2396 (Info-find-node Info-current-file
"*TOC*")
2397 (let ((prev-node (nth 1 (car Info-history
))) p
)
2398 (goto-char (point-min))
2399 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2400 (setq p
(- p
(length prev-node
) 2)))
2401 (goto-char (or p
(point-min)))))
2403 (defun Info-toc-insert (nodes node-list level curr-file
)
2404 "Insert table of contents with references to nodes."
2405 (let ((section "Top"))
2407 (let ((node (assoc (car nodes
) node-list
)))
2408 (unless (member (nth 2 node
) (list nil section
))
2409 (insert (setq section
(nth 2 node
)) "\n"))
2410 (insert (make-string level ?
\t))
2411 (insert "*Note " (car nodes
) ":: \n")
2412 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2413 (setq nodes
(cdr nodes
))))))
2415 (defun Info-toc-build (file)
2416 "Build table of contents from menus of Info FILE and its subfiles."
2418 (let* ((file (and (stringp file
) (Info-find-file file
)))
2419 (default-directory (or (and (stringp file
)
2420 (file-name-directory file
))
2422 (main-file (and (stringp file
) file
))
2423 (sections '(("Top" "Top")))
2425 (while (or main-file subfiles
)
2426 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2428 (info-insert-file-contents (or main-file
(car subfiles
)))
2429 (goto-char (point-min))
2430 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2431 (search-forward "Node: " nil
'move
))
2432 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2433 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2435 (upnode (and (re-search-forward
2436 (concat "Up:" (Info-following-node-name-re))
2438 (match-string-no-properties 1)))
2441 (when (and upnode
(string-match "(" upnode
)) (setq upnode nil
))
2442 (when (and (not (Info-index-node nodename file
))
2443 (re-search-forward "^\\* Menu:" bound t
))
2446 (setq bound
(or (and (equal nodename
"Top")
2449 "^[ \t-]*The Detailed Node Listing" nil t
)))
2451 (while (< (point) bound
)
2454 ((looking-at "^\\* +[^:]+:")
2457 (let ((menu-node-name (substring-no-properties
2458 (Info-extract-menu-node-name))))
2459 (setq menu-items
(cons menu-node-name menu-items
))
2460 (if (equal nodename
"Top")
2462 (cons (list menu-node-name section
) sections
)))))
2463 ;; Other non-empty strings in the Top node are section names
2464 ((and (equal nodename
"Top")
2465 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2466 (setq section
(match-string-no-properties 1))))
2468 (beginning-of-line)))
2469 (setq nodes
(cons (list nodename upnode
2470 (cadr (assoc nodename sections
))
2471 (nreverse menu-items
))
2476 (goto-char (point-min))
2477 (if (search-forward "\n\^_\nIndirect:" nil t
)
2478 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2479 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2480 (setq subfiles
(cons (match-string-no-properties 1)
2482 (setq subfiles
(nreverse subfiles
)
2484 (setq subfiles
(cdr subfiles
))))
2488 (defun Info-toc-nodes (filename)
2489 "Return a node list of Info FILENAME with parent-children information.
2490 This information is cached in the variable `Info-toc-nodes' with the help
2491 of the function `Info-toc-build'."
2494 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2497 (or filename
(setq filename Info-current-file
))
2498 (or (assoc filename Info-toc-nodes
)
2499 ;; Skip virtual Info files
2500 (and (or (not (stringp filename
))
2501 (Info-virtual-file-p filename
))
2502 (push (cons filename nil
) Info-toc-nodes
))
2503 ;; Scan the entire manual and cache the result in Info-toc-nodes
2504 (let ((nodes (Info-toc-build filename
)))
2505 (push (cons filename nodes
) Info-toc-nodes
)
2507 ;; If there is an error, still add nil to the cache
2508 (push (cons filename nil
) Info-toc-nodes
))
2509 (cdr (assoc filename Info-toc-nodes
)))))
2512 (defun Info-follow-reference (footnotename &optional fork
)
2513 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2514 FOOTNOTENAME may be an abbreviation of the reference name.
2515 If FORK is non-nil (interactively with a prefix arg), show the node in
2516 a new Info buffer. If FORK is a string, it is the name to use for the
2519 (let ((completion-ignore-case t
)
2520 (case-fold-search t
)
2521 completions default alt-default
(start-point (point)) str i bol eol
)
2523 ;; Store end and beginning of line.
2524 (setq eol
(line-end-position)
2525 bol
(line-beginning-position))
2526 (goto-char (point-min))
2527 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2528 (setq str
(match-string-no-properties 1))
2529 ;; See if this one should be the default.
2531 (<= (match-beginning 0) start-point
)
2532 (<= start-point
(point))
2534 ;; See if this one should be the alternate default.
2535 (and (null alt-default
)
2536 (and (<= bol
(match-beginning 0))
2538 (setq alt-default t
))
2540 (while (setq i
(string-match "[ \n\t]+" str i
))
2541 (setq str
(concat (substring str
0 i
) " "
2542 (substring str
(match-end 0))))
2544 ;; Record as a completion and perhaps as default.
2545 (if (eq default t
) (setq default str
))
2546 (if (eq alt-default t
) (setq alt-default str
))
2547 ;; Don't add this string if it's a duplicate.
2548 (or (assoc-string str completions t
)
2549 (push str completions
))))
2550 ;; If no good default was found, try an alternate.
2552 (setq default alt-default
))
2553 ;; If only one cross-reference found, then make it default.
2554 (if (eq (length completions
) 1)
2555 (setq default
(car completions
)))
2557 (let ((input (completing-read (if default
2559 "Follow reference named (default "
2561 "Follow reference named: ")
2562 completions nil t
)))
2563 (list (if (equal input
"")
2564 default input
) current-prefix-arg
))
2565 (user-error "No cross-references in this node"))))
2567 (unless footnotename
2568 (error "No reference was specified"))
2570 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2571 (case-fold-search t
))
2572 (while (setq i
(string-match " " str i
))
2573 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2576 ;; Move point to the beginning of reference if point is on reference
2577 (or (looking-at "\\*note[ \n\t]+")
2578 (and (looking-back "\\*note[ \n\t]+")
2579 (goto-char (match-beginning 0)))
2580 (if (and (save-excursion
2581 (goto-char (+ (point) 5)) ; skip a possible *note
2582 (re-search-backward "\\*note[ \n\t]+" nil t
)
2584 (<= (point) (match-end 0)))
2585 (goto-char (match-beginning 0))))
2586 ;; Go to the reference closest to point
2587 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2588 (+ (match-beginning 0) 5))))
2589 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2590 (+ (match-beginning 0) 5)))))
2591 (goto-char (cond ((and next-ref prev-ref
)
2592 (if (< (abs (- next-ref
(point)))
2593 (abs (- prev-ref
(point))))
2595 ((or next-ref prev-ref
))
2596 ((user-error "No cross-reference named %s"
2598 (setq target
(Info-extract-menu-node-name t
))))
2599 (while (setq i
(string-match "[ \t\n]+" target i
))
2600 (setq target
(concat (substring target
0 i
) " "
2601 (substring target
(match-end 0))))
2603 (Info-goto-node target fork
)))
2605 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2606 ;; We allow newline because this is also used in Info-follow-reference,
2607 ;; where the xref name might be wrapped over two lines.
2608 "Regexp that matches a menu entry name upto but not including the colon.
2609 Because of ambiguities, this should be concatenated with something like
2610 `:' and `Info-following-node-name-re'.")
2612 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2613 (skip-chars-forward " \t\n")
2614 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2615 (Info-following-node-name-re
2617 (index-node "^,\t\n")
2618 (multi-line "^.,\t")
2622 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2625 (setq Info-point-loc
2626 (if (match-beginning 5)
2627 (string-to-number (match-string 5))
2628 (buffer-substring-no-properties
2629 (match-beginning 0) (1- (match-beginning 1)))))
2630 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2631 ;;; (setq Info-point-loc
2632 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2634 (replace-regexp-in-string
2636 (or (and (not (equal (match-string-no-properties 2) ""))
2637 (match-string-no-properties 2))
2638 ;; If the node name is the menu entry name (using `entry::').
2639 (buffer-substring-no-properties
2640 (match-beginning 0) (1- (match-beginning 1)))))))
2642 ;; No one calls this.
2643 ;;(defun Info-menu-item-sequence (list)
2645 ;; (Info-menu (car list))
2646 ;; (setq list (cdr list))))
2648 (defvar Info-complete-menu-buffer
)
2649 (defvar Info-complete-next-re nil
)
2650 (defvar Info-complete-nodes nil
)
2651 (defvar Info-complete-cache nil
)
2653 (defconst Info-node-spec-re
2654 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2655 "Regexp to match the text after a : until the terminating `.'.")
2657 (defun Info-complete-menu-item (string predicate action
)
2658 ;; This uses two dynamically bound variables:
2659 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2660 ;; is the menu of items we're trying to complete.
2661 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2662 ;; also look for menu items in subsequent nodes as long as those
2663 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2665 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2666 ;; also look for menu items in these nodes. This feature is currently
2667 ;; only used for completion in Info-index.
2669 ;; Note that `Info-complete-menu-buffer' could be current already,
2670 ;; so we want to save point.
2671 (with-current-buffer Info-complete-menu-buffer
2673 (let ((completion-ignore-case t
)
2674 (case-fold-search t
)
2675 (orignode Info-current-node
)
2677 (goto-char (point-min))
2678 (search-forward "\n* Menu:")
2680 ((eq (car-safe action
) 'boundaries
) nil
)
2681 ((eq action
'lambda
)
2683 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2685 (let ((pattern (concat "\n\\* +\\("
2686 (regexp-quote string
)
2687 Info-menu-entry-name-re
"\\):"
2690 (complete-nodes Info-complete-nodes
))
2692 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2693 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2694 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2695 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2696 (let ((prev (nth 3 Info-complete-cache
)))
2697 (eq t
(compare-strings string
0 (length prev
)
2699 ;; We can reuse the previous list.
2700 (setq completions
(nth 4 Info-complete-cache
))
2701 ;; The cache can't be used.
2704 (while (re-search-forward pattern nil t
)
2705 (push (match-string-no-properties 1)
2707 (setq completions
(delete-dups completions
))
2708 ;; Check subsequent nodes if applicable.
2709 (or (and Info-complete-next-re
2710 (setq nextnode
(Info-extract-pointer "next" t
))
2711 (string-match Info-complete-next-re nextnode
))
2713 (setq complete-nodes
(cdr complete-nodes
)
2714 nextnode
(car complete-nodes
)))))
2715 (Info-goto-node nextnode
))
2716 ;; Go back to the start node (for the next completion).
2717 (unless (equal Info-current-node orignode
)
2718 (Info-goto-node orignode
))
2719 ;; Update the cache.
2720 (set (make-local-variable 'Info-complete-cache
)
2721 (list Info-current-file Info-current-node
2722 Info-complete-next-re string completions
2723 Info-complete-nodes
)))
2724 (complete-with-action action completions string predicate
))))))))
2727 (defun Info-menu (menu-item &optional fork
)
2728 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2729 The menu item should one of those listed in the current node's menu.
2730 Completion is allowed, and the default menu item is the one point is on.
2731 If FORK is non-nil (interactively with a prefix arg), show the node in
2732 a new Info buffer. If FORK is a string, it is the name to use for the
2735 (let (;; If point is within a menu item, use that item as the default
2739 (case-fold-search t
))
2741 (goto-char (point-min))
2742 (if (not (search-forward "\n* menu:" nil t
))
2743 (user-error "No menu in this node"))
2749 (if (re-search-backward (concat "\n\\* +\\("
2750 Info-menu-entry-name-re
2752 (setq default
(match-string-no-properties 1))))))
2755 (setq item
(let ((completion-ignore-case t
)
2756 (Info-complete-menu-buffer (current-buffer)))
2757 (completing-read (if default
2758 (format "Menu item (default %s): "
2761 'Info-complete-menu-item nil t
)))
2762 ;; we rely on the fact that completing-read accepts an input
2763 ;; of "" even when the require-match argument is true and ""
2764 ;; is not a valid possibility
2765 (if (string= item
"")
2770 (list item current-prefix-arg
))))
2771 ;; there is a problem here in that if several menu items have the same
2772 ;; name you can only go to the node of the first with this command.
2773 (Info-goto-node (Info-extract-menu-item menu-item
)
2775 (if (stringp fork
) fork menu-item
))))
2777 (defun Info-extract-menu-item (menu-item)
2778 (setq menu-item
(regexp-quote menu-item
))
2779 (let ((case-fold-search t
))
2781 (let ((case-fold-search t
))
2782 (goto-char (point-min))
2783 (or (search-forward "\n* menu:" nil t
)
2784 (user-error "No menu in this node"))
2785 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2786 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2787 (user-error "No such item in menu"))
2790 (Info-extract-menu-node-name nil
(Info-index-node))))))
2792 ;; If COUNT is nil, use the last item in the menu.
2793 (defun Info-extract-menu-counting (count &optional no-detail
)
2794 (let ((case-fold-search t
))
2796 (let ((case-fold-search t
)
2797 (bound (when (and no-detail
2799 "^[ \t-]*The Detailed Node Listing" nil t
))
2800 (match-beginning 0))))
2801 (goto-char (point-min))
2802 (or (search-forward "\n* menu:" bound t
)
2803 (user-error "No menu in this node"))
2805 (or (search-forward "\n* " bound t count
)
2806 (error "Too few items in menu"))
2807 (while (search-forward "\n* " bound t
)
2809 (Info-extract-menu-node-name nil
(Info-index-node))))))
2811 (defun Info-nth-menu-item ()
2812 "Go to the node of the Nth menu item.
2813 N is the digit argument used to invoke this command."
2816 (Info-extract-menu-counting
2817 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2819 (defun Info-top-node ()
2820 "Go to the Top node of this file."
2822 (Info-goto-node "Top"))
2824 (defun Info-final-node ()
2825 "Go to the final node in this file."
2827 (Info-goto-node "Top")
2828 (let ((Info-history nil
)
2829 (case-fold-search t
))
2830 ;; Go to the last node in the menu of Top. But don't delve into
2831 ;; detailed node listings.
2832 (Info-goto-node (Info-extract-menu-counting nil t
))
2833 ;; If the last node in the menu is not last in pointer structure,
2834 ;; move forward (but not down- or upward - see bug#1116) until we
2835 ;; can't go any farther.
2836 (while (Info-forward-node t t t
) nil
)
2837 ;; Then keep moving down to last subnode, unless we reach an index.
2838 (while (and (not (Info-index-node))
2839 (save-excursion (search-forward "\n* Menu:" nil t
)))
2840 (Info-goto-node (Info-extract-menu-counting nil
)))))
2842 (defun Info-forward-node (&optional not-down not-up no-error
)
2843 "Go forward one node, considering all nodes as forming one sequence."
2845 (goto-char (point-min))
2847 (let ((case-fold-search t
))
2848 ;; three possibilities, in order of priority:
2849 ;; 1. next node is in a menu in this node (but not in an index)
2850 ;; 2. next node is next at same level
2851 ;; 3. next node is up and next
2852 (cond ((and (not not-down
)
2853 (save-excursion (search-forward "\n* menu:" nil t
))
2854 (not (Info-index-node)))
2855 (Info-goto-node (Info-extract-menu-counting 1))
2857 ((save-excursion (search-backward "next:" nil t
))
2861 (save-excursion (search-backward "up:" nil t
))
2862 ;; Use string-equal, not equal, to ignore text props.
2863 (not (string-equal (downcase (Info-extract-pointer "up"))
2865 (let ((old-node Info-current-node
))
2867 (let ((old-history Info-history
)
2870 (setq success
(Info-forward-node t nil no-error
))
2871 (or success
(Info-goto-node old-node
)))
2872 (if Info-history-skip-intermediate-nodes
2873 (setq Info-history old-history
)))))
2875 (t (user-error "No pointer forward from this node")))))
2877 (defun Info-backward-node ()
2878 "Go backward one node, considering all nodes as forming one sequence."
2880 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2881 (upnode (Info-extract-pointer "up" t
))
2882 (case-fold-search t
))
2883 (cond ((and upnode
(string-match "(" upnode
))
2884 (user-error "First node in file"))
2885 ((and upnode
(or (null prevnode
)
2886 ;; Use string-equal, not equal,
2887 ;; to ignore text properties.
2888 (string-equal (downcase prevnode
)
2889 (downcase upnode
))))
2892 ;; If we move back at the same level,
2893 ;; go down to find the last subnode*.
2895 (let ((old-history Info-history
))
2896 (while (and (not (Info-index-node))
2897 (save-excursion (search-forward "\n* Menu:" nil t
)))
2898 (Info-goto-node (Info-extract-menu-counting nil
)))
2899 (if Info-history-skip-intermediate-nodes
2900 (setq Info-history old-history
))))
2902 (user-error "No pointer backward from this node")))))
2905 "Exit Info by selecting some other buffer."
2908 (save-buffers-kill-emacs)
2911 (defun Info-next-menu-item ()
2912 "Go to the node of the next menu item."
2914 ;; Bind this in case the user sets it to nil.
2915 (let* ((case-fold-search t
)
2919 (search-forward "\n* menu:" nil t
)
2920 (and (search-forward "\n* " nil t
)
2921 (Info-extract-menu-node-name)))))
2922 (if node
(Info-goto-node node
)
2923 (user-error "No more items in menu"))))
2925 (defun Info-last-menu-item ()
2926 "Go to the node of the previous menu item."
2930 ;; Bind this in case the user sets it to nil.
2931 (let* ((case-fold-search t
)
2932 (beg (save-excursion
2933 (and (search-backward "\n* menu:" nil t
)
2935 (or (and beg
(search-backward "\n* " beg t
))
2936 (user-error "No previous items in menu")))
2937 (Info-goto-node (save-excursion
2938 (goto-char (match-end 0))
2939 (Info-extract-menu-node-name)))))
2941 (defmacro Info-no-error
(&rest body
)
2942 `(condition-case nil
(progn ,@body t
) (error nil
)))
2944 (defun Info-next-preorder ()
2945 "Go to the next subnode or the next node, or go up a level."
2947 (cond ((Info-no-error (Info-next-menu-item)))
2948 ((Info-no-error (Info-next)))
2949 ((Info-no-error (Info-up t
))
2950 ;; Since we have already gone thru all the items in this menu,
2951 ;; go up to the end of this node.
2952 (goto-char (point-max))
2953 ;; Since logically we are done with the node with that menu,
2954 ;; move on from it. But don't add intermediate nodes
2955 ;; to the history on recursive calls.
2956 (let ((old-history Info-history
))
2957 (Info-next-preorder)
2958 (if Info-history-skip-intermediate-nodes
2959 (setq Info-history old-history
))))
2961 (user-error "No more nodes"))))
2963 (defun Info-last-preorder ()
2964 "Go to the last node, popping up a level if there is none."
2966 (cond ((and Info-scroll-prefer-subnodes
2968 (Info-last-menu-item)
2969 ;; If we go down a menu item, go to the end of the node
2970 ;; so we can scroll back through it.
2971 (goto-char (point-max))))
2972 ;; Keep going down, as long as there are nested menu nodes.
2973 (let ((old-history Info-history
))
2974 (while (Info-no-error
2975 (Info-last-menu-item)
2976 ;; If we go down a menu item, go to the end of the node
2977 ;; so we can scroll back through it.
2978 (goto-char (point-max))))
2979 (if Info-history-skip-intermediate-nodes
2980 (setq Info-history old-history
)))
2982 ((and (Info-no-error (Info-extract-pointer "prev"))
2983 (not (equal (Info-extract-pointer "up")
2984 (Info-extract-pointer "prev"))))
2985 (Info-no-error (Info-prev))
2986 (goto-char (point-max))
2987 (let ((old-history Info-history
))
2988 (while (Info-no-error
2989 (Info-last-menu-item)
2990 ;; If we go down a menu item, go to the end of the node
2991 ;; so we can scroll back through it.
2992 (goto-char (point-max))))
2993 (if Info-history-skip-intermediate-nodes
2994 (setq Info-history old-history
)))
2996 ((Info-no-error (Info-up t
))
2997 (goto-char (point-min))
2998 (let ((case-fold-search t
))
2999 (or (search-forward "\n* Menu:" nil t
)
3000 (goto-char (point-max)))))
3001 (t (user-error "No previous nodes"))))
3003 (defun Info-scroll-up ()
3004 "Scroll one screenful forward in Info, considering all nodes as one sequence.
3005 Once you scroll far enough in a node that its menu appears on the screen
3006 but after point, the next scroll moves into its first subnode, unless
3007 `Info-scroll-prefer-subnodes' is nil.
3009 When you scroll past the end of a node, that goes to the next node if
3010 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3011 if this node has no successor, it moves to the parent node's successor,
3012 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3013 the menu of a node, it moves to subnode indicated by the following menu
3014 item. (That case won't normally result from this command, but can happen
3018 (if (or (< (window-start) (point-min))
3019 (> (window-start) (point-max)))
3020 (set-window-start (selected-window) (point)))
3021 (let* ((case-fold-search t
)
3022 (virtual-end (save-excursion
3023 (goto-char (point-min))
3024 (if (and Info-scroll-prefer-subnodes
3025 (search-forward "\n* Menu:" nil t
))
3028 (if (or (< virtual-end
(window-start))
3029 (pos-visible-in-window-p virtual-end
))
3031 (Info-scroll-prefer-subnodes (Info-next-preorder))
3032 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3033 (t (Info-next-preorder)))
3036 (defun Info-mouse-scroll-up (e)
3037 "Scroll one screenful forward in Info, using the mouse.
3038 See `Info-scroll-up'."
3040 (save-selected-window
3042 (select-window (posn-window (event-start e
))))
3045 (defun Info-scroll-down ()
3046 "Scroll one screenful back in Info, considering all nodes as one sequence.
3047 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3048 is non-nil, this goes to its last subnode. When you scroll past the
3049 beginning of a node, that goes to the previous node or back up to the
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 (current-point (point))
3058 (and Info-scroll-prefer-subnodes
3060 (setq current-point
(line-beginning-position))
3061 (goto-char (point-min))
3062 (search-forward "\n* Menu:" current-point t
)))))
3064 (pos-visible-in-window-p (point-min) nil t
))
3065 (Info-last-preorder)
3068 (defun Info-mouse-scroll-down (e)
3069 "Scroll one screenful backward in Info, using the mouse.
3070 See `Info-scroll-down'."
3072 (save-selected-window
3074 (select-window (posn-window (event-start e
))))
3075 (Info-scroll-down)))
3077 (defun Info-next-reference-or-link (pat prop
)
3078 "Move point to the next pattern-based cross-reference or property-based link.
3079 The next cross-reference is searched using the regexp PAT, and the next link
3080 is searched using the text property PROP. Move point to the closest found position
3081 of either a cross-reference found by `re-search-forward' or a link found by
3082 `next-single-char-property-change'. Return the new position of point, or nil."
3083 (let ((pxref (save-excursion (re-search-forward pat nil t
)))
3084 (plink (next-single-char-property-change (point) prop
)))
3085 (when (and (< plink
(point-max)) (not (get-char-property plink prop
)))
3086 (setq plink
(next-single-char-property-change plink prop
)))
3087 (if (< plink
(point-max))
3088 (if (and pxref
(<= pxref plink
))
3089 (goto-char (or (match-beginning 1) (match-beginning 0)))
3091 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3093 (defun Info-prev-reference-or-link (pat prop
)
3094 "Move point to the previous pattern-based cross-reference or property-based link.
3095 The previous cross-reference is searched using the regexp PAT, and the previous link
3096 is searched using the text property PROP. Move point to the closest found position
3097 of either a cross-reference found by `re-search-backward' or a link found by
3098 `previous-single-char-property-change'. Return the new position of point, or nil."
3099 (let ((pxref (save-excursion (re-search-backward pat nil t
)))
3100 (plink (previous-single-char-property-change (point) prop
)))
3101 (when (and (> plink
(point-min)) (not (get-char-property plink prop
)))
3102 (setq plink
(previous-single-char-property-change plink prop
)))
3103 (if (> plink
(point-min))
3104 (if (and pxref
(>= pxref plink
))
3105 (goto-char (or (match-beginning 1) (match-beginning 0)))
3107 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3109 (defun Info-next-reference (&optional recur count
)
3110 "Move cursor to the next cross-reference or menu item in the node.
3111 If COUNT is non-nil (interactively with a prefix arg), jump over
3112 COUNT cross-references."
3113 (interactive "i\np")
3117 (Info-prev-reference recur
(- count
))
3118 (while (unless (zerop count
) (setq count
(1- count
)))
3119 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3121 (case-fold-search t
))
3122 (or (eobp) (forward-char 1))
3123 (or (Info-next-reference-or-link pat
'link
)
3125 (goto-char (point-min))
3126 (or (Info-next-reference-or-link pat
'link
)
3129 (user-error "No cross references in this node")))))
3130 (if (looking-at "\\* Menu:")
3132 (user-error "No cross references in this node")
3133 (Info-next-reference t
))
3134 (if (looking-at "^\\* ")
3135 (forward-char 2)))))))
3137 (defun Info-prev-reference (&optional recur count
)
3138 "Move cursor to the previous cross-reference or menu item in the node.
3139 If COUNT is non-nil (interactively with a prefix arg), jump over
3140 COUNT cross-references."
3141 (interactive "i\np")
3145 (Info-next-reference recur
(- count
))
3146 (while (unless (zerop count
) (setq count
(1- count
)))
3147 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3149 (case-fold-search t
))
3150 (or (Info-prev-reference-or-link pat
'link
)
3152 (goto-char (point-max))
3153 (or (Info-prev-reference-or-link pat
'link
)
3156 (user-error "No cross references in this node")))))
3157 (if (looking-at "\\* Menu:")
3159 (user-error "No cross references in this node")
3160 (Info-prev-reference t
))
3161 (if (looking-at "^\\* ")
3162 (forward-char 2)))))))
3164 (defun Info-index-nodes (&optional file
)
3165 "Return a list of names of all index nodes in Info FILE.
3166 If FILE is omitted, it defaults to the current Info file.
3167 First look in a list of cached index node names. Then scan Info
3168 file and its subfiles for nodes with the index cookie. Then try
3169 to find index nodes starting from the first node in the top level
3170 menu whose name contains the word \"Index\", plus any immediately
3171 following nodes whose names also contain the word \"Index\"."
3172 (or file
(setq file Info-current-file
))
3173 (or (assoc file Info-index-nodes
)
3174 ;; Skip virtual Info files
3175 (and (or (not (stringp file
))
3176 (Info-virtual-file-p file
))
3177 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3178 (if (Info-file-supports-index-cookies file
)
3179 ;; Find nodes with index cookie
3180 (let* ((default-directory (or (and (stringp file
)
3181 (file-name-directory
3182 (setq file
(Info-find-file file
))))
3184 Info-history Info-history-list Info-fontify-maximum-menu-size
3185 (main-file file
) subfiles nodes
)
3188 (while (or main-file subfiles
)
3190 (info-insert-file-contents (or main-file
(car subfiles
)))
3191 (goto-char (point-min))
3192 (while (search-forward "\0\b[index\0\b]" nil
'move
)
3194 (re-search-backward "^\^_")
3195 (search-forward "Node: ")
3196 (setq nodes
(cons (Info-following-node-name) nodes
))))
3199 (goto-char (point-min))
3200 (if (search-forward "\n\^_\nIndirect:" nil t
)
3201 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
3202 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
3203 (setq subfiles
(cons (match-string-no-properties 1)
3205 (setq subfiles
(nreverse subfiles
)
3207 (setq subfiles
(cdr subfiles
)))))
3210 (setq nodes
(nreverse nodes
)
3211 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3213 ;; Else find nodes with the word "Index" in the node name
3214 (let ((case-fold-search t
)
3215 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3220 (Info-find-node file
"Top")
3221 (when (and (search-forward "\n* menu:" nil t
)
3222 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
3223 (goto-char (match-beginning 1))
3224 (setq nodes
(list (Info-extract-menu-node-name)))
3225 (Info-goto-node (car nodes
))
3226 (while (and (setq node
(Info-extract-pointer "next" t
))
3227 (string-match "\\<Index\\>" node
))
3229 (Info-goto-node node
))))
3232 (setq nodes
(nreverse nodes
)
3233 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3235 ;; If file has no index nodes, still add it to the cache
3236 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3237 (cdr (assoc file Info-index-nodes
)))
3239 (defun Info-index-node (&optional node file
)
3240 "Return non-nil value if NODE is an index node.
3241 If NODE is nil, check the current Info node.
3242 If FILE is nil, check the current Info file."
3243 (or file
(setq file Info-current-file
))
3244 (if (and (or (and node
(not (equal node Info-current-node
)))
3245 (assoc file Info-index-nodes
))
3246 (not Info-current-node-virtual
))
3247 (member (or node Info-current-node
) (Info-index-nodes file
))
3248 ;; Don't search all index nodes if request is only for the current node
3249 ;; and file is not in the cache of index nodes
3251 (if (Info-file-supports-index-cookies file
)
3253 (goto-char (+ (or (save-excursion
3254 (search-backward "\n\^_" nil t
))
3256 (search-forward "\0\b[index\0\b]"
3258 (search-forward "\n\^_" nil t
))
3260 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3262 (defun Info-goto-index ()
3263 "Go to the first index node."
3264 (let ((node (car (Info-index-nodes))))
3265 (or node
(error "No index"))
3266 (Info-goto-node node
)))
3269 (defun Info-index (topic)
3270 "Look up a string TOPIC in the index for this manual and go to that entry.
3271 If there are no exact matches to the specified topic, this chooses
3272 the first match which is a case-insensitive substring of a topic.
3273 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3274 Give an empty topic name to go to the Index node itself."
3277 (let ((completion-ignore-case t
)
3278 (Info-complete-menu-buffer (clone-buffer))
3279 (Info-complete-nodes (Info-index-nodes))
3280 (Info-history-list nil
))
3281 (if (equal Info-current-file
"dir")
3282 (error "The Info directory node has no index; use m to select a manual"))
3284 (with-current-buffer Info-complete-menu-buffer
3286 (completing-read "Index topic: " 'Info-complete-menu-item
))
3287 (kill-buffer Info-complete-menu-buffer
)))))
3288 (if (equal Info-current-file
"dir")
3289 (error "The Info directory node has no index; use m to select a manual"))
3290 ;; Strip leading colon in topic; index format does not allow them.
3291 (if (and (stringp topic
)
3292 (> (length topic
) 0)
3293 (= (aref topic
0) ?
:))
3294 (setq topic
(substring topic
1)))
3295 (let ((orignode Info-current-node
)
3296 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3297 (regexp-quote topic
)))
3298 node
(nodes (Info-index-nodes))
3299 (ohist-list Info-history-list
)
3300 (case-fold-search t
))
3302 (or (equal topic
"")
3305 ;; We bind Info-history to nil for internal node-switches so
3306 ;; that we don't put junk in the history. In the first
3307 ;; Info-goto-index call, above, we do update the history
3308 ;; because that is what the user's previous node choice into it.
3313 (goto-char (point-min))
3314 (while (re-search-forward pattern nil t
)
3315 (let ((entry (match-string-no-properties 1))
3316 (nodename (match-string-no-properties 3))
3317 (line (string-to-number (concat "0" (match-string 4)))))
3318 (add-text-properties
3319 (- (match-beginning 2) (match-beginning 1))
3320 (- (match-end 2) (match-beginning 1))
3321 '(face info-index-match
) entry
)
3322 (push (list entry nodename Info-current-node line
) matches
)))
3323 (setq nodes
(cdr nodes
) node
(car nodes
)))
3324 (Info-goto-node node
))
3327 (Info-goto-node orignode
)
3328 (user-error "No `%s' in index" topic
)))
3329 ;; Here it is a feature that assoc is case-sensitive.
3330 (while (setq found
(assoc topic matches
))
3331 (setq exact
(cons found exact
)
3332 matches
(delq found matches
)))
3333 (setq Info-history-list ohist-list
)
3334 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3335 (Info-index-next 0)))))
3337 (defun Info-index-next (num)
3338 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3340 (or Info-index-alternatives
3341 (user-error "No previous `i' command"))
3343 (setq num
(+ num
(length Info-index-alternatives
))))
3345 (setq Info-index-alternatives
3346 (nconc (cdr Info-index-alternatives
)
3347 (list (car Info-index-alternatives
)))
3349 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3350 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3351 ;; Forward 2 lines less because `Info-find-node-2' initially
3352 ;; puts point to the 2nd line.
3353 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3354 (forward-line 3) ; don't search in headers
3355 (let ((name (car (car Info-index-alternatives
))))
3356 (Info-find-index-name name
)))
3357 (message "Found `%s' in %s. %s"
3358 (car (car Info-index-alternatives
))
3359 (nth 2 (car Info-index-alternatives
))
3360 (if (cdr Info-index-alternatives
)
3361 (format "(%s total; use `%s' for next)"
3362 (length Info-index-alternatives
)
3363 (key-description (where-is-internal
3364 'Info-index-next overriding-local-map
3368 (defun Info-find-index-name (name)
3369 "Move point to the place within the current node where NAME is defined."
3370 (let ((case-fold-search t
))
3371 (if (or (re-search-forward (format
3372 "[a-zA-Z]+: %s\\( \\|$\\)"
3373 (regexp-quote name
)) nil t
)
3374 ;; Find a function definition with a return type.
3375 (re-search-forward (format
3376 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3377 (regexp-quote name
)) nil t
)
3378 (search-forward (format "`%s'" name
) nil t
)
3379 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3381 (format "`%s'" (substring name
0 (match-beginning 1)))
3383 (search-forward name nil t
)
3384 ;; Try again without the " <1>" makeinfo can append
3385 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3386 (Info-find-index-name (match-string 1 name
))))
3387 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3388 (goto-char (point-min)))))
3390 (add-to-list 'Info-virtual-nodes
3391 '("\\`\\*Index.*\\*\\'"
3392 (find-node . Info-virtual-index-find-node
)
3396 (defvar Info-virtual-index-nodes nil
3397 "Alist of cached matched index search nodes.
3398 Each element is ((FILENAME . TOPIC) MATCHES) where
3399 FILENAME is the file name of the manual,
3400 TOPIC is the search string given as an argument to `Info-virtual-index',
3401 MATCHES is a list of index matches found by `Info-index'.")
3403 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3404 "Index-specific implementation of `Info-find-node-2'."
3405 ;; Generate Index-like menu of matches
3406 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3407 ;; Generate Index-like menu of matches
3408 (let* ((topic (match-string 1 nodename
))
3409 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3410 Info-virtual-index-nodes
))))
3411 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3412 (or filename Info-current-file
) nodename
))
3413 (insert "Info Virtual Index\n")
3414 (insert "******************\n\n")
3415 (insert "Index entries that match `" topic
"':\n\n")
3416 (insert "\0\b[index\0\b]\n")
3418 (insert "No matches found.\n")
3419 (insert "* Menu:\n\n")
3420 (dolist (entry matches
)
3421 (insert (format "* %-38s %s.%s\n"
3422 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3425 (format " (line %s)" (nth 3 entry
))
3427 ;; Else, Generate a list of previous search results
3428 (let ((nodes (reverse Info-virtual-index-nodes
)))
3429 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3430 (or filename Info-current-file
) nodename
))
3431 (insert "Info Virtual Index\n")
3432 (insert "******************\n\n")
3433 (insert "This is a list of search results produced by\n"
3434 "`Info-virtual-index' for the current manual.\n\n")
3435 (insert "* Menu:\n\n")
3436 (dolist (nodeinfo nodes
)
3437 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3439 (format "* %-20s %s.\n"
3440 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3441 (cdr (nth 0 nodeinfo
)))))))))
3443 (defun Info-virtual-index (topic)
3444 "Show a node with all lines in the index containing a string TOPIC.
3445 Like `Info-index' but displays a node with index search results.
3446 Give an empty topic name to go to the node with links to previous
3448 ;; `interactive' is a copy from `Info-index'
3451 (let ((completion-ignore-case t
)
3452 (Info-complete-menu-buffer (clone-buffer))
3453 (Info-complete-nodes (Info-index-nodes))
3454 (Info-history-list nil
))
3455 (if (equal Info-current-file
"dir")
3456 (error "The Info directory node has no index; use m to select a manual"))
3458 (with-current-buffer Info-complete-menu-buffer
3460 (completing-read "Index topic: " 'Info-complete-menu-item
))
3461 (kill-buffer Info-complete-menu-buffer
)))))
3462 (if (equal topic
"")
3463 (Info-find-node Info-current-file
"*Index*")
3464 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3465 (let ((orignode Info-current-node
)
3466 (ohist-list Info-history-list
))
3467 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3469 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3470 Info-virtual-index-nodes
)
3471 ;; Clean up unnecessary side-effects of `Info-index'.
3472 (setq Info-history-list ohist-list
)
3473 (Info-goto-node orignode
)
3475 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3477 (add-to-list 'Info-virtual-files
3478 '("\\`\\*Apropos\\*\\'"
3479 (toc-nodes . Info-apropos-toc-nodes
)
3480 (find-file . Info-apropos-find-file
)
3481 (find-node . Info-apropos-find-node
)
3485 (defvar Info-apropos-file
"*Apropos*"
3486 "Info file name of the virtual manual for matches of `info-apropos'.")
3488 (defvar Info-apropos-nodes nil
3489 "Alist of cached apropos matched nodes.
3490 Each element is (NODENAME STRING MATCHES) where
3491 NODENAME is the name of the node that holds the search result,
3492 STRING is the search string given as an argument to `info-apropos',
3493 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3495 (defun Info-apropos-toc-nodes (filename)
3496 "Apropos-specific implementation of `Info-toc-nodes'."
3497 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3499 ("Top" nil nil
,nodes
)
3500 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3502 (defun Info-apropos-find-file (filename &optional _noerror
)
3503 "Apropos-specific implementation of `Info-find-file'."
3506 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3507 "Apropos-specific implementation of `Info-find-node-2'."
3508 (if (equal nodename
"Top")
3509 ;; Generate Top menu
3510 (let ((nodes (reverse Info-apropos-nodes
)))
3511 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3512 Info-apropos-file nodename
))
3513 (insert "Apropos Index\n")
3514 (insert "*************\n\n")
3515 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3516 (insert "* Menu:\n\n")
3517 (dolist (nodeinfo nodes
)
3518 (insert (format "* %-20s %s.\n"
3519 (format "%s::" (nth 0 nodeinfo
))
3520 (nth 1 nodeinfo
)))))
3521 ;; Else, Generate Index-like menu of matches
3522 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3523 (matches (nth 2 nodeinfo
)))
3525 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3526 Info-apropos-file nodename
))
3527 (insert "Apropos Index\n")
3528 (insert "*************\n\n")
3529 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3530 (insert "\0\b[index\0\b]\n")
3532 (insert "No matches found.\n")
3533 (insert "* Menu:\n\n")
3534 (dolist (entry matches
)
3535 (insert (format "* %-38s (%s)%s.%s\n"
3536 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3540 (format " (line %s)" (nth 3 entry
))
3543 (defun Info-apropos-matches (string)
3544 "Collect STRING matches from all known Info files on your system.
3545 Return a list of matches where each element is in the format
3546 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3547 (unless (string= string
"")
3548 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3549 (regexp-quote string
)))
3550 (ohist Info-history
)
3551 (ohist-list Info-history-list
)
3552 (current-node Info-current-node
)
3553 (current-file Info-current-file
)
3554 manuals matches node nodes
)
3555 (let ((Info-fontify-maximum-menu-size nil
))
3557 ;; current-node and current-file are nil when they invoke info-apropos
3558 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3559 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3560 ;; the search is complete.
3561 (when (null current-node
)
3562 (setq current-file Info-current-file
)
3563 (setq current-node Info-current-node
))
3564 (message "Searching indices...")
3565 (goto-char (point-min))
3566 (re-search-forward "\\* Menu: *\n" nil t
)
3567 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3568 ;; add-to-list makes sure we don't have duplicates in `manuals',
3569 ;; so that the following dolist loop runs faster.
3570 (add-to-list 'manuals
(match-string 1)))
3571 (dolist (manual (nreverse manuals
))
3572 (message "Searching %s" manual
)
3574 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3576 (Info-find-node manual
(car nodes
))
3579 (goto-char (point-min))
3580 (while (re-search-forward pattern nil t
)
3581 (let ((entry (match-string-no-properties 1))
3582 (nodename (match-string-no-properties 3))
3583 (line (match-string-no-properties 4)))
3584 (add-text-properties
3585 (- (match-beginning 2) (match-beginning 1))
3586 (- (match-end 2) (match-beginning 1))
3587 '(face info-index-match
) entry
)
3588 (setq matches
(cons (list manual entry nodename line
)
3590 (setq nodes
(cdr nodes
) node
(car nodes
)))
3591 (Info-goto-node node
))))
3593 (message "%s" (if (eq (car-safe err
) 'error
)
3596 (Info-find-node current-file current-node
)
3597 (setq Info-history ohist
3598 Info-history-list ohist-list
)
3599 (message "Searching indices...done")
3600 (or (nreverse matches
) t
))))
3603 (defun info-apropos (string)
3604 "Grovel indices of all known Info files on your system for STRING.
3605 Build a menu of the possible matches."
3606 (interactive "sIndex apropos: ")
3607 (if (equal string
"")
3608 (Info-find-node Info-apropos-file
"Top")
3609 (let* ((nodes Info-apropos-nodes
) nodename
)
3610 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3611 (setq nodes
(cdr nodes
)))
3613 (Info-find-node Info-apropos-file
(car (car nodes
)))
3614 (setq nodename
(format "Index for `%s'" string
))
3615 (push (list nodename string
(Info-apropos-matches string
))
3617 (Info-find-node Info-apropos-file nodename
)))))
3619 (add-to-list 'Info-virtual-files
3620 '("\\`\\*Finder.*\\*\\'"
3621 (find-file . Info-finder-find-file
)
3622 (find-node . Info-finder-find-node
)
3625 (defvar Info-finder-file
"*Finder*"
3626 "Info file name of the virtual Info keyword finder manual.")
3628 (defun Info-finder-find-file (filename &optional _noerror
)
3629 "Finder-specific implementation of `Info-find-file'."
3632 (defvar finder-known-keywords
)
3633 (declare-function find-library-name
"find-func" (library))
3634 (declare-function finder-unknown-keywords
"finder" ())
3635 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3636 (defvar finder-keywords-hash
)
3637 (defvar package--builtins
) ; finder requires package
3639 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3640 "Finder-specific implementation of `Info-find-node-2'."
3643 ((equal nodename
"Top")
3644 ;; Display Top menu with descriptions of the keywords
3645 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3646 Info-finder-file nodename
))
3647 (insert "Finder Keywords\n")
3648 (insert "***************\n\n")
3649 (insert "* Menu:\n\n")
3650 (dolist (assoc (append '((all .
"All package info")
3651 (unknown .
"Unknown keywords"))
3652 finder-known-keywords
))
3653 (let ((keyword (car assoc
)))
3654 (insert (format "* %s %s.\n"
3655 (concat (symbol-name keyword
) ": "
3656 "Keyword " (symbol-name keyword
) ".")
3658 ((equal nodename
"Keyword unknown")
3659 ;; Display unknown keywords
3660 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3661 Info-finder-file nodename
))
3662 (insert "Finder Unknown Keywords\n")
3663 (insert "***********************\n\n")
3664 (insert "* Menu:\n\n")
3667 (insert (format "* %-14s %s.\n"
3668 (concat (symbol-name (car assoc
)) ": "
3669 "Keyword " (symbol-name (car assoc
)) ".")
3671 (finder-unknown-keywords)))
3672 ((equal nodename
"Keyword all")
3673 ;; Display all package info.
3674 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3675 Info-finder-file nodename
))
3676 (insert "Finder Package Info\n")
3677 (insert "*******************\n\n")
3678 (insert "* Menu:\n\n")
3680 (dolist (package package--builtins
)
3681 (setq desc
(cdr-safe package
))
3682 (when (vectorp desc
)
3683 (insert (format "* %-16s %s.\n"
3684 (concat (symbol-name (car package
)) "::")
3686 ((string-match "\\`Keyword " nodename
)
3687 (setq nodename
(substring nodename
(match-end 0)))
3688 ;; Display packages that match the keyword
3689 ;; or the list of keywords separated by comma.
3690 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3691 Info-finder-file nodename
))
3692 (insert "Finder Packages\n")
3693 (insert "***************\n\n")
3695 "The following packages match the keyword `" nodename
"':\n\n")
3696 (insert "* Menu:\n\n")
3698 (mapcar 'intern
(if (string-match-p "," nodename
)
3699 (split-string nodename
",[ \t\n]*" t
)
3702 (dolist (keyword keywords
)
3703 (push (copy-tree (gethash keyword finder-keywords-hash
)) hits
))
3704 (setq hits
(delete-dups (apply 'append hits
)))
3705 (dolist (package hits
)
3706 (setq desc
(cdr-safe (assq package package--builtins
)))
3707 (when (vectorp desc
)
3708 (insert (format "* %-16s %s.\n"
3709 (concat (symbol-name package
) "::")
3712 ;; Display commentary section
3713 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3714 Info-finder-file nodename
))
3715 (insert "Finder Commentary\n")
3716 (insert "*****************\n\n")
3718 "Commentary section of the package `" nodename
"':\n\n")
3719 (let ((str (lm-commentary (find-library-name nodename
))))
3721 (insert "Can't find any Commentary section\n\n")
3725 (goto-char (point-min))
3726 (delete-blank-lines)
3727 (goto-char (point-max))
3728 (delete-blank-lines)
3729 (goto-char (point-min))
3730 (while (re-search-forward "^;+ ?" nil t
)
3731 (replace-match "" nil nil
))
3732 (buffer-string))))))))
3735 (defun info-finder (&optional keywords
)
3736 "Display descriptions of the keywords in the Finder virtual manual.
3737 In interactive use, a prefix argument directs this command to read
3738 a list of keywords separated by comma. After that, it displays a node
3739 with a list of packages that contain all specified keywords."
3741 (when current-prefix-arg
3744 (completing-read-multiple
3745 "Keywords (separated by comma): "
3746 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3747 (finder-unknown-keywords))))
3751 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3752 (Info-find-node Info-finder-file
"Top")))
3755 (defun Info-undefined ()
3756 "Make command be undefined in Info."
3761 "Enter the Info tutorial."
3763 (delete-other-windows)
3764 (Info-find-node "info"
3765 (if (< (window-height) 23)
3769 (defun Info-summary ()
3770 "Display a brief summary of all Info commands."
3772 (save-window-excursion
3773 (switch-to-buffer "*Help*")
3774 (setq buffer-read-only nil
)
3776 (insert (documentation 'Info-mode
))
3778 (goto-char (point-min))
3780 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3781 (message (if flag
"Type Space to see more"
3782 "Type Space to return to Info"))
3783 (if (not (eq ?\s
(setq ch
(read-event))))
3784 (progn (setq unread-command-events
(list ch
)) nil
)
3787 (bury-buffer "*Help*")))
3789 (defun Info-get-token (pos start all
&optional errorstring
)
3790 "Return the token around POS.
3791 POS must be somewhere inside the token.
3792 START is a regular expression which will match the
3793 beginning of the tokens delimited string.
3794 ALL is a regular expression with a single
3795 parenthesized subpattern which is the token to be
3796 returned. E.g. '{\(.*\)}' would return any string
3797 enclosed in braces around POS.
3798 ERRORSTRING optional fourth argument, controls action on no match:
3801 a string: signal an error, using that string."
3802 (let ((case-fold-search t
))
3805 ;; First look for a match for START that goes across POS.
3806 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3807 (not (looking-at start
)))
3809 ;; If we did not find one, search back for START
3810 ;; (this finds only matches that end at or before POS).
3811 (or (looking-at start
)
3814 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3816 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3817 (not (setq found
(and (<= (match-beginning 0) pos
)
3818 (> (match-end 0) pos
))))))
3819 (if (and found
(<= (match-beginning 0) pos
)
3820 (> (match-end 0) pos
))
3821 (match-string-no-properties 1)
3822 (cond ((null errorstring
)
3828 (error "No %s around position %d" errorstring pos
))))))))
3830 (defun Info-mouse-follow-nearest-node (click)
3831 "\\<Info-mode-map>Follow a node reference near point.
3832 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3833 At end of the node's text, moves to the next node, or up if none."
3835 (mouse-set-point click
)
3836 (and (not (Info-follow-nearest-node))
3837 (save-excursion (forward-line 1) (eobp))
3838 (Info-next-preorder)))
3840 (defun Info-follow-nearest-node (&optional fork
)
3841 "Follow a node reference near point.
3842 If point is on a reference, follow that reference. Otherwise,
3843 if point is in a menu item description, follow that menu item.
3845 If FORK is non-nil (interactively with a prefix arg), show the node in
3847 If FORK is a string, it is the name to use for the new buffer."
3849 (or (Info-try-follow-nearest-node fork
)
3850 (when (save-excursion
3851 (search-backward "\n* menu:" nil t
))
3854 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3855 (beginning-of-line 0))
3856 (when (looking-at "\\* +\\([^\t\n]*\\):")
3858 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3860 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3861 ;; Don't raise an error when mouse-1 is bound to this - it's
3862 ;; often used to simply select the window or frame.
3863 (eq 'mouse-1
(event-basic-type last-input-event
)))
3864 (user-error "Point neither on reference nor in menu item description")))
3866 ;; Common subroutine.
3867 (defun Info-try-follow-nearest-node (&optional fork
)
3868 "Follow a node reference near point. Return non-nil if successful.
3869 If FORK is non-nil, it is passed to `Info-goto-node'."
3872 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3873 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3876 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3877 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3878 (Info-follow-reference node fork
))
3880 ((setq node
(Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3881 (let ((old-point (point)) new-point
)
3883 (goto-char (point-min))
3884 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t
)
3885 (setq new-point
(if (< old-point
(point))
3886 ;; Go to footnote reference
3887 (and (search-forward node nil t
)
3888 ;; Put point at beginning of link
3889 (match-beginning 0))
3890 ;; Go to footnote definition
3891 (search-backward node nil t
)))))
3894 (goto-char new-point
)
3897 ;; menu item: node name
3898 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3899 (Info-goto-node node fork
))
3900 ;; menu item: node name or index entry
3901 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3904 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3905 (Info-goto-node node fork
))
3906 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3907 (Info-goto-node node fork
))
3908 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3909 (Info-goto-node node fork
))
3910 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3911 (Info-goto-node "Top" fork
))
3912 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3913 (Info-goto-node node fork
)))
3916 (defun Info-mouse-follow-link (click)
3917 "Follow a link where you click."
3919 (let* ((position (event-start click
))
3920 (posn-string (and position
(posn-string position
)))
3921 (link-args (if posn-string
3922 (get-text-property (cdr posn-string
)
3925 (get-char-property (posn-point position
)
3927 (cond ((stringp link-args
)
3928 (Info-goto-node link-args
))
3929 ;; These special values of the `link-args' property are used
3930 ;; for navigation; see `Info-fontify-node'.
3931 ((eq link-args
'prev
) (Info-prev))
3932 ((eq link-args
'next
) (Info-next))
3933 ((eq link-args
'up
) (Info-up)))))
3936 (defvar Info-mode-map
3937 (let ((map (make-keymap)))
3938 (suppress-keymap map
)
3939 (define-key map
"." 'beginning-of-buffer
)
3940 (define-key map
" " 'Info-scroll-up
)
3941 (define-key map
[?\S-\
] 'Info-scroll-down
)
3942 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3943 (define-key map
"\t" 'Info-next-reference
)
3944 (define-key map
"\e\t" 'Info-prev-reference
)
3945 (define-key map
[backtab] 'Info-prev-reference)
3946 (define-key map "1" 'Info-nth-menu-item)
3947 (define-key map "2" 'Info-nth-menu-item)
3948 (define-key map "3" 'Info-nth-menu-item)
3949 (define-key map "4" 'Info-nth-menu-item)
3950 (define-key map "5" 'Info-nth-menu-item)
3951 (define-key map "6" 'Info-nth-menu-item)
3952 (define-key map "7" 'Info-nth-menu-item)
3953 (define-key map "8" 'Info-nth-menu-item)
3954 (define-key map "9" 'Info-nth-menu-item)
3955 (define-key map "0" 'undefined)
3956 (define-key map "?" 'Info-summary)
3957 (define-key map "]" 'Info-forward-node)
3958 (define-key map "[" 'Info-backward-node)
3959 (define-key map "<" 'Info-top-node)
3960 (define-key map ">" 'Info-final-node)
3961 (define-key map "b" 'beginning-of-buffer)
3962 (put 'beginning-of-buffer :advertised-binding "b")
3963 (define-key map "d" 'Info-directory)
3964 (define-key map "e" 'end-of-buffer)
3965 (define-key map "f" 'Info-follow-reference)
3966 (define-key map "g" 'Info-goto-node)
3967 (define-key map "h" 'Info-help)
3968 (define-key map "i" 'Info-index)
3969 (define-key map "I" 'Info-virtual-index)
3970 (define-key map "l" 'Info-history-back)
3971 (define-key map "L" 'Info-history)
3972 (define-key map "m" 'Info-menu)
3973 (define-key map "n" 'Info-next)
3974 (define-key map "p" 'Info-prev)
3975 (define-key map "q" 'Info-exit)
3976 (define-key map "r" 'Info-history-forward)
3977 (define-key map "s" 'Info-search)
3978 (define-key map "S" 'Info-search-case-sensitively)
3979 (define-key map "\M-n" 'clone-buffer)
3980 (define-key map "t" 'Info-top-node)
3981 (define-key map "T" 'Info-toc)
3982 (define-key map "u" 'Info-up)
3983 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3984 (define-key map "w" 'Info-copy-current-node-name)
3985 (define-key map "c" 'Info-copy-current-node-name)
3986 ;; `^' for consistency with `dired-up-directory'.
3987 (define-key map "^" 'Info-up)
3988 (define-key map "," 'Info-index-next)
3989 (define-key map "\177" 'Info-scroll-down)
3990 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3991 (define-key map [follow-link] 'mouse-face)
3992 (define-key map [XF86Back] 'Info-history-back)
3993 (define-key map [XF86Forward] 'Info-history-forward)
3995 "Keymap containing Info commands.")
3998 (defun Info-check-pointer (item)
3999 "Non-nil if ITEM is present in this node."
4001 (Info-extract-pointer item)
4005 Info-mode-menu Info-mode-map
4006 "Menu for Info files."
4008 ["Up" Info-up :active (Info-check-pointer "up")
4009 :help "Go up in the Info tree"]
4010 ["Next" Info-next :active (Info-check-pointer "next")
4011 :help "Go to the next node"]
4012 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4013 :help "Go to the previous node"]
4014 ["Backward" Info-backward-node
4015 :help "Go backward one node, considering all as a sequence"]
4016 ["Forward" Info-forward-node
4017 :help "Go forward one node, considering all as a sequence"]
4018 ["Beginning" beginning-of-buffer
4019 :help "Go to beginning of this node"]
4020 ["Top" Info-top-node
4021 :help "Go to top node of file"]
4022 ["Final Node" Info-final-node
4023 :help "Go to final node in this file"]
4024 ("Menu Item" ["You should never see this" report-emacs-bug t])
4025 ("Reference" ["You should never see this" report-emacs-bug t])
4026 ["Search..." Info-search
4027 :help "Search for regular expression in this Info file"]
4028 ["Search Next" Info-search-next
4029 :help "Search for another occurrence of regular expression"]
4030 ["Go to Node..." Info-goto-node
4031 :help "Go to a named node"]
4032 ["Back in history" Info-history-back :active Info-history
4033 :help "Go back in history to the last node you were at"]
4034 ["Forward in history" Info-history-forward :active Info-history-forward
4035 :help "Go forward in history"]
4036 ["History" Info-history :active Info-history-list
4037 :help "Go to menu of visited nodes"]
4038 ["Table of Contents" Info-toc
4039 :help "Go to table of contents"]
4041 ["Lookup a String..." Info-index
4042 :help "Look for a string in the index items"]
4043 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4044 :help "Look for another occurrence of previous item"]
4045 ["Lookup a string and display index of results..." Info-virtual-index
4046 :help "Look for a string in the index items and display node with results"]
4047 ["Lookup a string in all indices..." info-apropos
4048 :help "Look for a string in the indices of all manuals"])
4049 ["Copy Node Name" Info-copy-current-node-name
4050 :help "Copy the name of the current node into the kill ring"]
4051 ["Clone Info buffer" clone-buffer
4052 :help "Create a twin copy of the current Info buffer."]
4053 ["Exit" Info-exit :help "Stop reading Info"]))
4056 (defvar info-tool-bar-map
4057 (let ((map (make-sparse-keymap)))
4058 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4062 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4066 (define-key-after map [separator-1] menu-bar-separator)
4067 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4069 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4071 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4073 (define-key-after map [separator-2] menu-bar-separator)
4074 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4076 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4077 (define-key-after map [separator-3] menu-bar-separator)
4078 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4080 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4082 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4086 (defvar Info-menu-last-node nil)
4087 ;; Last node the menu was created for.
4088 ;; Value is a list, (FILE-NAME NODE-NAME).
4090 (defun Info-menu-update ()
4091 "Update the Info menu for the current node."
4093 (if (or (not (derived-mode-p 'Info-mode))
4094 (equal (list Info-current-file Info-current-node)
4095 Info-menu-last-node))
4097 ;; Update menu menu.
4098 (let* ((Info-complete-menu-buffer (current-buffer))
4099 (items (nreverse (condition-case nil
4100 (Info-complete-menu-item "" nil t)
4104 (while (and items (< number 9))
4105 (setq current (car items)
4108 (setq entries (cons `[,current
4109 (Info-menu ,current)
4110 :keys ,(format "%d" number)]
4113 (setq entries (cons ["Other..." Info-menu t] entries)))
4115 (setq entries (list ["No menu" nil nil] nil :active)))
4116 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4117 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4119 str i entries current
4121 (case-fold-search t))
4123 (goto-char (point-min))
4124 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4125 (setq str (match-string 1))
4127 (while (setq i (string-match "[ \n\t]+" str i))
4128 (setq str (concat (substring str 0 i) " "
4129 (substring str (match-end 0))))
4133 (while (and items (< number 9))
4134 (setq current (car items)
4137 (setq entries (cons `[,current
4138 (Info-follow-reference ,current)
4142 (setq entries (cons ["Other..." Info-follow-reference t]
4145 (setq entries (list ["No references" nil nil] nil :active)))
4146 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4147 ;; Update last seen node.
4148 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4149 ;; Try to avoid entering infinite beep mode in case of errors.
4153 (defun Info-copy-current-node-name (&optional arg)
4154 "Put the name of the current Info node into the kill ring.
4155 The name of the Info file is prepended to the node name in parentheses.
4156 With a zero prefix arg, put the name inside a function call to `info'."
4158 (unless Info-current-node
4159 (user-error "No current Info node"))
4160 (let ((node (if (stringp Info-current-file)
4161 (concat "(" (file-name-sans-extension
4162 (file-name-nondirectory Info-current-file))
4164 Info-current-node))))
4165 (if (zerop (prefix-numeric-value arg))
4166 (setq node (concat "(info \"" node "\")")))
4167 (unless (stringp Info-current-file)
4168 (setq node (format "(Info-find-node '%S '%S)"
4169 Info-current-file Info-current-node)))
4171 (message "%s" node)))
4174 ;; Info mode is suitable only for specially formatted data.
4175 (put 'Info-mode 'mode-class 'special)
4176 (put 'Info-mode 'no-clone-indirect t)
4178 (defvar tool-bar-map)
4179 (defvar bookmark-make-record-function)
4181 (defvar Info-mode-syntax-table
4182 (let ((st (copy-syntax-table text-mode-syntax-table)))
4183 ;; Use punctuation syntax for apostrophe because of
4184 ;; extensive use of quotes like `this' in Info manuals.
4185 (modify-syntax-entry ?' "." st)
4187 "Syntax table used in `Info-mode'.")
4189 ;; Autoload cookie needed by desktop.el
4191 (define-derived-mode Info-mode nil "Info"
4192 "Info mode provides commands for browsing through the Info documentation tree.
4193 Documentation in Info is divided into \"nodes\", each of which discusses
4194 one topic and contains references to other nodes which discuss related
4195 topics. Info has commands to follow the references and show you other nodes.
4198 \\[Info-help] Invoke the Info tutorial.
4199 \\[Info-exit] Quit Info: reselect previously selected buffer.
4201 Selecting other nodes:
4202 \\[Info-mouse-follow-nearest-node]
4203 Follow a node reference you click on.
4204 This works with menu items, cross references, and
4205 the \"next\", \"previous\" and \"up\", depending on where you click.
4206 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4207 \\[Info-next] Move to the \"next\" node of this node.
4208 \\[Info-prev] Move to the \"previous\" node of this node.
4209 \\[Info-up] Move \"up\" from this node.
4210 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4211 Picking a menu item causes another node to be selected.
4212 \\[Info-directory] Go to the Info directory node.
4213 \\[Info-top-node] Go to the Top node of this file.
4214 \\[Info-final-node] Go to the final node in this file.
4215 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4216 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4217 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4218 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4219 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4220 \\[Info-history-back] Move back in history to the last node you were at.
4221 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4222 \\[Info-history] Go to menu of visited nodes.
4223 \\[Info-toc] Go to table of contents of the current Info file.
4225 Moving within a node:
4226 \\[Info-scroll-up] Normally, scroll forward a full screen.
4227 Once you scroll far enough in a node that its menu appears on the
4228 screen but after point, the next scroll moves into its first
4229 subnode. When after all menu items (or if there is no menu),
4230 move up to the parent node.
4231 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4232 already visible, try to go to the previous menu entry, or up
4234 \\[beginning-of-buffer] Go to beginning of node.
4237 \\[Info-search] Search through this Info file for specified regexp,
4238 and select the node in which the next occurrence is found.
4239 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4240 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4241 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4242 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4243 \\[Info-virtual-index] Look for a string and display the index node with results.
4244 \\[info-apropos] Look for a string in the indices of all manuals.
4245 \\[Info-goto-node] Move to node specified by name.
4246 You may include a filename as well, as (FILENAME)NODENAME.
4247 1 .. 9 Pick first ... ninth item in node's menu.
4248 Every third `*' is highlighted to help pick the right number.
4249 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4250 \\[clone-buffer] Select a new cloned Info buffer in another window.
4251 \\[universal-argument] \\[info] Move to new Info file with completion.
4252 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4253 :syntax-table Info-mode-syntax-table
4254 :abbrev-table text-mode-abbrev-table
4256 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4257 (setq case-fold-search t)
4258 (setq buffer-read-only t)
4259 (make-local-variable 'Info-current-file)
4260 (make-local-variable 'Info-current-subfile)
4261 (make-local-variable 'Info-current-node)
4262 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
4263 (set (make-local-variable 'Info-tag-table-buffer) nil)
4264 (make-local-variable 'Info-history)
4265 (make-local-variable 'Info-history-forward)
4266 (make-local-variable 'Info-index-alternatives)
4267 (if Info-use-header-line ; do not override global header lines
4268 (setq header-line-format
4269 '(:eval (get-text-property (point-min) 'header-line))))
4270 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4271 ;; This is for the sake of the invisible text we use handling titles.
4272 (set (make-local-variable 'line-move-ignore-invisible) t)
4273 (set (make-local-variable 'desktop-save-buffer)
4274 'Info-desktop-buffer-misc-data)
4275 (set (make-local-variable 'widen-automatically) nil)
4276 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4277 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4278 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4279 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4280 (set (make-local-variable 'isearch-search-fun-function)
4281 'Info-isearch-search)
4282 (set (make-local-variable 'isearch-wrap-function)
4284 (set (make-local-variable 'isearch-push-state-function)
4285 'Info-isearch-push-state)
4286 (set (make-local-variable 'isearch-filter-predicate) #'Info-isearch-filter)
4287 (set (make-local-variable 'revert-buffer-function)
4288 'Info-revert-buffer-function)
4289 (Info-set-mode-line)
4290 (set (make-local-variable 'bookmark-make-record-function)
4291 'Info-bookmark-make-record))
4293 ;; When an Info buffer is killed, make sure the associated tags buffer
4295 (defun Info-kill-buffer ()
4296 (and (derived-mode-p 'Info-mode)
4297 Info-tag-table-buffer
4298 (kill-buffer Info-tag-table-buffer)))
4300 ;; Placed on `clone-buffer-hook'.
4301 (defun Info-clone-buffer ()
4302 (when (bufferp Info-tag-table-buffer)
4303 (setq Info-tag-table-buffer
4304 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4305 (let ((m Info-tag-table-marker))
4307 (setq Info-tag-table-marker
4308 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4309 (with-current-buffer Info-tag-table-buffer
4310 (copy-marker (marker-position m)))
4313 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4314 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4315 (set-keymap-parent map text-mode-map)
4316 (define-key map "\C-c\C-c" 'Info-cease-edit)
4318 "Local keymap used within `e' command of Info.")
4320 (make-obsolete-variable 'Info-edit-map
4321 "editing Info nodes by hand is not recommended."
4324 ;; Info-edit mode is suitable only for specially formatted data.
4325 (put 'Info-edit-mode 'mode-class 'special)
4327 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4328 "Major mode for editing the contents of an Info node.
4329 Like text mode with the addition of `Info-cease-edit'
4330 which returns to Info mode for browsing.
4332 (setq buffer-read-only nil)
4333 (force-mode-line-update)
4334 (buffer-enable-undo (current-buffer)))
4336 (make-obsolete 'Info-edit-mode
4337 "editing Info nodes by hand is not recommended." "24.4")
4340 "Edit the contents of this Info node."
4343 (message "%s" (substitute-command-keys
4344 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4346 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4347 This feature will be removed in future.")
4349 (make-obsolete 'Info-edit
4350 "editing Info nodes by hand is not recommended." "24.4")
4352 (defun Info-cease-edit ()
4353 "Finish editing Info node; switch back to Info proper."
4355 ;; Do this first, so nothing has changed if user C-g's at query.
4356 (and (buffer-modified-p)
4357 (y-or-n-p "Save the file? ")
4360 (force-mode-line-update)
4361 (and (marker-position Info-tag-table-marker)
4363 (message "Tags may have changed. Use Info-tagify if necessary")))
4365 (make-obsolete 'Info-cease-edit
4366 "editing Info nodes by hand is not recommended." "24.4")
4368 (defvar Info-file-list-for-emacs
4369 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4370 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4371 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4372 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4373 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4374 ("copyright" . "autotype") ("executable" . "autotype")
4375 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4376 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4377 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4378 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4379 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4380 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4381 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4382 ("rfc2045" . "emacs-mime")
4383 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4384 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4385 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4386 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4387 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4388 ("mml" . "emacs-mime")
4390 "List of Info files that describe Emacs commands.
4391 An element can be a file name, or a list of the form (PREFIX . FILE)
4392 where PREFIX is a name prefix and FILE is the file to look in.
4393 If the element is just a file name, the file name also serves as the prefix.")
4395 (defun Info-find-emacs-command-nodes (command)
4396 "Return a list of locations documenting COMMAND.
4397 The `info-file' property of COMMAND says which Info manual to search.
4398 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4399 defines heuristics for which Info manual to try.
4400 The locations are of the format used in the variable `Info-history', i.e.
4401 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4402 in the first element of the returned list (which is treated specially in
4403 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4404 (let ((where '()) line-number
4405 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4406 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4407 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4408 (info-file "emacs")) ;default
4409 ;; Determine which Info file this command is documented in.
4410 (if (get command 'info-file)
4411 (setq info-file (get command 'info-file))
4412 ;; If it doesn't say explicitly, test its name against
4413 ;; various prefixes that we know.
4414 (let ((file-list Info-file-list-for-emacs))
4416 (let* ((elt (car file-list))
4417 (name (if (consp elt)
4420 (file (if (consp elt) (cdr elt) elt))
4421 (case-fold-search nil)
4422 (regexp (concat "\\`" (regexp-quote name)
4424 (if (string-match regexp (symbol-name command))
4425 (setq info-file file file-list nil))
4426 (setq file-list (cdr file-list))))))
4427 (Info-find-node info-file "Top")
4428 ;; Bind Info-history to nil, to prevent the index nodes from
4429 ;; getting into the node history.
4430 (let ((Info-history nil)
4431 (Info-history-list nil)
4432 node (nodes (Info-index-nodes)))
4433 (Info-goto-node (car nodes))
4436 (goto-char (point-min))
4437 (while (re-search-forward cmd-desc nil t)
4439 (cons (list Info-current-file
4440 (match-string-no-properties 2)
4443 (setq line-number (and (match-beginning 3)
4444 (string-to-number (match-string 3)))))
4445 (and (setq nodes (cdr nodes) node (car nodes))))
4446 (Info-goto-node node)))
4447 (if (and line-number where)
4448 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4452 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4454 (defun Info-goto-emacs-command-node (command)
4455 "Go to the Info node in the Emacs manual for command COMMAND.
4456 The command is found by looking up in Emacs manual's indices
4457 or in another manual found via COMMAND's `info-file' property or
4458 the variable `Info-file-list-for-emacs'.
4459 COMMAND must be a symbol or string."
4460 (interactive "CFind documentation for command: ")
4461 ;; If command is given as a string, convert it to a symbol.
4462 (if (stringp command)
4463 (setq command (intern command)))
4464 (or (commandp command)
4465 (signal 'wrong-type-argument (list 'commandp command)))
4466 (let ((where (Info-find-emacs-command-nodes command)))
4468 (let ((num-matches (length where)))
4469 ;; Get Info running, and pop to it in another window.
4470 (save-window-excursion
4472 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4473 ;; Bind Info-history to nil, to prevent the last Index node
4474 ;; visited by Info-find-emacs-command-nodes from being
4475 ;; pushed onto the history.
4476 (let ((Info-history nil) (Info-history-list nil)
4477 (line-number (nth 2 (car where))))
4478 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4479 (if (and (integerp line-number) (> line-number 0))
4480 (forward-line (1- line-number))))
4481 (if (> num-matches 1)
4483 ;; (car where) will be pushed onto Info-history
4484 ;; when/if they go to another node. Put the other
4485 ;; nodes that were found on the history.
4486 (setq Info-history (nconc (cdr where) Info-history))
4487 (message "Found %d other entr%s. Use %s to see %s."
4489 (if (> num-matches 2) "ies" "y")
4490 (substitute-command-keys "\\[Info-history-back]")
4491 (if (> num-matches 2) "them" "it")))))
4492 (error "Couldn't find documentation for %s" command))))
4494 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4496 (defun Info-goto-emacs-key-command-node (key)
4497 "Go to the node in the Emacs manual which describes the command bound to KEY.
4499 Interactively, if the binding is `execute-extended-command', a command is read.
4500 The command is found by looking up in Emacs manual's indices
4501 or in another manual found via COMMAND's `info-file' property or
4502 the variable `Info-file-list-for-emacs'."
4503 (interactive "kFind documentation for key: ")
4504 (let ((command (key-binding key)))
4505 (cond ((null command)
4506 (message "%s is undefined" (key-description key)))
4507 ((and (called-interactively-p 'interactive)
4508 (eq command 'execute-extended-command))
4509 (Info-goto-emacs-command-node
4510 (read-command "Find documentation for command: ")))
4512 (Info-goto-emacs-command-node command)))))
4514 (defvar Info-link-keymap
4515 (let ((keymap (make-sparse-keymap)))
4516 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4517 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4518 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4519 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4520 (define-key keymap [follow-link] 'mouse-face)
4522 "Keymap to put on Info links.
4523 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4524 first line or header line, and for breadcrumb links.")
4526 (defun Info-breadcrumbs ()
4527 (let ((nodes (Info-toc-nodes Info-current-file))
4528 (node Info-current-node)
4530 (depth Info-breadcrumbs-depth)
4533 ;; Get ancestors from the cached parent-children node info
4534 (while (and (not (equal "Top" node)) (> depth 0))
4535 (setq node (nth 1 (assoc node nodes)))
4536 (if node (push node crumbs))
4537 (setq depth (1- depth)))
4540 (when Info-use-header-line
4541 ;; Let it disappear if crumbs is nil.
4542 (nconc crumbs (list Info-current-node)))
4543 (when (or Info-use-header-line crumbs)
4544 ;; Add top node (and continuation if needed).
4546 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4547 crumbs (cons nil crumbs))))
4548 ;; Eliminate duplicate.
4550 (dolist (node crumbs)
4552 (if (not (equal node "Top")) node
4554 (if (stringp Info-current-file)
4555 (file-name-sans-extension
4556 (file-name-nondirectory Info-current-file))
4557 ;; Some legacy code can still use a symbol.
4558 Info-current-file)))))
4561 (if (null line) "" " > ")
4564 ((equal node Info-current-node)
4565 ;; No point linking to ourselves.
4566 (propertize text 'font-lock-face 'info-header-node))
4569 'mouse-face 'highlight
4570 'font-lock-face 'info-header-xref
4571 'help-echo "mouse-2: Go to node"
4572 'keymap Info-link-keymap
4573 'link-args text)))))))
4574 (setq line (concat line "\n")))
4575 ;; (font-lock-append-text-property 0 (length line)
4576 ;; 'font-lock-face 'header-line line)
4579 (defun Info-fontify-node ()
4582 (let* ((inhibit-read-only t)
4583 (case-fold-search t)
4585 (not-fontified-p ; the node hasn't already been fontified
4586 (not (let ((where (next-single-property-change (point-min)
4588 (and where (not (= where (point-max)))))))
4589 (fontify-visited-p ; visited nodes need to be re-fontified
4590 (and Info-fontify-visited-nodes
4591 ;; Don't take time to refontify visited nodes in huge nodes
4592 Info-fontify-maximum-menu-size
4593 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4596 ;; Fontify header line
4597 (goto-char (point-min))
4598 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4599 (goto-char (match-end 0))
4600 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4601 (goto-char (match-end 0))
4602 (let* ((nbeg (match-beginning 2))
4603 (nend (match-end 2))
4604 (tbeg (match-beginning 1))
4605 (tag (match-string 1)))
4606 (if (string-equal (downcase tag) "node")
4607 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4608 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4609 (put-text-property tbeg nend 'mouse-face 'highlight)
4610 (put-text-property tbeg nend
4612 (concat "mouse-2: Go to node "
4613 (buffer-substring nbeg nend)))
4614 ;; Set up the text property keymap. Depending on
4615 ;; `Info-use-header-line', it is either used in the
4616 ;; buffer, or copied to the header line. A symbol value
4617 ;; of the `link-args' property is handled specially by
4618 ;; `Info-mouse-follow-link'.
4619 (put-text-property tbeg nend 'keymap Info-link-keymap)
4620 (put-text-property tbeg nend 'link-args
4621 (intern (downcase tag))))))
4623 ;; (when (> Info-breadcrumbs-depth 0)
4624 ;; (insert (Info-breadcrumbs)))
4626 ;; Treat header line.
4627 (when Info-use-header-line
4628 (goto-char (point-min))
4629 (let* ((header-end (line-end-position))
4631 ;; If we find neither Next: nor Prev: link, show the entire
4632 ;; node header. Otherwise, don't show the File: and Node:
4633 ;; parts, to avoid wasting precious space on information that
4634 ;; is available in the mode line.
4635 (if (re-search-forward
4636 "\\(next\\|up\\|prev[ious]*\\): "
4639 (goto-char (match-beginning 1))
4640 (buffer-substring (point) header-end))
4641 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4643 (concat "No next, prev or up links -- "
4644 (buffer-substring (point) header-end))
4645 (buffer-substring (point) header-end)))))
4646 (put-text-property (point-min) (1+ (point-min))
4648 (replace-regexp-in-string
4650 ;; Preserve text properties on duplicated `%'.
4651 (lambda (s) (concat s s)) header))
4652 ;; Hide the part of the first line
4653 ;; that is in the header, if it is just part.
4655 ((> Info-breadcrumbs-depth 0)
4656 (let ((ov (make-overlay (point-min) (1+ header-end))))
4657 (overlay-put ov 'display (Info-breadcrumbs))
4658 (overlay-put ov 'evaporate t)))
4660 ;; Hide the punctuation at the end, too.
4661 (skip-chars-backward " \t,")
4662 (put-text-property (point) header-end 'invisible t)
4663 ;; Hide the suffix of the Info file name.
4665 (if (re-search-forward
4666 (format "File: %s\\([^,\n\t]+\\),"
4667 (if (stringp Info-current-file)
4668 (file-name-sans-extension
4669 (file-name-nondirectory Info-current-file))
4672 (put-text-property (match-beginning 1) (match-end 1)
4676 (goto-char (point-min))
4677 (when (and font-lock-mode not-fontified-p)
4678 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4680 ;; Only consider it as an underlined title if the ASCII
4681 ;; underline has the same size as the text. A typical
4682 ;; counter example is when a continuation "..." is alone
4684 (= (string-width (match-string 1))
4685 (string-width (match-string 2))))
4686 (let* ((c (preceding-char))
4688 (cond ((= c ?*) 'info-title-1)
4689 ((= c ?=) 'info-title-2)
4690 ((= c ?-) 'info-title-3)
4691 (t 'info-title-4))))
4692 (put-text-property (match-beginning 1) (match-end 1)
4693 'font-lock-face face))
4694 ;; This is a serious problem for trying to handle multiple
4695 ;; frame types at once. We want this text to be invisible
4696 ;; on frames that can display the font above.
4697 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4698 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4699 '(invisible t front-sticky nil rear-nonsticky t)))))
4701 ;; Fontify cross references
4702 (goto-char (point-min))
4703 (when (or not-fontified-p fontify-visited-p)
4704 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4705 (let ((start (match-beginning 0))
4708 (when not-fontified-p
4709 (when Info-hide-note-references
4710 (when (and (not (eq Info-hide-note-references 'hide))
4711 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4712 ;; *Note is often used where *note should have been
4714 (skip-syntax-backward " ")
4715 (when (memq (char-before) '(?\( ?\[ ?\{))
4716 ;; Check whether the paren is preceded by
4717 ;; an end of sentence
4718 (skip-syntax-backward " ("))
4720 (cond ((save-match-data (looking-back "\\<see"))
4722 ((save-match-data (looking-back "\\<in"))
4724 ((memq (char-before) '(nil ?\. ?! ??))
4728 (search-forward "\n\n" start t)))
4732 (add-text-properties
4734 (or (save-match-data
4735 ;; Don't hide \n after *Note
4736 (let ((start1 (match-beginning 1)))
4737 (if (string-match "\n" (match-string 1))
4738 (+ start1 (match-beginning 0)))))
4741 `(display ,other-tag front-sticky nil rear-nonsticky t)
4742 '(invisible t front-sticky nil rear-nonsticky t))))
4743 (add-text-properties
4744 (match-beginning 2) (match-end 2)
4746 'help-echo (if (or (match-end 5)
4747 (not (equal (match-string 4) "")))
4748 (concat "mouse-2: go to " (or (match-string 5)
4750 "mouse-2: go to this node")
4751 'mouse-face 'highlight)))
4752 (when (or not-fontified-p fontify-visited-p)
4753 (setq rbeg (match-beginning 2)
4758 ;; Display visited nodes in a different face
4759 (if (and Info-fontify-visited-nodes
4761 (let* ((node (replace-regexp-in-string
4763 (replace-regexp-in-string
4765 (or (match-string-no-properties 5)
4766 (and (not (equal (match-string 4) ""))
4767 (match-string-no-properties 4))
4768 (match-string-no-properties 2)))))
4770 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4771 (file (if external-link-p
4772 (file-name-nondirectory
4773 (match-string-no-properties 1 node))
4775 (hl Info-history-list)
4778 (setq node (if (equal (match-string 2 node) "")
4780 (match-string-no-properties 2 node))))
4782 (if (and (string-equal node (nth 1 (car hl)))
4784 (if (and external-link-p
4785 (stringp (caar hl)))
4786 (file-name-nondirectory
4789 (setq res (car hl) hl nil)
4790 (setq hl (cdr hl))))
4791 res))) 'info-xref-visited 'info-xref))
4792 ;; For multiline ref, unfontify newline and surrounding whitespace
4796 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4797 (remove-text-properties (match-beginning 0)
4799 '(font-lock-face t))))))
4800 (when not-fontified-p
4801 (when (memq Info-hide-note-references '(t hide))
4802 (add-text-properties (match-beginning 3) (match-end 3)
4803 '(invisible t front-sticky nil rear-nonsticky t))
4804 ;; Unhide the file name of the external reference in parens
4805 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4806 (remove-text-properties (match-beginning 6) (match-end 6)
4807 '(invisible t front-sticky nil rear-nonsticky t)))
4808 ;; Unhide newline because hidden newlines cause too long lines
4810 (let ((beg3 (match-beginning 3))
4811 (end3 (match-end 3)))
4812 (if (and (string-match "\n[ \t]*" (match-string 3))
4813 (not (save-match-data
4815 (goto-char (1+ end3))
4816 (looking-at "[.)]*$")))))
4817 (remove-text-properties (+ beg3 (match-beginning 0))
4818 (+ beg3 (match-end 0))
4819 '(invisible t front-sticky nil rear-nonsticky t))))))
4820 (when (and Info-refill-paragraphs Info-hide-note-references)
4821 (push (set-marker (make-marker) start)
4822 paragraph-markers))))))
4824 ;; Refill paragraphs (experimental feature)
4825 (when (and not-fontified-p
4826 Info-refill-paragraphs
4828 (let ((fill-nobreak-invisible t)
4829 (fill-individual-varying-indent nil)
4830 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4831 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4832 (adaptive-fill-mode nil))
4833 (goto-char (point-max))
4834 (dolist (m paragraph-markers)
4838 (let ((beg (point)))
4839 (when (zerop (forward-paragraph))
4840 (fill-individual-paragraphs beg (point) nil nil)
4842 (set-marker m nil))))
4844 ;; Fontify menu items
4845 (goto-char (point-min))
4846 (when (and (or not-fontified-p fontify-visited-p)
4847 (search-forward "\n* Menu:" nil t)
4848 ;; Don't take time to annotate huge menus
4849 Info-fontify-maximum-menu-size
4850 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4853 (while (re-search-forward
4854 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4855 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4857 (when (match-beginning 1)
4858 (when not-fontified-p
4860 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4861 (put-text-property (match-beginning 0)
4862 (1+ (match-beginning 0))
4863 'font-lock-face 'info-menu-star)))
4864 (when not-fontified-p
4865 (add-text-properties
4866 (match-beginning 1) (match-end 1)
4868 'help-echo (if (and (match-end 3)
4869 (not (equal (match-string 3) "")))
4870 (concat "mouse-2: go to " (match-string 3))
4871 "mouse-2: go to this node")
4872 'mouse-face 'highlight)))
4873 (when (or not-fontified-p fontify-visited-p)
4875 (match-beginning 1) (match-end 1)
4877 ;; Display visited menu items in a different face
4878 (if (and Info-fontify-visited-nodes
4880 (let* ((node (if (equal (match-string 3) "")
4881 (match-string-no-properties 1)
4882 (match-string-no-properties 3)))
4884 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4885 (file (if external-link-p
4886 (file-name-nondirectory
4887 (match-string-no-properties 1 node))
4889 (hl Info-history-list)
4892 (setq node (if (equal (match-string 2 node) "")
4894 (match-string-no-properties 2 node))))
4896 (if (and (string-equal node (nth 1 (car hl)))
4898 (if (and external-link-p
4899 (stringp (caar hl)))
4900 (file-name-nondirectory
4903 (setq res (car hl) hl nil)
4904 (setq hl (cdr hl))))
4905 res))) 'info-xref-visited 'info-xref)))
4906 (when (and not-fontified-p
4907 (memq Info-hide-note-references '(t hide))
4908 (not (Info-index-node)))
4909 (put-text-property (match-beginning 2) (1- (match-end 6))
4911 ;; Unhide the file name in parens
4912 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4913 (remove-text-properties (match-beginning 4) (match-end 4)
4915 ;; We need a stretchable space like :align-to but with
4917 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4918 (if (>= 22 (- (match-end 1)
4919 (match-beginning 0)))
4920 '(space :align-to 24)
4922 (setq cont (looking-at "."))
4923 (while (and (= (forward-line 1) 0)
4924 (looking-at "\\([ \t]+\\)[^*\n]"))
4925 (put-text-property (match-beginning 1) (1- (match-end 1))
4927 (put-text-property (1- (match-end 1)) (match-end 1)
4930 '(space :align-to 26)
4931 '(space :align-to 24)))
4934 ;; Fontify menu headers
4935 ;; Add the face `info-menu-header' to any header before a menu entry
4936 (goto-char (point-min))
4937 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4938 (put-text-property (match-beginning 0) (match-end 0)
4939 'font-lock-face 'info-menu-header)
4940 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4941 (put-text-property (match-beginning 1) (match-end 1)
4942 'font-lock-face 'info-menu-header)))
4944 ;; Hide index line numbers
4945 (goto-char (point-min))
4946 (when (and not-fontified-p (Info-index-node))
4947 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4948 (put-text-property (match-beginning 0) (match-end 0)
4951 ;; Fontify http and ftp references
4952 (goto-char (point-min))
4953 (when not-fontified-p
4954 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4956 (add-text-properties (match-beginning 0) (match-end 0)
4957 '(font-lock-face info-xref
4958 mouse-face highlight
4959 help-echo "mouse-2: go to this URL"))))
4961 ;; Fontify footnotes
4962 (goto-char (point-min))
4963 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
4964 (let ((limit (point)))
4965 (goto-char (point-min))
4966 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
4967 (add-text-properties (match-beginning 0) (match-end 0)
4968 `(font-lock-face info-xref
4970 mouse-face highlight
4972 ,(if (< (point) limit)
4973 "mouse-2: go to footnote definition"
4974 "mouse-2: go to footnote reference"))))))
4976 ;; Hide empty lines at the end of the node.
4977 (goto-char (point-max))
4978 (skip-chars-backward "\n")
4979 (when (< (point) (1- (point-max)))
4980 (put-text-property (point) (1- (point-max)) 'invisible t))
4982 (set-buffer-modified-p nil))))
4984 ;;; Speedbar support:
4985 ;; These functions permit speedbar to display the "tags" in the
4986 ;; current Info node.
4987 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
4989 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
4990 (declare-function speedbar-center-buffer-smartly "speedbar" ())
4991 (declare-function speedbar-change-expand-button-char "speedbar" (char))
4992 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
4993 (declare-function speedbar-delete-subblock "speedbar" (indent))
4994 (declare-function speedbar-make-specialized-keymap "speedbar" ())
4995 (declare-function speedbar-make-tag-line "speedbar"
4996 (exp-button-type exp-button-char exp-button-function
4997 exp-button-data tag-button tag-button-function
4998 tag-button-data tag-button-face depth))
5000 (defvar Info-speedbar-key-map nil
5001 "Keymap used when in the Info display mode.")
5003 (defun Info-install-speedbar-variables ()
5004 "Install those variables used by speedbar to enhance Info."
5005 (if Info-speedbar-key-map
5007 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5009 ;; Basic tree features
5010 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5011 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5012 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5013 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5016 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5017 Info-speedbar-key-map
5018 Info-speedbar-hierarchy-buttons)))
5020 (defvar Info-speedbar-menu-items
5021 '(["Browse Node" speedbar-edit-line t]
5022 ["Expand Node" speedbar-expand-line
5023 (save-excursion (beginning-of-line)
5024 (looking-at "[0-9]+: *.\\+. "))]
5025 ["Contract Node" speedbar-contract-line
5026 (save-excursion (beginning-of-line)
5027 (looking-at "[0-9]+: *.-. "))]
5029 "Additional menu-items to add to speedbar frame.")
5031 ;; Make sure our special speedbar major mode is loaded
5032 (if (featurep 'speedbar)
5033 (Info-install-speedbar-variables)
5034 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5036 ;;; Info hierarchy display method
5038 (defun Info-speedbar-browser ()
5039 "Initialize speedbar to display an Info node browser.
5040 This will add a speedbar major display mode."
5043 ;; Make sure that speedbar is active
5044 (speedbar-frame-mode 1)
5045 ;; Now, throw us into Info mode on speedbar.
5046 (speedbar-change-initial-expansion-list "Info")
5049 ;; speedbar loads dframe at runtime.
5050 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5051 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5053 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5054 "Display an Info directory hierarchy in speedbar.
5055 DIRECTORY is the current directory in the attached frame.
5056 DEPTH is the current indentation depth.
5057 NODE is an optional argument that is used to represent the
5058 specific node to expand."
5060 (save-excursion (goto-char (point-min))
5061 (let ((case-fold-search t))
5062 (looking-at "Info Nodes:"))))
5063 ;; Update our "current node" maybe?
5065 ;; We cannot use the generic list code, that depends on all leaves
5066 ;; being known at creation time.
5068 (speedbar-with-writable (insert "Info Nodes:\n")))
5069 (let ((completions nil))
5070 (speedbar-select-attached-frame)
5071 (save-window-excursion
5073 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5074 (select-frame (speedbar-current-frame))
5076 (speedbar-with-writable
5077 (dolist (completion completions)
5078 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5081 'Info-speedbar-goto-node
5087 (defun Info-speedbar-goto-node (_text node _indent)
5088 "When user clicks on TEXT, go to an info NODE.
5089 The INDENT level is ignored."
5090 (speedbar-select-attached-frame)
5091 (let* ((buff (or (get-buffer "*info*")
5092 (progn (info) (get-buffer "*info*"))))
5093 (bwin (get-buffer-window buff 0)))
5096 (select-window bwin)
5097 (raise-frame (window-frame bwin)))
5098 (if speedbar-power-click
5099 (switch-to-buffer-other-frame buff)
5100 (speedbar-select-attached-frame)
5101 (switch-to-buffer buff)))
5102 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5103 (error "Invalid node %s" node)
5104 (Info-find-node (match-string 1 node) (match-string 2 node))
5105 ;; If we do a find-node, and we were in info mode, restore
5106 ;; the old default method. Once we are in info mode, it makes
5107 ;; sense to return to whatever method the user was using before.
5108 (if (string= speedbar-initial-expansion-list-name "Info")
5109 (speedbar-change-initial-expansion-list
5110 speedbar-previously-used-expansion-list-name)))))
5112 (defun Info-speedbar-expand-node (text token indent)
5113 "Expand the node the user clicked on.
5114 TEXT is the text of the button we clicked on, a + or - item.
5115 TOKEN is data related to this node (NAME . FILE).
5116 INDENT is the current indentation depth."
5117 (cond ((string-match "+" text) ;we have to expand this file
5118 (speedbar-change-expand-button-char ?-)
5119 (if (speedbar-with-writable
5121 (end-of-line) (forward-char 1)
5122 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5123 (speedbar-change-expand-button-char ?-)
5124 (speedbar-change-expand-button-char ??)))
5125 ((string-match "-" text) ;we have to contract this node
5126 (speedbar-change-expand-button-char ?+)
5127 (speedbar-delete-subblock indent))
5128 (t (error "Ooops... not sure what to do")))
5129 (speedbar-center-buffer-smartly))
5131 (defun Info-speedbar-fetch-file-nodes (nodespec)
5132 "Fetch the subnodes from the info NODESPEC.
5133 NODESPEC is a string of the form: (file)node."
5134 ;; Set up a buffer we can use to fake-out Info.
5135 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5136 (if (not (derived-mode-p 'Info-mode))
5138 ;; Get the node into this buffer
5139 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5140 (error "Invalid node specification %s" nodespec)
5141 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5142 ;; Scan the created buffer
5143 (goto-char (point-min))
5144 (let ((completions nil)
5145 (case-fold-search t)
5146 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5147 (match-string 1 nodespec))))
5148 ;; Always skip the first one...
5149 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5150 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5151 (let ((name (match-string 1)))
5153 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5155 (if (looking-at " *\\(([^)]+)\\)\\.")
5156 (concat (match-string 1) "Top")
5157 (concat "(" thisfile ")"
5158 (if (looking-at " \\([^.]+\\).")
5162 (nreverse completions))))
5164 ;;; Info mode node listing
5165 ;; This is called by `speedbar-add-localized-speedbar-support'
5166 (defun Info-speedbar-buttons (_buffer)
5167 "Create a speedbar display to help navigation in an Info file.
5168 BUFFER is the buffer speedbar is requesting buttons for."
5169 (if (save-excursion (goto-char (point-min))
5170 (let ((case-fold-search t))
5171 (not (looking-at "Info Nodes:"))))
5173 (Info-speedbar-hierarchy-buttons nil 0))
5175 ;; FIXME: Really? Why here?
5176 (add-to-list 'debug-ignored-errors 'search-failed)
5178 ;;;; Desktop support
5180 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5181 "Auxiliary information to be saved in desktop file."
5182 (list Info-current-file
5184 ;; Additional data as an association list.
5187 (cons 'history Info-history))
5188 (and (Info-virtual-fun
5189 'slow Info-current-file Info-current-node)
5192 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5194 desktop-buffer-misc)
5195 "Restore an Info buffer specified in a desktop file."
5196 (let* ((file (nth 0 desktop-buffer-misc))
5197 (node (nth 1 desktop-buffer-misc))
5198 (data (nth 2 desktop-buffer-misc))
5199 (hist (assq 'history data))
5200 (slow (assq 'slow data)))
5201 ;; Don't restore nodes slow to regenerate.
5203 (when (and file node)
5204 (when desktop-buffer-name
5205 (set-buffer (get-buffer-create desktop-buffer-name))
5207 (Info-find-node file node)
5209 (setq Info-history (cdr hist)))
5210 (current-buffer)))))
5212 (add-to-list 'desktop-buffer-mode-handlers
5213 '(Info-mode . Info-restore-desktop-buffer))
5215 ;;;; Bookmark support
5216 (declare-function bookmark-make-record-default
5217 "bookmark" (&optional no-file no-context posn))
5218 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5219 (declare-function bookmark-default-handler "bookmark" (bmk))
5220 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5222 (defun Info-bookmark-make-record ()
5223 "This implements the `bookmark-make-record-function' type (which see)
5225 (let* ((file (and (stringp Info-current-file)
5226 (file-name-sans-extension
5227 (file-name-nondirectory Info-current-file))))
5228 (bookmark-name (if file
5229 (concat "(" file ") " Info-current-node)
5231 (defaults (delq nil (list bookmark-name file Info-current-node))))
5233 ,@(bookmark-make-record-default 'no-file)
5234 (filename . ,Info-current-file)
5235 (info-node . ,Info-current-node)
5236 (handler . Info-bookmark-jump)
5237 (defaults . ,defaults))))
5240 (defun Info-bookmark-jump (bmk)
5241 "This implements the `handler' function interface for the record
5242 type returned by `Info-bookmark-make-record', which see."
5243 (let* ((file (bookmark-prop-get bmk 'filename))
5244 (info-node (bookmark-prop-get bmk 'info-node))
5245 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5246 (Info-find-node file info-node) (current-buffer))))
5247 ;; Use bookmark-default-handler to move to the appropriate location
5249 (bookmark-default-handler
5250 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5254 (defun info-display-manual (manual)
5255 "Display an Info buffer displaying MANUAL.
5256 If there is an existing Info buffer for MANUAL, display it.
5257 Otherwise, visit the manual in a new Info buffer."
5262 (completing-read "Manual name: "
5263 (info--manual-names)
5265 (let ((blist (buffer-list))
5266 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5267 (case-fold-search t)
5269 (dolist (buffer blist)
5270 (with-current-buffer buffer
5271 (when (and (eq major-mode 'Info-mode)
5272 (stringp Info-current-file)
5273 (string-match manual-re Info-current-file))
5277 (switch-to-buffer found)
5279 (info (Info-find-file manual)
5280 (generate-new-buffer-name "*info*")))))
5282 (defun info--manual-names ()
5284 (dolist (buffer (buffer-list))
5285 (with-current-buffer buffer
5286 (and (eq major-mode 'Info-mode)
5287 (stringp Info-current-file)
5288 (not (string= (substring (buffer-name) 0 1) " "))
5289 (push (file-name-sans-extension
5290 (file-name-nondirectory Info-current-file))
5292 (delete-dups (append (nreverse names)
5295 (apply-partially 'Info-read-node-name-2
5297 (mapcar 'car Info-suffix-list)))))))
5301 ;;; info.el ends here