1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2011 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 ": ".
35 (eval-when-compile (require 'cl
))
43 (defvar Info-history nil
44 "Stack of Info nodes user has visited.
45 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
47 (defvar Info-history-forward nil
48 "Stack of Info nodes user has visited with `Info-history-back' command.
49 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
51 (defvar Info-history-list nil
52 "List of all Info nodes user has visited.
53 Each element of the list is a list (FILENAME NODENAME).")
55 (defcustom Info-history-skip-intermediate-nodes t
56 "Non-nil means don't record intermediate Info nodes to the history.
57 Intermediate Info nodes are nodes visited by Info internally in the process of
58 searching the node to display. Intermediate nodes are not presented
64 (defcustom Info-enable-edit nil
65 "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
66 This is convenient if you want to write Info files by hand.
67 However, we recommend that you not do this.
68 It is better to write a Texinfo file and generate the Info file from that,
69 because that gives you a printed manual as well."
73 (defvar Info-enable-active-nodes nil
74 "Non-nil allows Info to execute Lisp code associated with nodes.
75 The Lisp code is executed when the node is selected.")
76 (put 'Info-enable-active-nodes
'risky-local-variable t
)
79 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
80 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
81 (t :weight bold
:slant italic
))
82 "Face for Info node names."
86 '((((type tty pc
) (class color
) (background light
))
87 :foreground
"green" :weight bold
)
88 (((type tty pc
) (class color
) (background dark
))
89 :foreground
"yellow" :weight bold
)
90 (t :height
1.2 :inherit info-title-2
))
91 "Face for info titles at level 1."
93 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
96 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
97 (t :height
1.2 :inherit info-title-3
))
98 "Face for info titles at level 2."
100 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
102 (defface info-title-3
103 '((((type tty pc
) (class color
)) :weight bold
)
104 (t :height
1.2 :inherit info-title-4
))
105 "Face for info titles at level 3."
107 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
109 (defface info-title-4
110 '((((type tty pc
) (class color
)) :weight bold
)
111 (t :weight bold
:inherit variable-pitch
))
112 "Face for info titles at level 4."
114 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
116 (defface info-menu-header
121 :inherit variable-pitch
123 "Face for headers in Info menus."
126 (defface info-menu-star
127 '((((class color
)) :foreground
"red1")
129 "Face for every third `*' in an Info menu."
131 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
135 "Face for unvisited Info cross-references."
138 (defface info-xref-visited
139 '((t :inherit
(link-visited info-xref
)))
140 "Face for visited Info cross-references."
144 (defcustom Info-fontify-visited-nodes t
145 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
150 (defcustom Info-fontify-maximum-menu-size
100000
151 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
152 Set to nil to disable node fontification."
156 (defcustom Info-use-header-line t
157 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
158 A header-line does not scroll with the rest of the buffer."
162 (defface info-header-xref
163 '((t :inherit info-xref
))
164 "Face for Info cross-references in a node header."
167 (defface info-header-node
168 '((t :inherit info-node
))
169 "Face for Info nodes in a node header."
172 (defvar Info-directory-list nil
173 "List of directories to search for Info documentation files.
174 If nil, meaning not yet initialized, Info uses the environment
175 variable INFOPATH to initialize it, or `Info-default-directory-list'
176 if there is no INFOPATH variable in the environment, or the
177 concatenation of the two if INFOPATH ends with a `path-separator'.
179 When `Info-directory-list' is initialized from the value of
180 `Info-default-directory-list', and Emacs is installed in one of the
181 standard directories, the directory of Info files that come with Emacs
182 is put last (so that local Info files override standard ones).
184 When `Info-directory-list' is initialized from the value of
185 `Info-default-directory-list', and Emacs is not installed in one
186 of the standard directories, the first element of the resulting
187 list is the directory where Emacs installs the Info files that
188 come with it. This is so that Emacs's own manual, which suits the
189 version of Emacs you are using, will always be found first. This
190 is useful when you install an experimental version of Emacs without
191 removing the standard installation.
193 If you want to override the order of directories in
194 `Info-default-directory-list', set INFOPATH in the environment.
196 If you run the Emacs executable from the `src' directory in the Emacs
197 source tree, and INFOPATH is not defined, the `info' directory in the
198 source tree is used as the first element of `Info-directory-list', in
199 place of the installation Info directory. This is useful when you run
200 a version of Emacs without installing it.")
202 (defcustom Info-additional-directory-list nil
203 "List of additional directories to search for Info documentation files.
204 These directories are searched after those in `Info-directory-list'."
205 :type
'(repeat directory
)
208 (defcustom Info-scroll-prefer-subnodes nil
209 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
211 If this is non-nil, and you scroll far enough in a node that its menu
212 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
213 moves to a subnode indicated by the following menu item. This means
214 that you visit a subnode before getting to the end of the menu.
216 Setting this option to nil results in behavior similar to the stand-alone
217 Info reader program, which visits the first subnode from the menu only
218 when you hit the end of the current node."
223 (defcustom Info-hide-note-references t
224 "If non-nil, hide the tag and section reference in *note and * menu items.
225 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
226 If value is non-nil but not t or `hide', the reference section is still shown.
227 `nil' completely disables this feature. If this is non-nil, you might
228 want to set `Info-refill-paragraphs'."
230 :type
'(choice (const :tag
"No hiding" nil
)
231 (const :tag
"Replace tag and hide reference" t
)
232 (const :tag
"Hide tag and reference" hide
)
233 (other :tag
"Only replace tag" tag
))
236 (defcustom Info-refill-paragraphs nil
237 "If non-nil, attempt to refill paragraphs with hidden references.
238 This refilling may accidentally remove explicit line breaks in the Info
239 file, so be prepared for a few surprises if you enable this feature.
240 This only has an effect if `Info-hide-note-references' is non-nil."
245 (defcustom Info-breadcrumbs-depth
4
246 "Depth of breadcrumbs to display.
247 0 means do not display breadcrumbs."
252 (defcustom Info-search-whitespace-regexp
"\\s-+"
253 "If non-nil, regular expression to match a sequence of whitespace chars.
254 This applies to Info search for regular expressions.
255 You might want to use something like \"[ \\t\\r\\n]+\" instead.
256 In the Customization buffer, that is `[' followed by a space,
257 a tab, a carriage return (control-M), a newline, and `]+'."
261 (defcustom Info-isearch-search t
262 "If non-nil, isearch in Info searches through multiple nodes.
263 Before leaving the initial Info node, where isearch was started,
264 it fails once with the error message [initial node], and with
265 subsequent C-s/C-r continues through other nodes without failing
266 with this error message in other nodes. When isearch fails for
267 the rest of the manual, it wraps aroung the whole manual and
268 restarts the search from the top/final node depending on
271 Setting this option to nil restores the default isearch behavior
272 with wrapping around the current Info node."
277 (defvar Info-isearch-initial-node nil
)
278 (defvar Info-isearch-initial-history nil
)
279 (defvar Info-isearch-initial-history-list nil
)
281 (defcustom Info-mode-hook
282 ;; Try to obey obsolete Info-fontify settings.
283 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
284 '(turn-on-font-lock))
285 "Hooks run when `Info-mode' is called."
289 (defcustom Info-selection-hook nil
290 "Hooks run when `Info-select-node' is called."
294 (defvar Info-edit-mode-hook nil
295 "Hooks run when `Info-edit-mode' is called.")
297 (defvar Info-current-file nil
298 "Info file that Info is now looking at, or nil.
299 This is the name that was specified in Info, not the actual file name.
300 It doesn't contain directory names or file name extensions added by Info.")
302 (defvar Info-current-subfile nil
303 "Info subfile that is actually in the *info* buffer now.
304 It is nil if current Info file is not split into subfiles.")
306 (defvar Info-current-node nil
307 "Name of node that Info is now looking at, or nil.")
309 (defvar Info-tag-table-marker nil
310 "Marker pointing at beginning of current Info file's tag table.
311 Marker points nowhere if file has no tag table.")
313 (defvar Info-tag-table-buffer nil
314 "Buffer used for indirect tag tables.")
316 (defvar Info-current-file-completions nil
317 "Cached completion list for current Info file.")
319 (defvar Info-file-supports-index-cookies nil
320 "Non-nil if current Info file supports index cookies.")
322 (defvar Info-file-supports-index-cookies-list nil
323 "List of Info files with information about index cookies support.
324 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
325 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
327 (defvar Info-index-alternatives nil
328 "List of possible matches for last `Info-index' command.")
330 (defvar Info-point-loc nil
331 "Point location within a selected node.
332 If string, the point is moved to the proper occurrence of the
333 name of the followed cross reference within a selected node.
334 If number, the point is moved to the corresponding line.")
336 (defvar Info-standalone nil
337 "Non-nil if Emacs was started solely as an Info browser.")
339 (defvar Info-virtual-files nil
340 "List of definitions of virtual Info files.
341 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
342 where FILENAME is a regexp that matches a class of virtual Info file names.
343 It should be carefully chosen to not cause file name clashes with
344 existing file names. OPERATION is one of the following operation
345 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
346 function to call instead of calling the default corresponding function
349 (defvar Info-virtual-nodes nil
350 "List of definitions of virtual Info nodes.
351 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
352 where NODENAME is a regexp that matches a class of virtual Info node names.
353 It should be carefully chosen to not cause node name clashes with
354 existing node names. OPERATION is one of the following operation
355 symbols `find-node' that define what HANDLER function to call instead
356 of calling the default corresponding function to override it.")
358 (defvar Info-current-node-virtual nil
359 "Non-nil if the current Info node is virtual.")
361 (defun Info-virtual-file-p (filename)
362 "Check if Info file FILENAME is virtual."
363 (Info-virtual-fun 'find-file filename nil
))
365 (defun Info-virtual-fun (op filename nodename
)
366 "Find a function that handles operations on virtual manuals.
367 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
368 FILENAME is a virtual Info file name, NODENAME is a virtual Info
369 node name. Return a function found either in `Info-virtual-files'
370 or `Info-virtual-nodes'."
371 (or (and (stringp filename
) ; some legacy code can still use a symbol
372 (cdr-safe (assoc op
(assoc-default filename
375 (and (stringp nodename
) ; some legacy code can still use a symbol
376 (cdr-safe (assoc op
(assoc-default nodename
380 (defun Info-virtual-call (virtual-fun &rest args
)
381 "Call a function that handles operations on virtual manuals."
382 (when (functionp virtual-fun
)
383 (or (apply virtual-fun args
) t
)))
386 (defvar Info-suffix-list
387 ;; The MS-DOS list should work both when long file names are
388 ;; supported (Windows 9X), and when only 8+3 file names are available.
389 (if (eq system-type
'ms-dos
)
390 '( (".gz" .
"gunzip")
392 (".bz2" .
("bzip2" "-dc"))
395 (".info.Z" .
"gunzip")
396 (".info.gz" .
"gunzip")
397 ("-info.Z" .
"gunzip")
398 ("-info.gz" .
"gunzip")
399 ("/index.gz" .
"gunzip")
400 ("/index.z" .
"gunzip")
406 '( (".info.Z" .
"uncompress")
407 (".info.Y" .
"unyabba")
408 (".info.gz" .
"gunzip")
409 (".info.z" .
"gunzip")
410 (".info.bz2" .
("bzip2" "-dc"))
411 (".info.xz" .
"unxz")
413 ("-info.Z" .
"uncompress")
414 ("-info.Y" .
"unyabba")
415 ("-info.gz" .
"gunzip")
416 ("-info.bz2" .
("bzip2" "-dc"))
417 ("-info.z" .
"gunzip")
418 ("-info.xz" .
"unxz")
420 ("/index.Z" .
"uncompress")
421 ("/index.Y" .
"unyabba")
422 ("/index.gz" .
"gunzip")
423 ("/index.z" .
"gunzip")
424 ("/index.bz2" .
("bzip2" "-dc"))
425 ("/index.xz" .
"unxz")
427 (".Z" .
"uncompress")
431 (".bz2" .
("bzip2" "-dc"))
434 "List of file name suffixes and associated decoding commands.
435 Each entry should be (SUFFIX . STRING); the file is given to
436 the command as standard input.
438 STRING may be a list of strings. In that case, the first element is
439 the command name, and the rest are arguments to that command.
441 If STRING is nil, no decoding is done.
442 Because the SUFFIXes are tried in order, the empty string should
443 be last in the list.")
445 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
446 ;; First, on MS-DOS with no long file names support, delete some of
447 ;; the extension in FILENAME to make room.
448 (defun info-insert-file-contents-1 (filename suffix lfn
)
449 (if lfn
; long file names are supported
450 (concat filename suffix
)
451 (let* ((sans-exts (file-name-sans-extension filename
))
452 ;; How long is the extension in FILENAME (not counting the dot).
453 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
455 ;; SUFFIX starts with a dot. If FILENAME already has one,
456 ;; get rid of the one in SUFFIX (unless suffix is empty).
457 (or (and (<= ext-len
0)
458 (not (eq (aref filename
(1- (length filename
))) ?.
)))
459 (= (length suffix
) 0)
460 (setq suffix
(substring suffix
1)))
461 ;; How many chars of that extension should we keep?
462 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
463 ;; Get rid of the rest of the extension, and add SUFFIX.
464 (concat (substring filename
0 (- (length filename
)
465 (- ext-len ext-left
)))
468 (defun info-file-exists-p (filename)
469 (and (file-exists-p filename
)
470 (not (file-directory-p filename
))))
472 (defun info-insert-file-contents (filename &optional visit
)
473 "Insert the contents of an Info file in the current buffer.
474 Do the right thing if the file has been compressed or zipped."
475 (let* ((tail Info-suffix-list
)
476 (jka-compr-verbose nil
)
477 (lfn (if (fboundp 'msdos-long-file-names
)
478 (msdos-long-file-names)
480 (check-short (and (fboundp 'msdos-long-file-names
)
482 fullname decoder done
)
483 (if (info-file-exists-p filename
)
484 ;; FILENAME exists--see if that name contains a suffix.
485 ;; If so, set DECODE accordingly.
489 (concat (regexp-quote (car (car tail
))) "$")
491 (setq tail
(cdr tail
)))
492 (setq fullname filename
493 decoder
(cdr (car tail
))))
494 ;; Try adding suffixes to FILENAME and see if we can find something.
495 (while (and tail
(not done
))
496 (setq fullname
(info-insert-file-contents-1 filename
497 (car (car tail
)) lfn
))
498 (if (info-file-exists-p fullname
)
500 ;; If we found a file with a suffix, set DECODER
501 ;; according to the suffix.
502 decoder
(cdr (car tail
)))
503 ;; When the MS-DOS port runs on Windows, we need to check
504 ;; the short variant of a long file name as well.
506 (setq fullname
(info-insert-file-contents-1 filename
507 (car (car tail
)) nil
))
508 (if (info-file-exists-p fullname
)
510 decoder
(cdr (car tail
))))))
511 (setq tail
(cdr tail
)))
513 (error "Can't find %s or any compressed version of it" filename
)))
514 ;; check for conflict with jka-compr
515 (if (and (jka-compr-installed-p)
516 (jka-compr-get-compression-info fullname
))
520 (insert-file-contents-literally fullname visit
)
521 (let ((inhibit-read-only t
)
522 (coding-system-for-write 'no-conversion
)
523 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
524 (default-directory (or (file-name-directory fullname
)
527 (setq decoder
(list decoder
)))
528 (apply 'call-process-region
(point-min) (point-max)
529 (car decoder
) t t nil
(cdr decoder
))))
530 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
531 (insert-file-contents fullname visit
)))))
533 (defun Info-file-supports-index-cookies (&optional file
)
534 "Return non-nil value if FILE supports Info index cookies.
535 Info index cookies were first introduced in 4.7, and all later
536 makeinfo versions output them in index nodes, so we can rely
537 solely on the makeinfo version. This function caches the information
538 in `Info-file-supports-index-cookies-list'."
539 (or file
(setq file Info-current-file
))
540 (or (assoc file Info-file-supports-index-cookies-list
)
541 ;; Skip virtual Info files
542 (and (or (not (stringp file
))
543 (Info-virtual-file-p file
))
544 (setq Info-file-supports-index-cookies-list
545 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
548 (goto-char (point-min))
550 (if (and (re-search-forward
551 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
552 (line-beginning-position 4) t
)
553 (not (version< (match-string 1) "4.7")))
556 (setq Info-file-supports-index-cookies-list
557 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
558 (cdr (assoc file Info-file-supports-index-cookies-list
)))
561 (defun Info-default-dirs ()
562 (let ((source (expand-file-name "info/" source-directory
))
563 (sibling (if installation-directory
564 (expand-file-name "info/" installation-directory
)
565 (if invocation-directory
566 (let ((infodir (expand-file-name
568 invocation-directory
)))
569 (if (file-exists-p infodir
)
571 (setq infodir
(expand-file-name
572 "../../../share/info/"
573 invocation-directory
))
574 (and (file-exists-p infodir
)
578 (if (and sibling
(file-exists-p sibling
))
579 ;; Uninstalled, Emacs builddir != srcdir.
581 ;; Uninstalled, builddir == srcdir
583 (if (or (member alternative Info-default-directory-list
)
584 ;; On DOS/NT, we use movable executables always,
585 ;; and we must always find the Info dir at run time.
586 (if (memq system-type
'(ms-dos windows-nt
))
588 ;; Use invocation-directory for Info
589 ;; only if we used it for exec-directory also.
590 (not (string= exec-directory
591 (expand-file-name "lib-src/"
592 installation-directory
))))
593 (not (file-exists-p alternative
)))
594 Info-default-directory-list
595 ;; `alternative' contains the Info files that came with this
596 ;; version, so we should look there first. `Info-insert-dir'
597 ;; currently expects to find `alternative' first on the list.
599 ;; Don't drop the last part, it might contain non-Emacs stuff.
600 ;; (reverse (cdr (reverse
601 Info-default-directory-list
)))) ;; )))
603 (defun info-initialize ()
604 "Initialize `Info-directory-list', if that hasn't been done yet."
605 (unless Info-directory-list
606 (let ((path (getenv "INFOPATH"))
607 (sep (regexp-quote path-separator
)))
608 (setq Info-directory-list
609 (prune-directory-list
611 (if (string-match-p (concat sep
"\\'") path
)
612 (append (split-string (substring path
0 -
1) sep
)
614 (split-string path sep
))
615 (Info-default-dirs)))))))
618 (defun info-other-window (&optional file-or-node
)
619 "Like `info' but show the Info buffer in another window."
620 (interactive (if current-prefix-arg
621 (list (read-file-name "Info file name: " nil nil t
))))
622 (info-setup file-or-node
(switch-to-buffer-other-window "*info*")))
624 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
626 (defun info (&optional file-or-node buffer
)
627 "Enter Info, the documentation browser.
628 Optional argument FILE-OR-NODE specifies the file to examine;
629 the default is the top-level directory of Info.
630 Called from a program, FILE-OR-NODE may specify an Info node of the form
631 \"(FILENAME)NODENAME\".
632 Optional argument BUFFER specifies the Info buffer name;
633 the default buffer name is *info*. If BUFFER exists,
634 just switch to BUFFER. Otherwise, create a new buffer
635 with the top-level Info directory.
637 In interactive use, a non-numeric prefix argument directs
638 this command to read a file name from the minibuffer.
639 A numeric prefix argument selects an Info buffer with the prefix number
640 appended to the Info buffer name.
642 The search path for Info files is in the variable `Info-directory-list'.
643 The top-level Info directory is made by combining all the files named `dir'
644 in all the directories in that path.
646 See a list of available Info commands in `Info-mode'."
648 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
649 (read-file-name "Info file name: " nil nil t
))
650 (if (numberp current-prefix-arg
)
651 (format "*info*<%s>" current-prefix-arg
))))
652 (info-setup file-or-node
653 (pop-to-buffer-same-window (or buffer
"*info*"))))
655 (defun info-setup (file-or-node buffer
)
656 "Display Info node FILE-OR-NODE in BUFFER."
657 (if (and buffer
(not (eq major-mode
'Info-mode
)))
660 ;; If argument already contains parentheses, don't add another set
661 ;; since the argument will then be parsed improperly. This also
662 ;; has the added benefit of allowing node names to be included
663 ;; following the parenthesized filename.
665 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
667 (concat "(" file-or-node
")")))
668 (if (and (zerop (buffer-size))
670 ;; If we just created the Info buffer, go to the directory.
674 (defun info-emacs-manual ()
675 "Display the Emacs manual in Info mode."
680 (defun info-standalone ()
681 "Run Emacs as a standalone Info reader.
682 Usage: emacs -f info-standalone [filename]
683 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
684 (setq Info-standalone t
)
685 (if (and command-line-args-left
686 (not (string-match "^-" (car command-line-args-left
))))
689 (info (car command-line-args-left
))
690 (setq command-line-args-left
(cdr command-line-args-left
)))
691 (error (send-string-to-terminal
692 (format "%s\n" (if (eq (car-safe err
) 'error
)
694 (save-buffers-kill-emacs)))
697 ;; See if the accessible portion of the buffer begins with a node
698 ;; delimiter, and the node header line which follows matches REGEXP.
699 ;; Typically, this test will be followed by a loop that examines the
700 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
701 ;; to have the overhead of this special test inside the loop.
703 ;; This function changes match-data, but supposedly the caller might
704 ;; want to use the results of re-search-backward.
706 ;; The return value is the value of point at the beginning of matching
707 ;; REGEXP, if the function succeeds, nil otherwise.
708 (defun Info-node-at-bob-matching (regexp)
709 (and (bobp) ; are we at beginning of buffer?
710 (looking-at "\^_") ; does it begin with node delimiter?
714 (forward-line 1) ; does the line after delimiter match REGEXP?
715 (re-search-backward regexp beg t
))))
717 (defun Info-find-file (filename &optional noerror
)
718 "Return expanded FILENAME, or t if FILENAME is \"dir\".
719 Optional second argument NOERROR, if t, means if file is not found
720 just return nil (no error)."
721 ;; Convert filename to lower case if not found as specified.
725 (Info-virtual-fun 'find-file filename nil
)
728 (let (temp temp-downcase found
)
729 (setq filename
(substitute-in-file-name filename
))
730 (let ((dirs (if (string-match "^\\./" filename
)
731 ;; If specified name starts with `./'
732 ;; then just try current directory.
734 (if (file-name-absolute-p filename
)
735 ;; No point in searching for an
736 ;; absolute file name
738 (if Info-additional-directory-list
739 (append Info-directory-list
740 Info-additional-directory-list
)
741 Info-directory-list
)))))
742 ;; Fall back on the installation directory if we can't find
743 ;; the info node anywhere else.
744 (when installation-directory
745 (setq dirs
(append dirs
(list (expand-file-name
746 "info" installation-directory
)))))
747 ;; Search the directory list for file FILENAME.
748 (while (and dirs
(not found
))
749 (setq temp
(expand-file-name filename
(car dirs
)))
751 (expand-file-name (downcase filename
) (car dirs
)))
752 ;; Try several variants of specified name.
753 (let ((suffix-list Info-suffix-list
)
754 (lfn (if (fboundp 'msdos-long-file-names
)
755 (msdos-long-file-names)
757 (while (and suffix-list
(not found
))
758 (cond ((info-file-exists-p
759 (info-insert-file-contents-1
760 temp
(car (car suffix-list
)) lfn
))
763 (info-insert-file-contents-1
764 temp-downcase
(car (car suffix-list
)) lfn
))
765 (setq found temp-downcase
))
766 ((and (fboundp 'msdos-long-file-names
)
769 (info-insert-file-contents-1
770 temp
(car (car suffix-list
)) nil
)))
772 (setq suffix-list
(cdr suffix-list
))))
773 (setq dirs
(cdr dirs
))))
775 (setq filename found
)
778 (error "Info file %s does not exist" filename
)))
781 (defun Info-find-node (filename nodename
&optional no-going-back
)
782 "Go to an Info node specified as separate FILENAME and NODENAME.
783 NO-GOING-BACK is non-nil if recovering from an error in this function;
784 it says do not attempt further (recursive) error recovery."
786 (setq filename
(Info-find-file filename
))
787 ;; Go into Info buffer.
788 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
789 ;; Record the node we are leaving, if we were in one.
790 (and (not no-going-back
)
792 (push (list Info-current-file Info-current-node
(point))
794 (Info-find-node-2 filename nodename no-going-back
))
797 (defun Info-on-current-buffer (&optional nodename
)
798 "Use Info mode to browse the current Info buffer.
799 With a prefix arg, this queries for the node name to visit first;
800 otherwise, that defaults to `Top'."
802 (list (if current-prefix-arg
803 (completing-read "Node name: " (Info-build-node-completions)
805 (unless nodename
(setq nodename
"Top"))
808 (set (make-local-variable 'Info-current-file
)
810 ;; If called on a non-file buffer, make a fake file name.
811 (concat default-directory
(buffer-name))))
812 (Info-find-node-2 nil nodename
))
814 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
815 ;; but at least it keeps this routine (which is for makeinfo-buffer and
816 ;; Info-revert-buffer-function) out of the way of normal operations.
818 (defun Info-revert-find-node (filename nodename
)
819 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
820 When *info* is already displaying FILENAME and NODENAME, the window position
821 is preserved, if possible."
822 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
823 (let ((old-filename Info-current-file
)
824 (old-nodename Info-current-node
)
825 (old-buffer-name (buffer-name))
826 (pcolumn (current-column))
827 (pline (count-lines (point-min) (line-beginning-position)))
828 (wline (count-lines (point-min) (window-start)))
829 (old-history-forward Info-history-forward
)
830 (old-history Info-history
)
831 (new-history (and Info-current-file
832 (list Info-current-file Info-current-node
(point)))))
833 (kill-buffer (current-buffer))
834 (switch-to-buffer (or old-buffer-name
"*info*"))
836 (Info-find-node filename nodename
)
837 (setq Info-history-forward old-history-forward
)
838 (setq Info-history old-history
)
839 (if (and (equal old-filename Info-current-file
)
840 (equal old-nodename Info-current-node
))
842 ;; note goto-line is no good, we want to measure from point-min
843 (goto-char (point-min))
845 (set-window-start (selected-window) (point))
846 (goto-char (point-min))
848 (move-to-column pcolumn
))
849 ;; only add to the history when coming from a different file+node
851 (setq Info-history
(cons new-history Info-history
))))))
853 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
854 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
855 (Info-revert-find-node Info-current-file Info-current-node
)
856 (message "Reverted %s" Info-current-file
)))
858 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
859 "Find a node in a tag table.
860 MARKER specifies the buffer and position to start searching at.
861 REGEXP is a regular expression matching nodes or references. Its first
862 group should match `Node:' or `Ref:'.
863 CASE-FOLD t means search for a case-insensitive match.
864 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
865 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
866 where the match was found, and MODE is `major-mode' of the buffer in
867 which the match was found."
868 (let ((case-fold-search case-fold
))
869 (with-current-buffer (marker-buffer marker
)
874 (when (re-search-forward regexp nil t
)
875 (list (string-equal "Ref:" (match-string 1))
876 (+ (point-min) (read (current-buffer)))
879 (defun Info-find-in-tag-table (marker regexp
)
880 "Find a node in a tag table.
881 MARKER specifies the buffer and position to start searching at.
882 REGEXP is a regular expression matching nodes or references. Its first
883 group should match `Node:' or `Ref:'.
884 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
885 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
886 where the match was found, and MODE is `major-mode' of the buffer in
887 which the match was found.
888 This function tries to find a case-sensitive match first, then a
889 case-insensitive match is tried."
890 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
891 (when (null (car result
))
892 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
895 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
896 "Find a node or anchor in the current buffer.
897 REGEXP is a regular expression matching nodes or references. Its first
898 group should match `Node:' or `Ref:'.
899 CASE-FOLD t means search for a case-insensitive match.
900 Value is the position at which a match was found, or nil if not found."
901 (let ((case-fold-search case-fold
)
904 (if (Info-node-at-bob-matching regexp
)
906 (while (and (not found
)
907 (search-forward "\n\^_" nil t
))
911 (if (re-search-backward regexp beg t
)
912 (setq found
(line-beginning-position)))))))
915 (defun Info-find-node-in-buffer (regexp)
916 "Find a node or anchor in the current buffer.
917 REGEXP is a regular expression matching nodes or references. Its first
918 group should match `Node:' or `Ref:'.
919 Value is the position at which a match was found, or nil if not found.
920 This function looks for a case-sensitive match first. If none is found,
921 a case-insensitive match is tried."
922 (or (Info-find-node-in-buffer-1 regexp nil
)
923 (Info-find-node-in-buffer-1 regexp t
)))
925 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
926 (buffer-disable-undo (current-buffer))
927 (or (eq major-mode
'Info-mode
)
930 (setq Info-current-node nil
)
932 (let ((case-fold-search t
)
933 (virtual-fun (Info-virtual-fun 'find-node
934 (or filename Info-current-file
)
938 ((functionp virtual-fun
)
939 (let ((filename (or filename Info-current-file
)))
940 (setq buffer-read-only nil
)
941 (setq Info-current-file filename
942 Info-current-subfile nil
943 Info-current-file-completions nil
944 buffer-file-name nil
)
946 (Info-virtual-call virtual-fun filename nodename no-going-back
)
947 (set-marker Info-tag-table-marker nil
)
948 (setq buffer-read-only t
)
949 (set-buffer-modified-p nil
)
950 (set (make-local-variable 'Info-current-node-virtual
) t
)))
952 ;; Reread a file when moving from a virtual node.
953 (not Info-current-node-virtual
)
955 (equal Info-current-file filename
))))
956 ;; Switch files if necessary
957 (let ((inhibit-read-only t
))
958 (when Info-current-node-virtual
959 ;; When moving from a virtual node.
960 (set (make-local-variable 'Info-current-node-virtual
) nil
)
962 (setq filename Info-current-file
)))
963 (setq Info-current-file nil
964 Info-current-subfile nil
965 Info-current-file-completions nil
966 buffer-file-name nil
)
968 (info-insert-file-contents filename nil
)
969 (setq default-directory
(file-name-directory filename
))
970 (set-buffer-modified-p nil
)
971 (set (make-local-variable 'Info-file-supports-index-cookies
)
972 (Info-file-supports-index-cookies filename
))
974 ;; See whether file has a tag table. Record the location if yes.
975 (goto-char (point-max))
977 ;; Use string-equal, not equal, to ignore text props.
978 (if (not (or (string-equal nodename
"*")
980 (search-forward "\^_\nEnd tag table\n" nil t
))))
982 ;; We have a tag table. Find its beginning.
983 ;; Is this an indirect file?
984 (search-backward "\nTag table:\n")
988 (looking-at "(Indirect)\n"))
989 ;; It is indirect. Copy it to another buffer
990 ;; and record that the tag table is in that buffer.
991 (let ((buf (current-buffer))
993 (or Info-tag-table-buffer
994 (generate-new-buffer " *info tag table*"))))
995 (setq Info-tag-table-buffer tagbuf
)
996 (with-current-buffer tagbuf
997 (buffer-disable-undo (current-buffer))
998 (setq case-fold-search t
)
1000 (insert-buffer-substring buf
))
1001 (set-marker Info-tag-table-marker
1002 (match-end 0) tagbuf
))
1003 (set-marker Info-tag-table-marker pos
)))
1004 (set-marker Info-tag-table-marker nil
))
1005 (setq Info-current-file filename
)
1008 ;; Use string-equal, not equal, to ignore text props.
1009 (if (string-equal nodename
"*")
1010 (progn (setq Info-current-node nodename
)
1011 (Info-set-mode-line))
1014 ;; 1. Anchor found in tag table
1015 ;; 2. Anchor *not* in tag table
1017 ;; 3. Node found in tag table
1018 ;; 4. Node *not* found in tag table, but found in file
1019 ;; 5. Node *not* in tag table, and *not* in file
1021 ;; *Or* the same, but in an indirect subfile.
1023 ;; Search file for a suitable node.
1024 (let ((guesspos (point-min))
1025 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1026 (if (stringp nodename
)
1027 (regexp-quote nodename
)
1029 "\\) *[,\t\n\177]")))
1033 ;; First, search a tag table, if any
1034 (when (marker-position Info-tag-table-marker
)
1035 (let* ((m Info-tag-table-marker
)
1036 (found (Info-find-in-tag-table m regexp
)))
1039 ;; FOUND is (ANCHOR POS MODE).
1040 (setq guesspos
(nth 1 found
))
1042 ;; If this is an indirect file, determine which
1043 ;; file really holds this node and read it in.
1044 (unless (eq (nth 2 found
) 'Info-mode
)
1045 ;; Note that the current buffer must be the
1046 ;; *info* buffer on entry to
1047 ;; Info-read-subfile. Thus the hackery above.
1048 (setq guesspos
(Info-read-subfile guesspos
)))
1052 (goto-char (setq anchorpos guesspos
))
1055 ;; Else we may have a node, which we search for:
1056 (goto-char (max (point-min)
1057 (- (byte-to-position guesspos
) 1000)))
1059 ;; Now search from our advised position (or from beg of
1060 ;; buffer) to find the actual node. First, check
1061 ;; whether the node is right where we are, in case the
1062 ;; buffer begins with a node.
1063 (let ((pos (Info-find-node-in-buffer regexp
)))
1068 (when (string-match "\\([^.]+\\)\\." nodename
)
1069 (let (Info-point-loc)
1071 filename
(match-string 1 nodename
) no-going-back
))
1075 ;; No such anchor in tag table or node in tag table or file
1076 (error "No such node or anchor: %s" nodename
))
1079 (goto-char (point-min))
1080 (forward-line 1) ; skip header line
1081 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1082 ;; (forward-line 1))
1085 (let ((new-history (list Info-current-file
1086 (substring-no-properties nodename
))))
1087 ;; Add anchors to the history too
1088 (setq Info-history-list
1090 (delete new-history Info-history-list
))))
1091 (goto-char anchorpos
))
1092 ((numberp Info-point-loc
)
1093 (forward-line (- Info-point-loc
2))
1094 (setq Info-point-loc nil
))
1095 ((stringp Info-point-loc
)
1096 (Info-find-index-name Info-point-loc
)
1097 (setq Info-point-loc nil
))))))
1098 ;; If we did not finish finding the specified node,
1099 ;; go back to the previous one.
1100 (or Info-current-node no-going-back
(null Info-history
)
1101 (let ((hist (car Info-history
)))
1102 (setq Info-history
(cdr Info-history
))
1103 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1104 (goto-char (nth 2 hist
))))))
1106 ;; Cache the contents of the (virtual) dir file, once we have merged
1107 ;; it for the first time, so we can save time subsequently.
1108 (defvar Info-dir-contents nil
)
1110 ;; Cache for the directory we decided to use for the default-directory
1111 ;; of the merged dir text.
1112 (defvar Info-dir-contents-directory nil
)
1114 ;; Record the file attributes of all the files from which we
1115 ;; constructed Info-dir-contents.
1116 (defvar Info-dir-file-attributes nil
)
1118 (defvar Info-dir-file-name nil
)
1120 ;; Construct the Info directory node by merging the files named `dir'
1121 ;; from various directories. Set the *info* buffer's
1122 ;; default-directory to the first directory we actually get any text
1124 (defun Info-insert-dir ()
1125 (if (and Info-dir-contents Info-dir-file-attributes
1126 ;; Verify that none of the files we used has changed
1127 ;; since we used it.
1129 (mapcar (lambda (elt)
1130 (let ((curr (file-attributes
1132 (file-truename (car elt
)))))
1134 ;; Don't compare the access time.
1135 (if curr
(setcar (nthcdr 4 curr
) 0))
1136 (setcar (nthcdr 4 (cdr elt
)) 0)
1137 (equal (cdr elt
) curr
)))
1138 Info-dir-file-attributes
))))
1140 (insert Info-dir-contents
)
1141 (goto-char (point-min)))
1142 (let ((dirs (if Info-additional-directory-list
1143 (append Info-directory-list
1144 Info-additional-directory-list
)
1145 Info-directory-list
))
1146 (dir-file-attrs nil
)
1147 ;; Bind this in case the user sets it to nil.
1148 (case-fold-search t
)
1149 ;; This is set non-nil if we find a problem in some input files.
1151 buffers buffer others nodes dirs-done
)
1153 ;; Search the directory list for the directory file.
1155 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1156 (or (member truename dirs-done
)
1157 (member (directory-file-name truename
) dirs-done
)
1158 ;; Try several variants of specified name.
1159 ;; Try upcasing, appending `.info', or both.
1163 (progn (setq file
(expand-file-name "dir" truename
))
1164 (file-attributes file
))
1165 (progn (setq file
(expand-file-name "DIR" truename
))
1166 (file-attributes file
))
1167 (progn (setq file
(expand-file-name "dir.info" truename
))
1168 (file-attributes file
))
1169 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1170 (file-attributes file
)))))
1173 (cons (directory-file-name truename
)
1176 (with-current-buffer (generate-new-buffer " info dir")
1178 (message "Composing main Info directory..."))
1180 ;; Index nodes include null bytes. DIR
1181 ;; files should not have indices, but who
1183 (let ((inhibit-null-byte-detection t
))
1184 (insert-file-contents file
)
1185 (set (make-local-variable 'Info-dir-file-name
)
1187 (push (current-buffer) buffers
)
1188 (push (cons file attrs
) dir-file-attrs
))
1189 (error (kill-buffer (current-buffer))))))))
1191 (set (make-local-variable 'Info-dir-contents-directory
)
1192 (file-name-as-directory (car dirs
))))
1193 (setq dirs
(cdr dirs
))))
1196 (error "Can't find the Info directory node"))
1198 ;; Distinguish the dir file that comes with Emacs from all the
1199 ;; others. Yes, that is really what this is supposed to do.
1200 ;; The definition of `Info-directory-list' puts it first on that
1201 ;; list and so last in `buffers' at this point.
1202 (setq buffer
(car (last buffers
))
1203 others
(delq buffer buffers
))
1205 ;; Insert the entire original dir file as a start; note that we've
1206 ;; already saved its default directory to use as the default
1207 ;; directory for the whole concatenation.
1208 (save-excursion (insert-buffer-substring buffer
))
1210 ;; Look at each of the other buffers one by one.
1211 (dolist (other others
)
1212 (let (this-buffer-nodes)
1213 ;; In each, find all the menus.
1214 (with-current-buffer other
1215 (goto-char (point-min))
1216 ;; Find each menu, and add an elt to NODES for it.
1217 (while (re-search-forward "^\\* Menu:" nil t
)
1218 (while (and (zerop (forward-line 1)) (eolp)))
1221 (re-search-backward "^\^_")
1222 (search-forward "Node: ")
1223 (setq nodename
(Info-following-node-name))
1224 (search-forward "\n\^_" nil
'move
)
1227 (push (list nodename other beg end
) this-buffer-nodes
)))
1228 (if (assoc-string "top" this-buffer-nodes t
)
1229 (setq nodes
(nconc this-buffer-nodes nodes
))
1231 (message "No `top' node in %s" Info-dir-file-name
)))))
1232 ;; Add to the main menu a menu item for each other node.
1233 (re-search-forward "^\\* Menu:")
1235 (let ((menu-items '("top"))
1236 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1237 (dolist (node nodes
)
1238 (let ((nodename (car node
)))
1240 (or (member (downcase nodename
) menu-items
)
1241 (re-search-forward (concat "^\\* +"
1242 (regexp-quote nodename
)
1246 (insert "* " nodename
"::" "\n")
1247 (push nodename menu-items
)))))))
1248 ;; Now take each node of each of the other buffers
1249 ;; and merge it into the main buffer.
1250 (dolist (node nodes
)
1251 (let ((case-fold-search t
)
1252 (nodename (car node
)))
1253 (goto-char (point-min))
1254 ;; Find the like-named node in the main buffer.
1255 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1256 (regexp-quote nodename
)
1260 (search-forward "\n\^_" nil
'move
)
1263 ;; If none exists, add one.
1264 (goto-char (point-max))
1265 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1266 ;; Merge the text from the other buffer's menu
1267 ;; into the menu in the like-named node in the main buffer.
1268 (apply 'insert-buffer-substring
(cdr node
))))
1269 (Info-dir-remove-duplicates)
1270 ;; Kill all the buffers we just made, including the special one excised.
1271 (mapc 'kill-buffer
(cons buffer buffers
))
1272 (goto-char (point-min))
1274 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1275 (message "Composing main Info directory...done"))
1276 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1277 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1278 (setq default-directory Info-dir-contents-directory
))
1280 (defvar Info-streamline-headings
1281 '(("Emacs" .
"Emacs")
1282 ("Programming" .
"Programming")
1283 ("Libraries" .
"Libraries")
1284 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1285 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1287 (defun Info-dir-remove-duplicates ()
1289 (goto-char (point-min))
1290 ;; Remove duplicate headings in the same menu.
1291 (while (search-forward "\n* Menu:" nil t
)
1292 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1293 ;; Look for the next heading to unify.
1294 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1295 (let ((name (match-string 1))
1296 (start (match-beginning 0))
1298 ;; Check whether this heading should be streamlined.
1300 (dolist (x Info-streamline-headings
)
1301 (when (string-match (car x
) name
)
1303 (setq re
(car x
)))))
1304 (if re
(replace-match name t t nil
1))
1305 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1307 (or limit
(point-max))))
1308 ;; Look for other headings of the same category and merge them.
1310 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1311 (when (if re
(save-match-data (string-match re
(match-string 1)))
1312 (equal name
(match-string 1)))
1314 ;; Delete redundant heading.
1315 (delete-region (match-beginning 0) (point))
1316 ;; Push the entries onto `text'.
1318 (delete-and-extract-region
1320 (if (re-search-forward "^[^* \n\t]" nil t
)
1322 (or limit
(point-max))))
1325 ;; Insert the entries just found.
1326 (while (= (line-beginning-position 0) (1- (point)))
1328 (dolist (entry (nreverse entries
))
1330 (while (= (line-beginning-position 0) (1- (point)))
1331 (delete-region (1- (point)) (point))))
1333 ;; Now remove duplicate entries under the same heading.
1336 (narrow-to-region start
(point))
1337 (goto-char (point-min))
1338 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1339 ;; Fold case straight away; `member-ignore-case' here wasteful.
1340 (let ((x (downcase (match-string 1))))
1344 (if (re-search-forward "^[^ \t]" nil
'move
)
1345 (goto-char (match-beginning 0))
1347 (push x seen
)))))))))))
1349 ;; Note that on entry to this function the current-buffer must be the
1350 ;; *info* buffer; not the info tags buffer.
1351 (defun Info-read-subfile (nodepos)
1352 ;; NODEPOS is either a position (in the Info file as a whole,
1353 ;; not relative to a subfile) or the name of a subfile.
1356 (if (numberp nodepos
)
1357 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1358 (goto-char (point-min))
1359 (or (looking-at "\^_")
1360 (search-forward "\n\^_"))
1363 (while (not (looking-at "\^_"))
1366 thisfilepos thisfilename
)
1367 (search-forward ": ")
1368 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1369 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1370 ;; read in version 19 stops at the end of number.
1371 ;; Advance to the next line.
1373 (if (> thisfilepos nodepos
)
1375 (setq lastfilename thisfilename
)
1376 (setq lastfilepos thisfilepos
))
1377 (forward-line 1)))))
1378 (setq lastfilename nodepos
)
1379 (setq lastfilepos
0))
1380 ;; Assume previous buffer is in Info-mode.
1381 ;; (set-buffer (get-buffer "*info*"))
1382 (or (equal Info-current-subfile lastfilename
)
1383 (let ((inhibit-read-only t
))
1384 (setq buffer-file-name nil
)
1387 (info-insert-file-contents lastfilename
)
1388 (set-buffer-modified-p nil
)
1389 (setq Info-current-subfile lastfilename
)))
1390 ;; Widen in case we are in the same subfile as before.
1392 (goto-char (point-min))
1393 (if (looking-at "\^_")
1395 (search-forward "\n\^_"))
1396 (if (numberp nodepos
)
1397 (+ (- nodepos lastfilepos
) (point)))))
1399 (defun Info-unescape-quotes (value)
1400 "Unescape double quotes and backslashes in VALUE."
1403 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1404 (setq unquote
(replace-match "" t t unquote
1))
1405 (setq start
(- (match-end 0) 1)))
1408 ;; As of Texinfo 4.6, makeinfo writes constructs like
1409 ;; \0\h[image param=value ...\h\0]
1410 ;; into the Info file for handling images.
1411 (defun Info-split-parameter-string (parameter-string)
1412 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1413 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1414 If VALUE contains whitespace or double quotes, it must be quoted
1415 in double quotes and any double quotes or backslashes must be
1416 escaped (\\\",\\\\)."
1419 (while (string-match
1420 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1421 parameter-string start
)
1422 (setq start
(match-end 0))
1423 (push (cons (match-string 1 parameter-string
)
1424 (or (match-string 2 parameter-string
)
1425 (Info-unescape-quotes
1426 (match-string 3 parameter-string
))))
1430 (defun Info-display-images-node ()
1431 "Display images in current node."
1433 (let ((inhibit-read-only t
)
1434 (case-fold-search t
))
1435 (goto-char (point-min))
1436 (while (re-search-forward
1437 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1439 (let* ((start (match-beginning 1))
1440 (parameter-alist (Info-split-parameter-string (match-string 2)))
1441 (src (cdr (assoc-string "src" parameter-alist
))))
1442 (if (display-images-p)
1443 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1444 (concat default-directory src
))
1446 (image (if (file-exists-p image-file
)
1447 (create-image image-file
)
1449 (if (not (get-text-property start
'display
))
1450 (add-text-properties
1451 start
(point) `(display ,image rear-nonsticky
(display)))))
1452 ;; text-only display, show alternative text if provided, or
1453 ;; otherwise a clue that there's meant to be a picture
1454 (delete-region start
(point))
1455 (insert (or (cdr (assoc-string "text" parameter-alist
))
1456 (cdr (assoc-string "alt" parameter-alist
))
1458 (concat "[image:" src
"]"))
1460 (set-buffer-modified-p nil
)))
1462 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1463 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1464 ;; including one optional trailing newline.
1465 (defun Info-hide-cookies-node ()
1466 "Hide unrecognized cookies in current node."
1468 (let ((inhibit-read-only t
)
1469 (case-fold-search t
))
1470 (goto-char (point-min))
1471 (while (re-search-forward
1472 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1474 (let* ((start (match-beginning 1)))
1475 (if (and (not (get-text-property start
'invisible
))
1476 (not (get-text-property start
'display
)))
1477 (put-text-property start
(point) 'invisible t
)))))
1478 (set-buffer-modified-p nil
)))
1480 (defun Info-select-node ()
1481 "Select the Info node that point is in."
1482 ;; Bind this in case the user sets it to nil.
1483 (let ((case-fold-search t
))
1485 ;; Find beginning of node.
1486 (if (search-backward "\n\^_" nil
'move
)
1488 (if (looking-at "\^_")
1490 (signal 'search-failed
(list "\n\^_"))))
1491 ;; Get nodename spelled as it is in the node.
1492 (re-search-forward "Node:[ \t]*")
1493 (setq Info-current-node
1494 (buffer-substring-no-properties (point)
1496 (skip-chars-forward "^,\t\n")
1498 (Info-set-mode-line)
1499 ;; Find the end of it, and narrow.
1501 (let (active-expression)
1502 ;; Narrow to the node contents
1503 (narrow-to-region (point)
1504 (if (re-search-forward "\n[\^_\f]" nil t
)
1507 (if (looking-at "[\n\^_\f]*execute: ")
1509 (goto-char (match-end 0))
1510 (setq active-expression
1511 (read (current-buffer))))))
1513 (if Info-enable-active-nodes
(eval active-expression
))
1514 ;; Add a new unique history item to full history list
1515 (let ((new-history (list Info-current-file Info-current-node
)))
1516 (setq Info-history-list
1517 (cons new-history
(delete new-history Info-history-list
)))
1518 (setq Info-history-forward nil
))
1519 (if (not (eq Info-fontify-maximum-menu-size nil
))
1520 (Info-fontify-node))
1521 (Info-display-images-node)
1522 (Info-hide-cookies-node)
1523 (run-hooks 'Info-selection-hook
)))))
1525 (defvar Info-mode-line-node-keymap
1526 (let ((map (make-sparse-keymap)))
1527 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1528 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1530 "Keymap to put on the Info node name in the mode line.")
1532 (defun Info-set-mode-line ()
1533 (setq mode-line-buffer-identification
1534 (nconc (propertized-buffer-identification "%b")
1538 (if (stringp Info-current-file
)
1539 (replace-regexp-in-string
1540 "%" "%%" (file-name-nondirectory Info-current-file
))
1541 (format "*%S*" Info-current-file
))
1543 (if Info-current-node
1544 (propertize (replace-regexp-in-string
1545 "%" "%%" Info-current-node
)
1546 'face
'mode-line-buffer-id
1548 "mouse-1: scroll forward, mouse-3: scroll back"
1549 'mouse-face
'mode-line-highlight
1550 'local-map Info-mode-line-node-keymap
)
1553 ;; Go to an Info node specified with a filename-and-nodename string
1554 ;; of the sort that is found in pointers in nodes.
1556 ;; Don't autoload this function: the correct entry point for other packages
1557 ;; to use is `info'. --Stef
1559 (defun Info-goto-node (nodename &optional fork
)
1560 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1561 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1562 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1564 Completion is available, but only for node names in the current Info file.
1565 If FORK is non-nil (interactively with a prefix arg), show the node in
1567 If FORK is a string, it is the name to use for the new buffer."
1568 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1572 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1574 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1576 (setq filename
(if (= (match-beginning 1) (match-end 1))
1578 (match-string 2 nodename
))
1579 nodename
(match-string 3 nodename
))
1580 (let ((trim (string-match "\\s +\\'" filename
)))
1581 (if trim
(setq filename
(substring filename
0 trim
))))
1582 (let ((trim (string-match "\\s +\\'" nodename
)))
1583 (if trim
(setq nodename
(substring nodename
0 trim
))))
1584 (if transient-mark-mode
(deactivate-mark))
1585 (Info-find-node (if (equal filename
"") nil filename
)
1586 (if (equal nodename
"") "Top" nodename
))))
1588 (defvar Info-read-node-completion-table
)
1590 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1591 "Internal function used to complete Info node names.
1592 Return a completion table for Info files---the FILENAME part of a
1593 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1594 directories to search if FILENAME is not absolute; SUFFIXES is a
1595 list of valid filename suffixes for Info files. See
1596 `try-completion' for a description of the remaining arguments."
1597 (setq suffixes
(remove "" suffixes
))
1598 (when (file-name-absolute-p string
)
1599 (setq dirs
(list (file-name-directory string
))))
1601 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1602 (string-dir (file-name-directory string
)))
1605 (setq dir default-directory
))
1606 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1607 (when (file-directory-p dir
)
1608 (dolist (file (file-name-all-completions
1609 (file-name-nondirectory string
) dir
))
1610 ;; If the file name has no suffix or a standard suffix,
1612 (and (or (null (file-name-extension file
))
1613 (string-match suffix file
))
1614 ;; But exclude subfiles of split Info files.
1615 (not (string-match "-[0-9]+\\'" file
))
1616 ;; And exclude backup files.
1617 (not (string-match "~\\'" file
))
1618 (push (if string-dir
(concat string-dir file
) file
) names
))
1619 ;; If the file name ends in a standard suffix,
1620 ;; add the unsuffixed name as a completion option.
1621 (when (string-match suffix file
)
1622 (setq file
(substring file
0 (match-beginning 0)))
1623 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1624 (complete-with-action action names string pred
)))
1626 (defun Info-read-node-name-1 (string predicate code
)
1627 "Internal function used by `Info-read-node-name'.
1628 See `completing-read' for a description of arguments and usage."
1630 ;; First complete embedded file names.
1631 ((string-match "\\`([^)]*\\'" string
)
1632 (completion-table-with-context
1634 (apply-partially 'completion-table-with-terminator
")"
1635 (apply-partially 'Info-read-node-name-2
1637 (mapcar 'car Info-suffix-list
)))
1638 (substring string
1)
1641 ;; If a file name was given, then any node is fair game.
1642 ((string-match "\\`(" string
)
1644 ((eq code nil
) string
)
1647 ;; Otherwise use Info-read-node-completion-table.
1648 (t (complete-with-action
1649 code Info-read-node-completion-table string predicate
))))
1651 ;; Arrange to highlight the proper letters in the completion list buffer.
1652 (defun Info-read-node-name (prompt)
1653 "Read an Info node name with completion, prompting with PROMPT.
1654 A node name can have the form \"NODENAME\", referring to a node
1655 in the current Info file, or \"(FILENAME)NODENAME\"."
1656 (let* ((completion-ignore-case t
)
1657 (Info-read-node-completion-table (Info-build-node-completions))
1658 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1659 (if (equal nodename
"")
1660 (Info-read-node-name prompt
)
1663 (defun Info-build-node-completions ()
1664 (or Info-current-file-completions
1666 ;; Bind this in case the user sets it to nil.
1667 (case-fold-search t
)
1668 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1671 (or Info-tag-table-marker
1672 (error "No Info tags found"))
1673 (if (marker-buffer Info-tag-table-marker
)
1674 (let ((marker Info-tag-table-marker
))
1675 (set-buffer (marker-buffer marker
))
1678 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1680 (cons (list (match-string-no-properties 2))
1683 (goto-char (point-min))
1684 ;; If the buffer begins with a node header, process that first.
1685 (if (Info-node-at-bob-matching node-regexp
)
1686 (setq compl
(list (match-string-no-properties 1))))
1687 ;; Now for the rest of the nodes.
1688 (while (search-forward "\n\^_" nil t
)
1690 (let ((beg (point)))
1692 (if (re-search-backward node-regexp beg t
)
1694 (cons (list (match-string-no-properties 1))
1696 (setq compl
(cons '("*") compl
))
1697 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1699 (defun Info-restore-point (hl)
1700 "If this node has been visited, restore the point value when we left."
1702 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1703 ;; Use string-equal, not equal, to ignore text props.
1704 (string-equal (nth 1 (car hl
)) Info-current-node
))
1706 (goto-char (nth 2 (car hl
)))
1707 (setq hl nil
)) ;terminate the while at next iter
1708 (setq hl
(cdr hl
)))))
1710 (defvar Info-search-history nil
1711 "The history list for `Info-search'.")
1713 (defvar Info-search-case-fold nil
1714 "The value of `case-fold-search' from previous `Info-search' command.")
1716 (defun Info-search (regexp &optional bound _noerror _count direction
)
1717 "Search for REGEXP, starting from point, and select node it's found in.
1718 If DIRECTION is `backward', search in the reverse direction."
1719 (interactive (list (read-string
1720 (if Info-search-history
1721 (format "Regexp search%s (default %s): "
1722 (if case-fold-search
"" " case-sensitively")
1723 (car Info-search-history
))
1724 (format "Regexp search%s: "
1725 (if case-fold-search
"" " case-sensitively")))
1726 nil
'Info-search-history
)))
1728 (when (equal regexp
"")
1729 (setq regexp
(car Info-search-history
)))
1731 (let (found beg-found give-up
1732 (backward (eq direction
'backward
))
1733 (onode Info-current-node
)
1734 (ofile Info-current-file
)
1736 (opoint-min (point-min))
1737 (opoint-max (point-max))
1738 (ostart (window-start))
1739 (osubfile Info-current-subfile
))
1740 (setq Info-search-case-fold case-fold-search
)
1745 ;; Hide Info file header for backward search
1746 (narrow-to-region (save-excursion
1747 (goto-char (point-min))
1748 (search-forward "\n\^_")
1751 (while (and (not give-up
)
1753 (not (funcall isearch-filter-predicate beg-found found
))))
1754 (let ((search-spaces-regexp
1755 (if (or (not isearch-mode
) isearch-regexp
)
1756 Info-search-whitespace-regexp
)))
1758 (re-search-backward regexp bound t
)
1759 (re-search-forward regexp bound t
))
1760 (setq found
(point) beg-found
(if backward
(match-end 0)
1761 (match-beginning 0)))
1762 (setq give-up t
))))))
1764 (when (and isearch-mode Info-isearch-search
1765 (not Info-isearch-initial-node
)
1767 (or give-up
(and found
(not (and (> found opoint-min
)
1768 (< found opoint-max
))))))
1769 (signal 'search-failed
(list regexp
"initial node")))
1771 ;; If no subfiles, give error now.
1773 (if (null Info-current-subfile
)
1774 (let ((search-spaces-regexp
1775 (if (or (not isearch-mode
) isearch-regexp
)
1776 Info-search-whitespace-regexp
)))
1778 (re-search-backward regexp
)
1779 (re-search-forward regexp
)))
1782 (if (and bound
(not found
))
1783 (signal 'search-failed
(list regexp
)))
1785 (unless (or found bound
)
1787 ;; Try other subfiles.
1789 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1790 (goto-char (point-min))
1791 (search-forward "\n\^_\nIndirect:")
1793 (narrow-to-region (point)
1794 (progn (search-forward "\n\^_")
1796 (goto-char (point-min))
1797 ;; Find the subfile we just searched.
1798 (search-forward (concat "\n" osubfile
": "))
1800 (forward-line (if backward
0 1))
1801 (if backward
(forward-char -
1))
1802 ;; Make a list of all following subfiles.
1803 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1804 (while (not (if backward
(bobp) (eobp)))
1806 (re-search-backward "\\(^.*\\): [0-9]+$")
1807 (re-search-forward "\\(^.*\\): [0-9]+$"))
1808 (goto-char (+ (match-end 1) 2))
1809 (setq list
(cons (cons (+ (point-min)
1810 (read (current-buffer)))
1811 (match-string-no-properties 1))
1813 (goto-char (if backward
1814 (1- (match-beginning 0))
1815 (1+ (match-end 0)))))
1816 ;; Put in forward order
1817 (setq list
(nreverse list
))))
1819 (message "Searching subfile %s..." (cdr (car list
)))
1820 (Info-read-subfile (car (car list
)))
1822 ;; Hide Info file header for backward search
1823 (narrow-to-region (save-excursion
1824 (goto-char (point-min))
1825 (search-forward "\n\^_")
1828 (goto-char (point-max)))
1829 (setq list
(cdr list
))
1830 (setq give-up nil found nil
)
1831 (while (and (not give-up
)
1833 (not (funcall isearch-filter-predicate beg-found found
))))
1834 (let ((search-spaces-regexp
1835 (if (or (not isearch-mode
) isearch-regexp
)
1836 Info-search-whitespace-regexp
)))
1838 (re-search-backward regexp nil t
)
1839 (re-search-forward regexp nil t
))
1840 (setq found
(point) beg-found
(if backward
(match-end 0)
1841 (match-beginning 0)))
1849 (signal 'search-failed
(list regexp
))))
1851 (progn (Info-read-subfile osubfile
)
1854 (set-window-start (selected-window) ostart
)))))
1856 (if (and (string= osubfile Info-current-subfile
)
1857 (> found opoint-min
)
1858 (< found opoint-max
))
1859 ;; Search landed in the same node
1863 (save-match-data (Info-select-node)))
1865 ;; Use string-equal, not equal, to ignore text props.
1866 (or (and (string-equal onode Info-current-node
)
1867 (equal ofile Info-current-file
))
1868 (and isearch-mode isearch-wrapped
1869 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1870 (setq Info-history
(cons (list ofile onode opoint
)
1873 (defun Info-search-case-sensitively ()
1874 "Search for a regexp case-sensitively."
1876 (let ((case-fold-search nil
))
1877 (call-interactively 'Info-search
)))
1879 (defun Info-search-next ()
1880 "Search for next regexp from a previous `Info-search' command."
1882 (let ((case-fold-search Info-search-case-fold
))
1883 (if Info-search-history
1884 (Info-search (car Info-search-history
))
1885 (call-interactively 'Info-search
))))
1887 (defun Info-search-backward (regexp &optional bound noerror count
)
1888 "Search for REGEXP in the reverse direction."
1889 (interactive (list (read-string
1890 (if Info-search-history
1891 (format "Regexp search%s backward (default %s): "
1892 (if case-fold-search
"" " case-sensitively")
1893 (car Info-search-history
))
1894 (format "Regexp search%s backward: "
1895 (if case-fold-search
"" " case-sensitively")))
1896 nil
'Info-search-history
)))
1897 (Info-search regexp bound noerror count
'backward
))
1899 (defun Info-isearch-search ()
1900 (if Info-isearch-search
1901 (lambda (string &optional bound noerror count
)
1903 (Info-search (concat "\\b" (replace-regexp-in-string
1905 (replace-regexp-in-string
1906 "^\\W+\\|\\W+$" "" string
)
1908 ;; Lax version of word search
1909 (if (or isearch-nonincremental
1911 (length (isearch-string-state
1912 (car isearch-cmds
)))))
1915 (unless isearch-forward
'backward
))
1916 (Info-search (if isearch-regexp string
(regexp-quote string
))
1918 (unless isearch-forward
'backward
)))
1920 (let ((isearch-search-fun-function nil
))
1921 (isearch-search-fun))))
1923 (defun Info-isearch-wrap ()
1924 (if Info-isearch-search
1925 (if Info-isearch-initial-node
1927 (if isearch-forward
(Info-top-node) (Info-final-node))
1928 (goto-char (if isearch-forward
(point-min) (point-max))))
1929 (setq Info-isearch-initial-node Info-current-node
)
1930 (setq isearch-wrapped nil
))
1931 (goto-char (if isearch-forward
(point-min) (point-max)))))
1933 (defun Info-isearch-push-state ()
1935 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
1937 (defun Info-isearch-pop-state (_cmd file node
)
1938 (or (and (equal Info-current-file file
)
1939 (equal Info-current-node node
))
1940 (progn (Info-find-node file node
) (sit-for 0))))
1942 (defun Info-isearch-start ()
1943 (setq Info-isearch-initial-node
1944 ;; Don't stop at initial node for nonincremental search.
1945 ;; Otherwise this variable is set after first search failure.
1946 (and isearch-nonincremental Info-current-node
))
1947 (setq Info-isearch-initial-history Info-history
1948 Info-isearch-initial-history-list Info-history-list
)
1949 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
1951 (defun Info-isearch-end ()
1952 ;; Remove intermediate nodes (visited while searching)
1953 ;; from the history. Add only the last node (where Isearch ended).
1954 (if (> (length Info-history
)
1955 (length Info-isearch-initial-history
))
1957 (nthcdr (- (length Info-history
)
1958 (length Info-isearch-initial-history
)
1961 (if (> (length Info-history-list
)
1962 (length Info-isearch-initial-history-list
))
1963 (setq Info-history-list
1964 (cons (car Info-history-list
)
1965 Info-isearch-initial-history-list
)))
1966 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
1968 (defun Info-isearch-filter (beg-found found
)
1969 "Test whether the current search hit is a visible useful text.
1970 Return non-nil if the text from BEG-FOUND to FOUND is visible
1971 and is not in the header line or a tag table."
1973 (let ((backward (< found beg-found
)))
1976 (and (not (eq search-invisible t
))
1978 (or (text-property-not-all found beg-found
'invisible nil
)
1979 (text-property-not-all found beg-found
'display nil
))
1980 (or (text-property-not-all beg-found found
'invisible nil
)
1981 (text-property-not-all beg-found found
'display nil
))))
1982 ;; Skip node header line
1983 (and (save-excursion (forward-line -
1)
1985 (forward-line (if backward -
1 1)))
1986 ;; Skip Tag Table node
1988 (and (search-backward "\^_" nil t
)
1990 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1993 (defun Info-extract-pointer (name &optional errorname
)
1994 "Extract the value of the node-pointer named NAME.
1995 If there is none, use ERRORNAME in the error message;
1996 if ERRORNAME is nil, just return nil."
1997 ;; Bind this in case the user sets it to nil.
1998 (let ((case-fold-search t
))
2000 (goto-char (point-min))
2001 (let ((bound (point)))
2003 (cond ((re-search-backward
2004 (concat name
":" (Info-following-node-name-re)) bound t
)
2005 (match-string-no-properties 1))
2006 ((not (eq errorname t
))
2007 (error "Node has no %s"
2008 (capitalize (or errorname name
)))))))))
2010 (defun Info-following-node-name-re (&optional allowedchars
)
2011 "Return a regexp matching a node name.
2012 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2013 saying which chars may appear in the node name.
2014 Submatch 1 is the complete node name.
2015 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2016 Submatch 3 is the local part of the node name.
2017 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2018 (concat "[ \t]*" ;Skip leading space.
2019 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2020 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2021 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2022 "\\|\\)\\)")) ;Allow empty node names.
2024 ;;; For compatibility; other files have used this name.
2025 (defun Info-following-node-name ()
2026 (and (looking-at (Info-following-node-name-re))
2027 (match-string-no-properties 1)))
2030 "Go to the next node of this node."
2032 ;; In case another window is currently selected
2033 (save-window-excursion
2034 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2035 (Info-goto-node (Info-extract-pointer "next"))))
2038 "Go to the previous node of this node."
2040 ;; In case another window is currently selected
2041 (save-window-excursion
2042 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2043 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2045 (defun Info-up (&optional same-file
)
2046 "Go to the superior node of this node.
2047 If SAME-FILE is non-nil, do not move to a different Info file."
2049 ;; In case another window is currently selected
2050 (save-window-excursion
2051 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2052 (let ((old-node Info-current-node
)
2053 (old-file Info-current-file
)
2054 (node (Info-extract-pointer "up")) p
)
2056 (string-match "^(" node
)
2057 (error "Up node is in another Info file"))
2058 (Info-goto-node node
)
2060 (goto-char (point-min))
2061 (if (and (stringp old-file
)
2062 (search-forward "\n* Menu:" nil t
)
2064 (if (string-equal old-node
"Top")
2065 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2066 (concat "\n\\* +\\(" (regexp-quote old-node
)
2067 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2069 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2071 (Info-restore-point Info-history
)))))
2073 (defun Info-history-back ()
2074 "Go back in the history to the last node visited."
2077 (error "This is the first Info node you looked at"))
2078 (let ((history-forward
2079 (cons (list Info-current-file Info-current-node
(point))
2080 Info-history-forward
))
2081 filename nodename opoint
)
2082 (setq filename
(car (car Info-history
)))
2083 (setq nodename
(car (cdr (car Info-history
))))
2084 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2085 (setq Info-history
(cdr Info-history
))
2086 (Info-find-node filename nodename
)
2087 (setq Info-history
(cdr Info-history
))
2088 (setq Info-history-forward history-forward
)
2089 (goto-char opoint
)))
2091 (defalias 'Info-last
'Info-history-back
)
2093 (defun Info-history-forward ()
2094 "Go forward in the history of visited nodes."
2096 (or Info-history-forward
2097 (error "This is the last Info node you looked at"))
2098 (let ((history-forward (cdr Info-history-forward
))
2099 filename nodename opoint
)
2100 (setq filename
(car (car Info-history-forward
)))
2101 (setq nodename
(car (cdr (car Info-history-forward
))))
2102 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2103 (Info-find-node filename nodename
)
2104 (setq Info-history-forward history-forward
)
2105 (goto-char opoint
)))
2107 (add-to-list 'Info-virtual-files
2109 (toc-nodes . Info-directory-toc-nodes
)
2110 (find-file . Info-directory-find-file
)
2111 (find-node . Info-directory-find-node
)
2114 (defun Info-directory-toc-nodes (filename)
2115 "Directory-specific implementation of `Info-toc-nodes'."
2117 ("Top" nil nil nil
)))
2119 (defun Info-directory-find-file (filename &optional _noerror
)
2120 "Directory-specific implementation of `Info-find-file'."
2123 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2124 "Directory-specific implementation of `Info-find-node-2'."
2128 (defun Info-directory ()
2129 "Go to the Info directory node."
2131 (Info-find-node "dir" "top"))
2133 (add-to-list 'Info-virtual-files
2134 '("\\`\\*History\\*\\'"
2135 (toc-nodes . Info-history-toc-nodes
)
2136 (find-file . Info-history-find-file
)
2137 (find-node . Info-history-find-node
)
2140 (defun Info-history-toc-nodes (filename)
2141 "History-specific implementation of `Info-toc-nodes'."
2143 ("Top" nil nil nil
)))
2145 (defun Info-history-find-file (filename &optional _noerror
)
2146 "History-specific implementation of `Info-find-file'."
2149 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2150 "History-specific implementation of `Info-find-node-2'."
2151 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2152 (or filename Info-current-file
) nodename
))
2153 (insert "Recently Visited Nodes\n")
2154 (insert "**********************\n\n")
2155 (insert "* Menu:\n\n")
2156 (let ((hl (delete '("*History*" "Top") Info-history-list
)))
2158 (let ((file (nth 0 (car hl
)))
2159 (node (nth 1 (car hl
))))
2161 (insert "* " node
": ("
2162 (propertize (or (file-name-directory file
) "") 'invisible t
)
2163 (file-name-nondirectory file
)
2165 (setq hl
(cdr hl
)))))
2167 (defun Info-history ()
2168 "Go to a node with a menu of visited nodes."
2170 (Info-find-node "*History*" "Top")
2171 (Info-next-reference)
2172 (Info-next-reference))
2174 (add-to-list 'Info-virtual-nodes
2176 (find-node . Info-toc-find-node
)
2179 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2180 "Toc-specific implementation of `Info-find-node-2'."
2181 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2182 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2183 (node-list (Info-toc-nodes curr-file
)))
2184 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2185 curr-file curr-node
))
2186 (insert "Table of Contents\n")
2187 (insert "*****************\n\n")
2188 (insert "*Note Top::\n")
2190 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2191 node-list
0 curr-file
)
2193 (let ((Info-hide-note-references 'hide
)
2194 (Info-fontify-visited-nodes nil
))
2195 (setq Info-current-file filename Info-current-node
"*TOC*")
2196 (goto-char (point-min))
2197 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2204 "Go to a node with table of contents of the current Info file.
2205 Table of contents is created from the tree structure of menus."
2207 (Info-find-node Info-current-file
"*TOC*")
2208 (let ((prev-node (nth 1 (car Info-history
))) p
)
2209 (goto-char (point-min))
2210 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2211 (setq p
(- p
(length prev-node
) 2)))
2212 (goto-char (or p
(point-min)))))
2214 (defun Info-toc-insert (nodes node-list level curr-file
)
2215 "Insert table of contents with references to nodes."
2216 (let ((section "Top"))
2218 (let ((node (assoc (car nodes
) node-list
)))
2219 (unless (member (nth 2 node
) (list nil section
))
2220 (insert (setq section
(nth 2 node
)) "\n"))
2221 (insert (make-string level ?
\t))
2222 (insert "*Note " (car nodes
) ":: \n")
2223 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2224 (setq nodes
(cdr nodes
))))))
2226 (defun Info-toc-build (file)
2227 "Build table of contents from menus of Info FILE and its subfiles."
2229 (let* ((file (and (stringp file
) (Info-find-file file
)))
2230 (default-directory (or (and (stringp file
)
2231 (file-name-directory file
))
2233 (main-file (and (stringp file
) file
))
2234 (sections '(("Top" "Top")))
2236 (while (or main-file subfiles
)
2237 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2239 (info-insert-file-contents (or main-file
(car subfiles
)))
2240 (goto-char (point-min))
2241 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2242 (search-forward "Node: " nil
'move
))
2243 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2244 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2246 (upnode (and (re-search-forward
2247 (concat "Up:" (Info-following-node-name-re))
2249 (match-string-no-properties 1)))
2252 (when (string-match "(" upnode
) (setq upnode nil
))
2253 (when (and (not (Info-index-node nodename file
))
2254 (re-search-forward "^\\* Menu:" bound t
))
2257 (setq bound
(or (and (equal nodename
"Top")
2260 "^[ \t-]*The Detailed Node Listing" nil t
)))
2262 (while (< (point) bound
)
2265 ((looking-at "^\\* +[^:]+:")
2268 (let ((menu-node-name (substring-no-properties
2269 (Info-extract-menu-node-name))))
2270 (setq menu-items
(cons menu-node-name menu-items
))
2271 (if (equal nodename
"Top")
2273 (cons (list menu-node-name section
) sections
)))))
2274 ;; Other non-empty strings in the Top node are section names
2275 ((and (equal nodename
"Top")
2276 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2277 (setq section
(match-string-no-properties 1))))
2279 (beginning-of-line)))
2280 (setq nodes
(cons (list nodename upnode
2281 (cadr (assoc nodename sections
))
2282 (nreverse menu-items
))
2287 (goto-char (point-min))
2288 (if (search-forward "\n\^_\nIndirect:" nil t
)
2289 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2290 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2291 (setq subfiles
(cons (match-string-no-properties 1)
2293 (setq subfiles
(nreverse subfiles
)
2295 (setq subfiles
(cdr subfiles
))))
2299 (defvar Info-toc-nodes nil
2300 "Alist of cached parent-children node information in visited Info files.
2301 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2302 where PARENT is the parent node extracted from the Up pointer,
2303 SECTION is the section name in the Top node where this node is placed,
2304 CHILDREN is a list of child nodes extracted from the node menu.")
2306 (defun Info-toc-nodes (filename)
2307 "Return a node list of Info FILENAME with parent-children information.
2308 This information is cached in the variable `Info-toc-nodes' with the help
2309 of the function `Info-toc-build'."
2312 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2315 (or filename
(setq filename Info-current-file
))
2316 (or (assoc filename Info-toc-nodes
)
2317 ;; Skip virtual Info files
2318 (and (or (not (stringp filename
))
2319 (Info-virtual-file-p filename
))
2320 (push (cons filename nil
) Info-toc-nodes
))
2321 ;; Scan the entire manual and cache the result in Info-toc-nodes
2322 (let ((nodes (Info-toc-build filename
)))
2323 (push (cons filename nodes
) Info-toc-nodes
)
2325 ;; If there is an error, still add nil to the cache
2326 (push (cons filename nil
) Info-toc-nodes
))
2327 (cdr (assoc filename Info-toc-nodes
)))))
2330 (defun Info-follow-reference (footnotename &optional fork
)
2331 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2332 FOOTNOTENAME may be an abbreviation of the reference name.
2333 If FORK is non-nil (interactively with a prefix arg), show the node in
2334 a new Info buffer. If FORK is a string, it is the name to use for the
2337 (let ((completion-ignore-case t
)
2338 (case-fold-search t
)
2339 completions default alt-default
(start-point (point)) str i bol eol
)
2341 ;; Store end and beginning of line.
2342 (setq eol
(line-end-position)
2343 bol
(line-beginning-position))
2344 (goto-char (point-min))
2345 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2346 (setq str
(match-string-no-properties 1))
2347 ;; See if this one should be the default.
2349 (<= (match-beginning 0) start-point
)
2350 (<= start-point
(point))
2352 ;; See if this one should be the alternate default.
2353 (and (null alt-default
)
2354 (and (<= bol
(match-beginning 0))
2356 (setq alt-default t
))
2358 (while (setq i
(string-match "[ \n\t]+" str i
))
2359 (setq str
(concat (substring str
0 i
) " "
2360 (substring str
(match-end 0))))
2362 ;; Record as a completion and perhaps as default.
2363 (if (eq default t
) (setq default str
))
2364 (if (eq alt-default t
) (setq alt-default str
))
2365 ;; Don't add this string if it's a duplicate.
2366 (or (assoc-string str completions t
)
2367 (push str completions
))))
2368 ;; If no good default was found, try an alternate.
2370 (setq default alt-default
))
2371 ;; If only one cross-reference found, then make it default.
2372 (if (eq (length completions
) 1)
2373 (setq default
(car completions
)))
2375 (let ((input (completing-read (if default
2377 "Follow reference named (default "
2379 "Follow reference named: ")
2380 completions nil t
)))
2381 (list (if (equal input
"")
2382 default input
) current-prefix-arg
))
2383 (error "No cross-references in this node"))))
2385 (unless footnotename
2386 (error "No reference was specified"))
2388 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2389 (case-fold-search t
))
2390 (while (setq i
(string-match " " str i
))
2391 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2394 ;; Move point to the beginning of reference if point is on reference
2395 (or (looking-at "\\*note[ \n\t]+")
2396 (and (looking-back "\\*note[ \n\t]+")
2397 (goto-char (match-beginning 0)))
2398 (if (and (save-excursion
2399 (goto-char (+ (point) 5)) ; skip a possible *note
2400 (re-search-backward "\\*note[ \n\t]+" nil t
)
2402 (<= (point) (match-end 0)))
2403 (goto-char (match-beginning 0))))
2404 ;; Go to the reference closest to point
2405 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2406 (+ (match-beginning 0) 5))))
2407 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2408 (+ (match-beginning 0) 5)))))
2409 (goto-char (cond ((and next-ref prev-ref
)
2410 (if (< (abs (- next-ref
(point)))
2411 (abs (- prev-ref
(point))))
2413 ((or next-ref prev-ref
))
2414 ((error "No cross-reference named %s" footnotename
))))
2415 (setq target
(Info-extract-menu-node-name t
))))
2416 (while (setq i
(string-match "[ \t\n]+" target i
))
2417 (setq target
(concat (substring target
0 i
) " "
2418 (substring target
(match-end 0))))
2420 (Info-goto-node target fork
)))
2422 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2423 ;; We allow newline because this is also used in Info-follow-reference,
2424 ;; where the xref name might be wrapped over two lines.
2425 "Regexp that matches a menu entry name upto but not including the colon.
2426 Because of ambiguities, this should be concatenated with something like
2427 `:' and `Info-following-node-name-re'.")
2429 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2430 (skip-chars-forward " \t\n")
2431 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2432 (Info-following-node-name-re
2434 (index-node "^,\t\n")
2435 (multi-line "^.,\t")
2439 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2442 (setq Info-point-loc
2443 (if (match-beginning 5)
2444 (string-to-number (match-string 5))
2445 (buffer-substring-no-properties
2446 (match-beginning 0) (1- (match-beginning 1)))))
2447 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2448 ;;; (setq Info-point-loc
2449 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2451 (replace-regexp-in-string
2453 (or (and (not (equal (match-string-no-properties 2) ""))
2454 (match-string-no-properties 2))
2455 ;; If the node name is the menu entry name (using `entry::').
2456 (buffer-substring-no-properties
2457 (match-beginning 0) (1- (match-beginning 1)))))))
2459 ;; No one calls this.
2460 ;;(defun Info-menu-item-sequence (list)
2462 ;; (Info-menu (car list))
2463 ;; (setq list (cdr list))))
2465 (defvar Info-complete-menu-buffer
)
2466 (defvar Info-complete-next-re nil
)
2467 (defvar Info-complete-nodes nil
)
2468 (defvar Info-complete-cache nil
)
2470 (defconst Info-node-spec-re
2471 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2472 "Regexp to match the text after a : until the terminating `.'.")
2474 (defun Info-complete-menu-item (string predicate action
)
2475 ;; This uses two dynamically bound variables:
2476 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2477 ;; is the menu of items we're trying to complete.
2478 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2479 ;; also look for menu items in subsequent nodes as long as those
2480 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2482 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2483 ;; also look for menu items in these nodes. This feature is currently
2484 ;; only used for completion in Info-index.
2486 ;; Note that `Info-complete-menu-buffer' could be current already,
2487 ;; so we want to save point.
2488 (with-current-buffer Info-complete-menu-buffer
2490 (let ((completion-ignore-case t
)
2491 (case-fold-search t
)
2492 (orignode Info-current-node
)
2494 (goto-char (point-min))
2495 (search-forward "\n* Menu:")
2497 ((eq (car-safe action
) 'boundaries
) nil
)
2498 ((eq action
'lambda
)
2500 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2502 (let ((pattern (concat "\n\\* +\\("
2503 (regexp-quote string
)
2504 Info-menu-entry-name-re
"\\):"
2507 (complete-nodes Info-complete-nodes
))
2509 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2510 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2511 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2512 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2513 (let ((prev (nth 3 Info-complete-cache
)))
2514 (eq t
(compare-strings string
0 (length prev
)
2516 ;; We can reuse the previous list.
2517 (setq completions
(nth 4 Info-complete-cache
))
2518 ;; The cache can't be used.
2521 (while (re-search-forward pattern nil t
)
2522 (push (match-string-no-properties 1)
2524 ;; Check subsequent nodes if applicable.
2525 (or (and Info-complete-next-re
2526 (setq nextnode
(Info-extract-pointer "next" t
))
2527 (string-match Info-complete-next-re nextnode
))
2529 (setq complete-nodes
(cdr complete-nodes
)
2530 nextnode
(car complete-nodes
)))))
2531 (Info-goto-node nextnode
))
2532 ;; Go back to the start node (for the next completion).
2533 (unless (equal Info-current-node orignode
)
2534 (Info-goto-node orignode
))
2535 ;; Update the cache.
2536 (set (make-local-variable 'Info-complete-cache
)
2537 (list Info-current-file Info-current-node
2538 Info-complete-next-re string completions
2539 Info-complete-nodes
)))
2540 (complete-with-action action completions string predicate
))))))))
2543 (defun Info-menu (menu-item &optional fork
)
2544 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2545 The menu item should one of those listed in the current node's menu.
2546 Completion is allowed, and the default menu item is the one point is on.
2547 If FORK is non-nil (interactively with a prefix arg), show the node in
2548 a new Info buffer. If FORK is a string, it is the name to use for the
2551 (let (;; If point is within a menu item, use that item as the default
2555 (case-fold-search t
))
2557 (goto-char (point-min))
2558 (if (not (search-forward "\n* menu:" nil t
))
2559 (error "No menu in this node"))
2565 (if (re-search-backward (concat "\n\\* +\\("
2566 Info-menu-entry-name-re
2568 (setq default
(match-string-no-properties 1))))))
2571 (setq item
(let ((completion-ignore-case t
)
2572 (Info-complete-menu-buffer (current-buffer)))
2573 (completing-read (if default
2574 (format "Menu item (default %s): "
2577 'Info-complete-menu-item nil t
)))
2578 ;; we rely on the fact that completing-read accepts an input
2579 ;; of "" even when the require-match argument is true and ""
2580 ;; is not a valid possibility
2581 (if (string= item
"")
2586 (list item current-prefix-arg
))))
2587 ;; there is a problem here in that if several menu items have the same
2588 ;; name you can only go to the node of the first with this command.
2589 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2591 (defun Info-extract-menu-item (menu-item)
2592 (setq menu-item
(regexp-quote menu-item
))
2593 (let ((case-fold-search t
))
2595 (let ((case-fold-search t
))
2596 (goto-char (point-min))
2597 (or (search-forward "\n* menu:" nil t
)
2598 (error "No menu in this node"))
2599 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2600 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2601 (error "No such item in menu"))
2604 (Info-extract-menu-node-name nil
(Info-index-node))))))
2606 ;; If COUNT is nil, use the last item in the menu.
2607 (defun Info-extract-menu-counting (count &optional no-detail
)
2608 (let ((case-fold-search t
))
2610 (let ((case-fold-search t
)
2611 (bound (when (and no-detail
2613 "^[ \t-]*The Detailed Node Listing" nil t
))
2614 (match-beginning 0))))
2615 (goto-char (point-min))
2616 (or (search-forward "\n* menu:" bound t
)
2617 (error "No menu in this node"))
2619 (or (search-forward "\n* " bound t count
)
2620 (error "Too few items in menu"))
2621 (while (search-forward "\n* " bound t
)
2623 (Info-extract-menu-node-name nil
(Info-index-node))))))
2625 (defun Info-nth-menu-item ()
2626 "Go to the node of the Nth menu item.
2627 N is the digit argument used to invoke this command."
2630 (Info-extract-menu-counting
2631 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2633 (defun Info-top-node ()
2634 "Go to the Top node of this file."
2636 (Info-goto-node "Top"))
2638 (defun Info-final-node ()
2639 "Go to the final node in this file."
2641 (Info-goto-node "Top")
2642 (let ((Info-history nil
)
2643 (case-fold-search t
))
2644 ;; Go to the last node in the menu of Top. But don't delve into
2645 ;; detailed node listings.
2646 (Info-goto-node (Info-extract-menu-counting nil t
))
2647 ;; If the last node in the menu is not last in pointer structure,
2648 ;; move forward (but not down- or upward - see bug#1116) until we
2649 ;; can't go any farther.
2650 (while (Info-forward-node t t t
) nil
)
2651 ;; Then keep moving down to last subnode, unless we reach an index.
2652 (while (and (not (Info-index-node))
2653 (save-excursion (search-forward "\n* Menu:" nil t
)))
2654 (Info-goto-node (Info-extract-menu-counting nil
)))))
2656 (defun Info-forward-node (&optional not-down not-up no-error
)
2657 "Go forward one node, considering all nodes as forming one sequence."
2659 (goto-char (point-min))
2661 (let ((case-fold-search t
))
2662 ;; three possibilities, in order of priority:
2663 ;; 1. next node is in a menu in this node (but not in an index)
2664 ;; 2. next node is next at same level
2665 ;; 3. next node is up and next
2666 (cond ((and (not not-down
)
2667 (save-excursion (search-forward "\n* menu:" nil t
))
2668 (not (Info-index-node)))
2669 (Info-goto-node (Info-extract-menu-counting 1))
2671 ((save-excursion (search-backward "next:" nil t
))
2675 (save-excursion (search-backward "up:" nil t
))
2676 ;; Use string-equal, not equal, to ignore text props.
2677 (not (string-equal (downcase (Info-extract-pointer "up"))
2679 (let ((old-node Info-current-node
))
2681 (let ((old-history Info-history
)
2684 (setq success
(Info-forward-node t nil no-error
))
2685 (or success
(Info-goto-node old-node
)))
2686 (if Info-history-skip-intermediate-nodes
2687 (setq Info-history old-history
)))))
2689 (t (error "No pointer forward from this node")))))
2691 (defun Info-backward-node ()
2692 "Go backward one node, considering all nodes as forming one sequence."
2694 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2695 (upnode (Info-extract-pointer "up" t
))
2696 (case-fold-search t
))
2697 (cond ((and upnode
(string-match "(" upnode
))
2698 (error "First node in file"))
2699 ((and upnode
(or (null prevnode
)
2700 ;; Use string-equal, not equal,
2701 ;; to ignore text properties.
2702 (string-equal (downcase prevnode
)
2703 (downcase upnode
))))
2706 ;; If we move back at the same level,
2707 ;; go down to find the last subnode*.
2709 (let ((old-history Info-history
))
2710 (while (and (not (Info-index-node))
2711 (save-excursion (search-forward "\n* Menu:" nil t
)))
2712 (Info-goto-node (Info-extract-menu-counting nil
)))
2713 (if Info-history-skip-intermediate-nodes
2714 (setq Info-history old-history
))))
2716 (error "No pointer backward from this node")))))
2719 "Exit Info by selecting some other buffer."
2722 (save-buffers-kill-emacs)
2725 (defun Info-next-menu-item ()
2726 "Go to the node of the next menu item."
2728 ;; Bind this in case the user sets it to nil.
2729 (let* ((case-fold-search t
)
2733 (search-forward "\n* menu:" nil t
)
2734 (and (search-forward "\n* " nil t
)
2735 (Info-extract-menu-node-name)))))
2736 (if node
(Info-goto-node node
)
2737 (error "No more items in menu"))))
2739 (defun Info-last-menu-item ()
2740 "Go to the node of the previous menu item."
2744 ;; Bind this in case the user sets it to nil.
2745 (let* ((case-fold-search t
)
2746 (beg (save-excursion
2747 (and (search-backward "\n* menu:" nil t
)
2749 (or (and beg
(search-backward "\n* " beg t
))
2750 (error "No previous items in menu")))
2751 (Info-goto-node (save-excursion
2752 (goto-char (match-end 0))
2753 (Info-extract-menu-node-name)))))
2755 (defmacro Info-no-error
(&rest body
)
2756 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2758 (defun Info-next-preorder ()
2759 "Go to the next subnode or the next node, or go up a level."
2761 (cond ((Info-no-error (Info-next-menu-item)))
2762 ((Info-no-error (Info-next)))
2763 ((Info-no-error (Info-up t
))
2764 ;; Since we have already gone thru all the items in this menu,
2765 ;; go up to the end of this node.
2766 (goto-char (point-max))
2767 ;; Since logically we are done with the node with that menu,
2768 ;; move on from it. But don't add intermediate nodes
2769 ;; to the history on recursive calls.
2770 (let ((old-history Info-history
))
2771 (Info-next-preorder)
2772 (if Info-history-skip-intermediate-nodes
2773 (setq Info-history old-history
))))
2775 (error "No more nodes"))))
2777 (defun Info-last-preorder ()
2778 "Go to the last node, popping up a level if there is none."
2780 (cond ((and Info-scroll-prefer-subnodes
2782 (Info-last-menu-item)
2783 ;; If we go down a menu item, go to the end of the node
2784 ;; so we can scroll back through it.
2785 (goto-char (point-max))))
2786 ;; Keep going down, as long as there are nested menu nodes.
2787 (let ((old-history Info-history
))
2788 (while (Info-no-error
2789 (Info-last-menu-item)
2790 ;; If we go down a menu item, go to the end of the node
2791 ;; so we can scroll back through it.
2792 (goto-char (point-max))))
2793 (if Info-history-skip-intermediate-nodes
2794 (setq Info-history old-history
)))
2796 ((and (Info-no-error (Info-extract-pointer "prev"))
2797 (not (equal (Info-extract-pointer "up")
2798 (Info-extract-pointer "prev"))))
2799 (Info-no-error (Info-prev))
2800 (goto-char (point-max))
2801 (let ((old-history Info-history
))
2802 (while (Info-no-error
2803 (Info-last-menu-item)
2804 ;; If we go down a menu item, go to the end of the node
2805 ;; so we can scroll back through it.
2806 (goto-char (point-max))))
2807 (if Info-history-skip-intermediate-nodes
2808 (setq Info-history old-history
)))
2810 ((Info-no-error (Info-up t
))
2811 (goto-char (point-min))
2812 (let ((case-fold-search t
))
2813 (or (search-forward "\n* Menu:" nil t
)
2814 (goto-char (point-max)))))
2815 (t (error "No previous nodes"))))
2817 (defun Info-scroll-up ()
2818 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2819 Once you scroll far enough in a node that its menu appears on the screen
2820 but after point, the next scroll moves into its first subnode, unless
2821 `Info-scroll-prefer-subnodes' is nil.
2823 When you scroll past the end of a node, that goes to the next node if
2824 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2825 if this node has no successor, it moves to the parent node's successor,
2826 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2827 the menu of a node, it moves to subnode indicated by the following menu
2828 item. (That case won't normally result from this command, but can happen
2832 (if (or (< (window-start) (point-min))
2833 (> (window-start) (point-max)))
2834 (set-window-start (selected-window) (point)))
2835 (let* ((case-fold-search t
)
2836 (virtual-end (save-excursion
2837 (goto-char (point-min))
2838 (if (and Info-scroll-prefer-subnodes
2839 (search-forward "\n* Menu:" nil t
))
2842 (if (or (< virtual-end
(window-start))
2843 (pos-visible-in-window-p virtual-end
))
2845 (Info-scroll-prefer-subnodes (Info-next-preorder))
2846 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2847 (t (Info-next-preorder)))
2850 (defun Info-mouse-scroll-up (e)
2851 "Scroll one screenful forward in Info, using the mouse.
2852 See `Info-scroll-up'."
2854 (save-selected-window
2856 (select-window (posn-window (event-start e
))))
2859 (defun Info-scroll-down ()
2860 "Scroll one screenful back in Info, considering all nodes as one sequence.
2861 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2862 is non-nil, this goes to its last subnode. When you scroll past the
2863 beginning of a node, that goes to the previous node or back up to the
2866 (if (or (< (window-start) (point-min))
2867 (> (window-start) (point-max)))
2868 (set-window-start (selected-window) (point)))
2869 (let* ((case-fold-search t
)
2870 (current-point (point))
2872 (and Info-scroll-prefer-subnodes
2874 (setq current-point
(line-beginning-position))
2875 (goto-char (point-min))
2876 (search-forward "\n* Menu:" current-point t
)))))
2878 (pos-visible-in-window-p (point-min) nil t
))
2879 (Info-last-preorder)
2882 (defun Info-mouse-scroll-down (e)
2883 "Scroll one screenful backward in Info, using the mouse.
2884 See `Info-scroll-down'."
2886 (save-selected-window
2888 (select-window (posn-window (event-start e
))))
2889 (Info-scroll-down)))
2891 (defun Info-next-reference (&optional recur
)
2892 "Move cursor to the next cross-reference or menu item in the node."
2894 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2896 (case-fold-search t
))
2897 (or (eobp) (forward-char 1))
2898 (or (re-search-forward pat nil t
)
2900 (goto-char (point-min))
2901 (or (re-search-forward pat nil t
)
2904 (error "No cross references in this node")))))
2905 (goto-char (or (match-beginning 1) (match-beginning 0)))
2906 (if (looking-at "\\* Menu:")
2908 (error "No cross references in this node")
2909 (Info-next-reference t
))
2910 (if (looking-at "^\\* ")
2911 (forward-char 2)))))
2913 (defun Info-prev-reference (&optional recur
)
2914 "Move cursor to the previous cross-reference or menu item in the node."
2916 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2918 (case-fold-search t
))
2919 (or (re-search-backward pat nil t
)
2921 (goto-char (point-max))
2922 (or (re-search-backward pat nil t
)
2925 (error "No cross references in this node")))))
2926 (goto-char (or (match-beginning 1) (match-beginning 0)))
2927 (if (looking-at "\\* Menu:")
2929 (error "No cross references in this node")
2930 (Info-prev-reference t
))
2931 (if (looking-at "^\\* ")
2932 (forward-char 2)))))
2934 (defvar Info-index-nodes nil
2935 "Alist of cached index node names of visited Info files.
2936 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2938 (defun Info-index-nodes (&optional file
)
2939 "Return a list of names of all index nodes in Info FILE.
2940 If FILE is omitted, it defaults to the current Info file.
2941 First look in a list of cached index node names. Then scan Info
2942 file and its subfiles for nodes with the index cookie. Then try
2943 to find index nodes starting from the first node in the top level
2944 menu whose name contains the word \"Index\", plus any immediately
2945 following nodes whose names also contain the word \"Index\"."
2946 (or file
(setq file Info-current-file
))
2947 (or (assoc file Info-index-nodes
)
2948 ;; Skip virtual Info files
2949 (and (or (not (stringp file
))
2950 (Info-virtual-file-p file
))
2951 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2952 (if (Info-file-supports-index-cookies file
)
2953 ;; Find nodes with index cookie
2954 (let* ((default-directory (or (and (stringp file
)
2955 (file-name-directory
2956 (setq file
(Info-find-file file
))))
2958 Info-history Info-history-list Info-fontify-maximum-menu-size
2959 (main-file file
) subfiles nodes
)
2962 (while (or main-file subfiles
)
2964 (info-insert-file-contents (or main-file
(car subfiles
)))
2965 (goto-char (point-min))
2966 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2968 (re-search-backward "^\^_")
2969 (search-forward "Node: ")
2970 (setq nodes
(cons (Info-following-node-name) nodes
))))
2973 (goto-char (point-min))
2974 (if (search-forward "\n\^_\nIndirect:" nil t
)
2975 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2976 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2977 (setq subfiles
(cons (match-string-no-properties 1)
2979 (setq subfiles
(nreverse subfiles
)
2981 (setq subfiles
(cdr subfiles
)))))
2984 (setq nodes
(nreverse nodes
)
2985 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2987 ;; Else find nodes with the word "Index" in the node name
2988 (let ((case-fold-search t
)
2989 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2994 (Info-find-node file
"Top")
2995 (when (and (search-forward "\n* menu:" nil t
)
2996 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2997 (goto-char (match-beginning 1))
2998 (setq nodes
(list (Info-extract-menu-node-name)))
2999 (Info-goto-node (car nodes
))
3000 (while (and (setq node
(Info-extract-pointer "next" t
))
3001 (string-match "\\<Index\\>" node
))
3003 (Info-goto-node node
))))
3006 (setq nodes
(nreverse nodes
)
3007 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3009 ;; If file has no index nodes, still add it to the cache
3010 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3011 (cdr (assoc file Info-index-nodes
)))
3013 (defun Info-index-node (&optional node file
)
3014 "Return non-nil value if NODE is an index node.
3015 If NODE is nil, check the current Info node.
3016 If FILE is nil, check the current Info file."
3017 (or file
(setq file Info-current-file
))
3018 (if (and (or (and node
(not (equal node Info-current-node
)))
3019 (assoc file Info-index-nodes
))
3020 (not Info-current-node-virtual
))
3021 (member (or node Info-current-node
) (Info-index-nodes file
))
3022 ;; Don't search all index nodes if request is only for the current node
3023 ;; and file is not in the cache of index nodes
3025 (if (Info-file-supports-index-cookies file
)
3027 (goto-char (+ (or (save-excursion
3028 (search-backward "\n\^_" nil t
))
3030 (search-forward "\0\b[index\0\b]"
3032 (search-forward "\n\^_" nil t
))
3034 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3036 (defun Info-goto-index ()
3037 "Go to the first index node."
3038 (let ((node (car (Info-index-nodes))))
3039 (or node
(error "No index"))
3040 (Info-goto-node node
)))
3043 (defun Info-index (topic)
3044 "Look up a string TOPIC in the index for this manual and go to that entry.
3045 If there are no exact matches to the specified topic, this chooses
3046 the first match which is a case-insensitive substring of a topic.
3047 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3048 Give an empty topic name to go to the Index node itself."
3051 (let ((completion-ignore-case t
)
3052 (Info-complete-menu-buffer (clone-buffer))
3053 (Info-complete-nodes (Info-index-nodes))
3054 (Info-history-list nil
))
3055 (if (equal Info-current-file
"dir")
3056 (error "The Info directory node has no index; use m to select a manual"))
3058 (with-current-buffer Info-complete-menu-buffer
3060 (completing-read "Index topic: " 'Info-complete-menu-item
))
3061 (kill-buffer Info-complete-menu-buffer
)))))
3062 (if (equal Info-current-file
"dir")
3063 (error "The Info directory node has no index; use m to select a manual"))
3064 ;; Strip leading colon in topic; index format does not allow them.
3065 (if (and (stringp topic
)
3066 (> (length topic
) 0)
3067 (= (aref topic
0) ?
:))
3068 (setq topic
(substring topic
1)))
3069 (let ((orignode Info-current-node
)
3070 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3071 (regexp-quote topic
)))
3072 node
(nodes (Info-index-nodes))
3073 (ohist-list Info-history-list
)
3074 (case-fold-search t
))
3076 (or (equal topic
"")
3079 ;; We bind Info-history to nil for internal node-switches so
3080 ;; that we don't put junk in the history. In the first
3081 ;; Info-goto-index call, above, we do update the history
3082 ;; because that is what the user's previous node choice into it.
3087 (goto-char (point-min))
3088 (while (re-search-forward pattern nil t
)
3089 (push (list (match-string-no-properties 1)
3090 (match-string-no-properties 2)
3092 (string-to-number (concat "0"
3095 (setq nodes
(cdr nodes
) node
(car nodes
)))
3096 (Info-goto-node node
))
3099 (Info-goto-node orignode
)
3100 (error "No `%s' in index" topic
)))
3101 ;; Here it is a feature that assoc is case-sensitive.
3102 (while (setq found
(assoc topic matches
))
3103 (setq exact
(cons found exact
)
3104 matches
(delq found matches
)))
3105 (setq Info-history-list ohist-list
)
3106 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3107 (Info-index-next 0)))))
3109 (defun Info-index-next (num)
3110 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3112 (or Info-index-alternatives
3113 (error "No previous `i' command"))
3115 (setq num
(+ num
(length Info-index-alternatives
))))
3117 (setq Info-index-alternatives
3118 (nconc (cdr Info-index-alternatives
)
3119 (list (car Info-index-alternatives
)))
3121 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3122 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3123 ;; Forward 2 lines less because `Info-find-node-2' initially
3124 ;; puts point to the 2nd line.
3125 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3126 (forward-line 3) ; don't search in headers
3127 (let ((name (car (car Info-index-alternatives
))))
3128 (Info-find-index-name name
)))
3129 (message "Found `%s' in %s. %s"
3130 (car (car Info-index-alternatives
))
3131 (nth 2 (car Info-index-alternatives
))
3132 (if (cdr Info-index-alternatives
)
3133 (format "(%s total; use `%s' for next)"
3134 (length Info-index-alternatives
)
3135 (key-description (where-is-internal
3136 'Info-index-next overriding-local-map
3140 (defun Info-find-index-name (name)
3141 "Move point to the place within the current node where NAME is defined."
3142 (let ((case-fold-search t
))
3143 (if (or (re-search-forward (format
3144 "[a-zA-Z]+: %s\\( \\|$\\)"
3145 (regexp-quote name
)) nil t
)
3146 ;; Find a function definition with a return type.
3147 (re-search-forward (format
3148 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3149 (regexp-quote name
)) nil t
)
3150 (search-forward (format "`%s'" name
) nil t
)
3151 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3153 (format "`%s'" (substring name
0 (match-beginning 1)))
3155 (search-forward name nil t
)
3156 ;; Try again without the " <1>" makeinfo can append
3157 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3158 (Info-find-index-name (match-string 1 name
))))
3159 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3160 (goto-char (point-min)))))
3162 (add-to-list 'Info-virtual-nodes
3163 '("\\`\\*Index.*\\*\\'"
3164 (find-node . Info-virtual-index-find-node
)
3168 (defvar Info-virtual-index-nodes nil
3169 "Alist of cached matched index search nodes.
3170 Each element is ((FILENAME . TOPIC) MATCHES) where
3171 FILENAME is the file name of the manual,
3172 TOPIC is the search string given as an argument to `Info-virtual-index',
3173 MATCHES is a list of index matches found by `Info-index'.")
3175 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3176 "Index-specific implementation of `Info-find-node-2'."
3177 ;; Generate Index-like menu of matches
3178 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3179 ;; Generate Index-like menu of matches
3180 (let* ((topic (match-string 1 nodename
))
3181 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3182 Info-virtual-index-nodes
))))
3183 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3184 (or filename Info-current-file
) nodename
))
3185 (insert "Info Virtual Index\n")
3186 (insert "******************\n\n")
3187 (insert "Index entries that match `" topic
"':\n\n")
3188 (insert "\0\b[index\0\b]\n")
3190 (insert "No matches found.\n")
3191 (insert "* Menu:\n\n")
3192 (dolist (entry matches
)
3193 (insert (format "* %-38s %s.%s\n"
3194 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3197 (format " (line %s)" (nth 3 entry
))
3199 ;; Else, Generate a list of previous search results
3200 (let ((nodes (reverse Info-virtual-index-nodes
)))
3201 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3202 (or filename Info-current-file
) nodename
))
3203 (insert "Info Virtual Index\n")
3204 (insert "******************\n\n")
3205 (insert "This is a list of search results produced by\n"
3206 "`Info-virtual-index' for the current manual.\n\n")
3207 (insert "* Menu:\n\n")
3208 (dolist (nodeinfo nodes
)
3209 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3211 (format "* %-20s %s.\n"
3212 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3213 (cdr (nth 0 nodeinfo
)))))))))
3215 (defun Info-virtual-index (topic)
3216 "Show a node with all lines in the index containing a string TOPIC.
3217 Like `Info-index' but displays a node with index search results.
3218 Give an empty topic name to go to the node with links to previous
3220 ;; `interactive' is a copy from `Info-index'
3223 (let ((completion-ignore-case t
)
3224 (Info-complete-menu-buffer (clone-buffer))
3225 (Info-complete-nodes (Info-index-nodes))
3226 (Info-history-list nil
))
3227 (if (equal Info-current-file
"dir")
3228 (error "The Info directory node has no index; use m to select a manual"))
3230 (with-current-buffer Info-complete-menu-buffer
3232 (completing-read "Index topic: " 'Info-complete-menu-item
))
3233 (kill-buffer Info-complete-menu-buffer
)))))
3234 (if (equal topic
"")
3235 (Info-find-node Info-current-file
"*Index*")
3236 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3237 (let ((orignode Info-current-node
)
3238 (ohist-list Info-history-list
))
3239 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3241 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3242 Info-virtual-index-nodes
)
3243 ;; Clean up unneccessary side-effects of `Info-index'.
3244 (setq Info-history-list ohist-list
)
3245 (Info-goto-node orignode
)
3247 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3249 (add-to-list 'Info-virtual-files
3250 '("\\`\\*Apropos\\*\\'"
3251 (toc-nodes . Info-apropos-toc-nodes
)
3252 (find-file . Info-apropos-find-file
)
3253 (find-node . Info-apropos-find-node
)
3257 (defvar Info-apropos-file
"*Apropos*"
3258 "Info file name of the virtual manual for matches of `info-apropos'.")
3260 (defvar Info-apropos-nodes nil
3261 "Alist of cached apropos matched nodes.
3262 Each element is (NODENAME STRING MATCHES) where
3263 NODENAME is the name of the node that holds the search result,
3264 STRING is the search string given as an argument to `info-apropos',
3265 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3267 (defun Info-apropos-toc-nodes (filename)
3268 "Apropos-specific implementation of `Info-toc-nodes'."
3269 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3271 ("Top" nil nil
,nodes
)
3272 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3274 (defun Info-apropos-find-file (filename &optional _noerror
)
3275 "Apropos-specific implementation of `Info-find-file'."
3278 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3279 "Apropos-specific implementation of `Info-find-node-2'."
3280 (if (equal nodename
"Top")
3281 ;; Generate Top menu
3282 (let ((nodes (reverse Info-apropos-nodes
)))
3283 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3284 Info-apropos-file nodename
))
3285 (insert "Apropos Index\n")
3286 (insert "*************\n\n")
3287 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3288 (insert "* Menu:\n\n")
3289 (dolist (nodeinfo nodes
)
3290 (insert (format "* %-20s %s.\n"
3291 (format "%s::" (nth 0 nodeinfo
))
3292 (nth 1 nodeinfo
)))))
3293 ;; Else, Generate Index-like menu of matches
3294 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3295 (matches (nth 2 nodeinfo
)))
3297 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3298 Info-apropos-file nodename
))
3299 (insert "Apropos Index\n")
3300 (insert "*************\n\n")
3301 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3302 (insert "\0\b[index\0\b]\n")
3304 (insert "No matches found.\n")
3305 (insert "* Menu:\n\n")
3306 (dolist (entry matches
)
3307 (insert (format "* %-38s (%s)%s.%s\n"
3308 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3312 (format " (line %s)" (nth 3 entry
))
3315 (defun Info-apropos-matches (string)
3316 "Collect STRING matches from all known Info files on your system.
3317 Return a list of matches where each element is in the format
3318 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3319 (unless (string= string
"")
3320 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3321 (regexp-quote string
)))
3322 (ohist Info-history
)
3323 (ohist-list Info-history-list
)
3324 (current-node Info-current-node
)
3325 (current-file Info-current-file
)
3326 manuals matches node nodes
)
3327 (let ((Info-fontify-maximum-menu-size nil
))
3329 ;; current-node and current-file are nil when they invoke info-apropos
3330 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3331 ;; case, we use (DIR)Top instead, to avoid signalling an error after
3332 ;; the search is complete.
3333 (when (null current-node
)
3334 (setq current-file Info-current-file
)
3335 (setq current-node Info-current-node
))
3336 (message "Searching indices...")
3337 (goto-char (point-min))
3338 (re-search-forward "\\* Menu: *\n" nil t
)
3339 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3340 ;; add-to-list makes sure we don't have duplicates in `manuals',
3341 ;; so that the following dolist loop runs faster.
3342 (add-to-list 'manuals
(match-string 1)))
3343 (dolist (manual (nreverse manuals
))
3344 (message "Searching %s" manual
)
3346 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3348 (Info-find-node manual
(car nodes
))
3351 (goto-char (point-min))
3352 (while (re-search-forward pattern nil t
)
3355 (match-string-no-properties 1)
3356 (match-string-no-properties 2)
3357 (match-string-no-properties 3))
3359 (setq nodes
(cdr nodes
) node
(car nodes
)))
3360 (Info-goto-node node
))))
3362 (message "%s" (if (eq (car-safe err
) 'error
)
3365 (Info-find-node current-file current-node
)
3366 (setq Info-history ohist
3367 Info-history-list ohist-list
)
3368 (message "Searching indices...done")
3369 (or (nreverse matches
) t
))))
3372 (defun info-apropos (string)
3373 "Grovel indices of all known Info files on your system for STRING.
3374 Build a menu of the possible matches."
3375 (interactive "sIndex apropos: ")
3376 (if (equal string
"")
3377 (Info-find-node Info-apropos-file
"Top")
3378 (let* ((nodes Info-apropos-nodes
) nodename
)
3379 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3380 (setq nodes
(cdr nodes
)))
3382 (Info-find-node Info-apropos-file
(car (car nodes
)))
3383 (setq nodename
(format "Index for `%s'" string
))
3384 (push (list nodename string
(Info-apropos-matches string
))
3386 (Info-find-node Info-apropos-file nodename
)))))
3388 (add-to-list 'Info-virtual-files
3389 '("\\`\\*Finder.*\\*\\'"
3390 (find-file . Info-finder-find-file
)
3391 (find-node . Info-finder-find-node
)
3394 (defvar Info-finder-file
"*Finder*"
3395 "Info file name of the virtual Info keyword finder manual.")
3397 (defun Info-finder-find-file (filename &optional _noerror
)
3398 "Finder-specific implementation of `Info-find-file'."
3401 (defvar finder-known-keywords
)
3402 (declare-function find-library-name
"find-func" (library))
3403 (declare-function finder-unknown-keywords
"finder" ())
3404 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3405 (defvar finder-keywords-hash
)
3406 (defvar package-alist
) ; finder requires package
3408 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3409 "Finder-specific implementation of `Info-find-node-2'."
3412 ((equal nodename
"Top")
3413 ;; Display Top menu with descriptions of the keywords
3414 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3415 Info-finder-file nodename
))
3416 (insert "Finder Keywords\n")
3417 (insert "***************\n\n")
3418 (insert "* Menu:\n\n")
3419 (dolist (assoc (append '((all .
"All package info")
3420 (unknown .
"unknown keywords"))
3421 finder-known-keywords
))
3422 (let ((keyword (car assoc
)))
3423 (insert (format "* %s %s.\n"
3424 (concat (symbol-name keyword
) ": "
3425 "kw:" (symbol-name keyword
) ".")
3427 ((equal nodename
"unknown")
3428 ;; Display unknown keywords
3429 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3430 Info-finder-file nodename
))
3431 (insert "Finder Unknown Keywords\n")
3432 (insert "***********************\n\n")
3433 (insert "* Menu:\n\n")
3436 (insert (format "* %-14s %s.\n"
3437 (concat (symbol-name (car assoc
)) "::")
3439 (finder-unknown-keywords)))
3440 ((equal nodename
"all")
3441 ;; Display all package info.
3442 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3443 Info-finder-file nodename
))
3444 (insert "Finder Package Info\n")
3445 (insert "*******************\n\n")
3446 (dolist (package package-alist
)
3447 (insert (format "%s - %s\n"
3448 (format "*Note %s::" (nth 0 package
))
3450 ((string-match "\\`kw:" nodename
)
3451 (setq nodename
(substring nodename
(match-end 0)))
3452 ;; Display packages that match the keyword
3453 ;; or the list of keywords separated by comma.
3454 (insert (format "\n\^_\nFile: %s, Node: kw:%s, Up: Top\n\n"
3455 Info-finder-file nodename
))
3456 (insert "Finder Packages\n")
3457 (insert "***************\n\n")
3459 "The following packages match the keyword `" nodename
"':\n\n")
3460 (insert "* Menu:\n\n")
3462 (mapcar 'intern
(if (string-match-p "," nodename
)
3463 (split-string nodename
",[ \t\n]*" t
)
3466 (dolist (kw keywords
)
3467 (push (copy-tree (gethash kw finder-keywords-hash
)) hits
))
3468 (setq hits
(delete-dups (apply 'append hits
)))
3469 (dolist (package hits
)
3470 (setq desc
(cdr-safe (assq package package-alist
)))
3471 (when (vectorp desc
)
3472 (insert (format "* %-16s %s.\n"
3473 (concat (symbol-name package
) "::")
3476 ;; Display commentary section
3477 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3478 Info-finder-file nodename
))
3479 (insert "Finder Commentary\n")
3480 (insert "*****************\n\n")
3482 "Commentary section of the package `" nodename
"':\n\n")
3483 (let ((str (lm-commentary (find-library-name nodename
))))
3485 (insert "Can't find any Commentary section\n\n")
3489 (goto-char (point-min))
3490 (delete-blank-lines)
3491 (goto-char (point-max))
3492 (delete-blank-lines)
3493 (goto-char (point-min))
3494 (while (re-search-forward "^;+ ?" nil t
)
3495 (replace-match "" nil nil
))
3496 (buffer-string))))))))
3499 (defun info-finder (&optional keywords
)
3500 "Display descriptions of the keywords in the Finder virtual manual.
3501 In interactive use, a prefix argument directs this command to read
3502 a list of keywords separated by comma. After that, it displays a node
3503 with a list of packages that contain all specified keywords."
3505 (when current-prefix-arg
3508 (completing-read-multiple
3509 "Keywords (separated by comma): "
3510 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3511 (finder-unknown-keywords))))
3515 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3516 (Info-find-node Info-finder-file
"Top")))
3519 (defun Info-undefined ()
3520 "Make command be undefined in Info."
3525 "Enter the Info tutorial."
3527 (delete-other-windows)
3528 (Info-find-node "info"
3529 (if (< (window-height) 23)
3533 (defun Info-summary ()
3534 "Display a brief summary of all Info commands."
3536 (save-window-excursion
3537 (switch-to-buffer "*Help*")
3538 (setq buffer-read-only nil
)
3540 (insert (documentation 'Info-mode
))
3542 (goto-char (point-min))
3544 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3545 (message (if flag
"Type Space to see more"
3546 "Type Space to return to Info"))
3547 (if (not (eq ?\s
(setq ch
(read-event))))
3548 (progn (setq unread-command-events
(list ch
)) nil
)
3551 (bury-buffer "*Help*")))
3553 (defun Info-get-token (pos start all
&optional errorstring
)
3554 "Return the token around POS.
3555 POS must be somewhere inside the token.
3556 START is a regular expression which will match the
3557 beginning of the tokens delimited string.
3558 ALL is a regular expression with a single
3559 parenthesized subpattern which is the token to be
3560 returned. E.g. '{\(.*\)}' would return any string
3561 enclosed in braces around POS.
3562 ERRORSTRING optional fourth argument, controls action on no match:
3565 a string: signal an error, using that string."
3566 (let ((case-fold-search t
))
3569 ;; First look for a match for START that goes across POS.
3570 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3571 (not (looking-at start
)))
3573 ;; If we did not find one, search back for START
3574 ;; (this finds only matches that end at or before POS).
3575 (or (looking-at start
)
3578 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3580 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3581 (not (setq found
(and (<= (match-beginning 0) pos
)
3582 (> (match-end 0) pos
))))))
3583 (if (and found
(<= (match-beginning 0) pos
)
3584 (> (match-end 0) pos
))
3585 (match-string-no-properties 1)
3586 (cond ((null errorstring
)
3592 (error "No %s around position %d" errorstring pos
))))))))
3594 (defun Info-mouse-follow-nearest-node (click)
3595 "\\<Info-mode-map>Follow a node reference near point.
3596 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3597 At end of the node's text, moves to the next node, or up if none."
3599 (mouse-set-point click
)
3600 (and (not (Info-follow-nearest-node))
3601 (save-excursion (forward-line 1) (eobp))
3602 (Info-next-preorder)))
3604 (defun Info-follow-nearest-node (&optional fork
)
3605 "Follow a node reference near point.
3606 If point is on a reference, follow that reference. Otherwise,
3607 if point is in a menu item description, follow that menu item.
3609 If FORK is non-nil (interactively with a prefix arg), show the node in
3611 If FORK is a string, it is the name to use for the new buffer."
3613 (or (Info-try-follow-nearest-node fork
)
3614 (when (save-excursion
3615 (search-backward "\n* menu:" nil t
))
3618 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3619 (beginning-of-line 0))
3620 (when (looking-at "\\* +\\([^\t\n]*\\):")
3622 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3624 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3625 ;; Don't raise an error when mouse-1 is bound to this - it's
3626 ;; often used to simply select the window or frame.
3627 (eq 'mouse-1
(event-basic-type last-input-event
)))
3628 (error "Point neither on reference nor in menu item description")))
3630 ;; Common subroutine.
3631 (defun Info-try-follow-nearest-node (&optional fork
)
3632 "Follow a node reference near point. Return non-nil if successful.
3633 If FORK is non-nil, it is passed to `Info-goto-node'."
3636 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3637 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3640 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3641 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3642 (Info-follow-reference node fork
))
3643 ;; menu item: node name
3644 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3645 (Info-goto-node node fork
))
3646 ;; menu item: node name or index entry
3647 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3650 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3651 (Info-goto-node node fork
))
3652 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3653 (Info-goto-node node fork
))
3654 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3655 (Info-goto-node node fork
))
3656 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3657 (Info-goto-node "Top" fork
))
3658 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3659 (Info-goto-node node fork
)))
3662 (defun Info-mouse-follow-link (click)
3663 "Follow a link where you click."
3665 (let* ((position (event-start click
))
3666 (posn-string (and position
(posn-string position
)))
3667 (string (car-safe posn-string
))
3668 (string-pos (cdr-safe posn-string
))
3669 (link-args (and string string-pos
3670 (get-text-property string-pos
'link-args string
))))
3672 (Info-goto-node link-args
))))
3675 (defvar Info-mode-map
3676 (let ((map (make-keymap)))
3677 (suppress-keymap map
)
3678 (define-key map
"." 'beginning-of-buffer
)
3679 (define-key map
" " 'Info-scroll-up
)
3680 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3681 (define-key map
"\t" 'Info-next-reference
)
3682 (define-key map
"\e\t" 'Info-prev-reference
)
3683 (define-key map
[backtab] 'Info-prev-reference)
3684 (define-key map "1" 'Info-nth-menu-item)
3685 (define-key map "2" 'Info-nth-menu-item)
3686 (define-key map "3" 'Info-nth-menu-item)
3687 (define-key map "4" 'Info-nth-menu-item)
3688 (define-key map "5" 'Info-nth-menu-item)
3689 (define-key map "6" 'Info-nth-menu-item)
3690 (define-key map "7" 'Info-nth-menu-item)
3691 (define-key map "8" 'Info-nth-menu-item)
3692 (define-key map "9" 'Info-nth-menu-item)
3693 (define-key map "0" 'undefined)
3694 (define-key map "?" 'Info-summary)
3695 (define-key map "]" 'Info-forward-node)
3696 (define-key map "[" 'Info-backward-node)
3697 (define-key map "<" 'Info-top-node)
3698 (define-key map ">" 'Info-final-node)
3699 (define-key map "b" 'beginning-of-buffer)
3700 (put 'beginning-of-buffer :advertised-binding "b")
3701 (define-key map "d" 'Info-directory)
3702 (define-key map "e" 'Info-edit)
3703 (define-key map "f" 'Info-follow-reference)
3704 (define-key map "g" 'Info-goto-node)
3705 (define-key map "h" 'Info-help)
3706 (define-key map "i" 'Info-index)
3707 (define-key map "I" 'Info-virtual-index)
3708 (define-key map "l" 'Info-history-back)
3709 (define-key map "L" 'Info-history)
3710 (define-key map "m" 'Info-menu)
3711 (define-key map "n" 'Info-next)
3712 (define-key map "p" 'Info-prev)
3713 (define-key map "q" 'Info-exit)
3714 (define-key map "r" 'Info-history-forward)
3715 (define-key map "s" 'Info-search)
3716 (define-key map "S" 'Info-search-case-sensitively)
3717 (define-key map "\M-n" 'clone-buffer)
3718 (define-key map "t" 'Info-top-node)
3719 (define-key map "T" 'Info-toc)
3720 (define-key map "u" 'Info-up)
3721 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3722 (define-key map "w" 'Info-copy-current-node-name)
3723 (define-key map "c" 'Info-copy-current-node-name)
3724 ;; `^' for consistency with `dired-up-directory'.
3725 (define-key map "^" 'Info-up)
3726 (define-key map "," 'Info-index-next)
3727 (define-key map "\177" 'Info-scroll-down)
3728 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3729 (define-key map [follow-link] 'mouse-face)
3731 "Keymap containing Info commands.")
3734 (defun Info-check-pointer (item)
3735 "Non-nil if ITEM is present in this node."
3737 (Info-extract-pointer item)
3741 Info-mode-menu Info-mode-map
3742 "Menu for Info files."
3744 ["Up" Info-up :active (Info-check-pointer "up")
3745 :help "Go up in the Info tree"]
3746 ["Next" Info-next :active (Info-check-pointer "next")
3747 :help "Go to the next node"]
3748 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3749 :help "Go to the previous node"]
3750 ["Backward" Info-backward-node
3751 :help "Go backward one node, considering all as a sequence"]
3752 ["Forward" Info-forward-node
3753 :help "Go forward one node, considering all as a sequence"]
3754 ["Beginning" beginning-of-buffer
3755 :help "Go to beginning of this node"]
3756 ["Top" Info-top-node
3757 :help "Go to top node of file"]
3758 ["Final Node" Info-final-node
3759 :help "Go to final node in this file"]
3760 ("Menu Item" ["You should never see this" report-emacs-bug t])
3761 ("Reference" ["You should never see this" report-emacs-bug t])
3762 ["Search..." Info-search
3763 :help "Search for regular expression in this Info file"]
3764 ["Search Next" Info-search-next
3765 :help "Search for another occurrence of regular expression"]
3766 ["Go to Node..." Info-goto-node
3767 :help "Go to a named node"]
3768 ["Back in history" Info-history-back :active Info-history
3769 :help "Go back in history to the last node you were at"]
3770 ["Forward in history" Info-history-forward :active Info-history-forward
3771 :help "Go forward in history"]
3772 ["History" Info-history :active Info-history-list
3773 :help "Go to menu of visited nodes"]
3774 ["Table of Contents" Info-toc
3775 :help "Go to table of contents"]
3777 ["Lookup a String..." Info-index
3778 :help "Look for a string in the index items"]
3779 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3780 :help "Look for another occurrence of previous item"]
3781 ["Lookup a string and display index of results..." Info-virtual-index
3782 :help "Look for a string in the index items and display node with results"]
3783 ["Lookup a string in all indices..." info-apropos
3784 :help "Look for a string in the indices of all manuals"])
3785 ["Copy Node Name" Info-copy-current-node-name
3786 :help "Copy the name of the current node into the kill ring"]
3787 ["Clone Info buffer" clone-buffer
3788 :help "Create a twin copy of the current Info buffer."]
3789 ["Exit" Info-exit :help "Stop reading Info"]))
3792 (defvar info-tool-bar-map
3793 (let ((map (make-sparse-keymap)))
3794 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3798 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3802 (define-key-after map [separator-1] menu-bar-separator)
3803 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3805 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3807 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
3809 (define-key-after map [separator-2] menu-bar-separator)
3810 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
3812 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3813 (define-key-after map [separator-3] menu-bar-separator)
3814 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3816 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
3818 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
3822 (defvar Info-menu-last-node nil)
3823 ;; Last node the menu was created for.
3824 ;; Value is a list, (FILE-NAME NODE-NAME).
3826 (defun Info-menu-update ()
3827 "Update the Info menu for the current node."
3829 (if (or (not (eq major-mode 'Info-mode))
3830 (equal (list Info-current-file Info-current-node)
3831 Info-menu-last-node))
3833 ;; Update menu menu.
3834 (let* ((Info-complete-menu-buffer (current-buffer))
3835 (items (nreverse (condition-case nil
3836 (Info-complete-menu-item "" nil t)
3840 (while (and items (< number 9))
3841 (setq current (car items)
3844 (setq entries (cons `[,current
3845 (Info-menu ,current)
3846 :keys ,(format "%d" number)]
3849 (setq entries (cons ["Other..." Info-menu t] entries)))
3851 (setq entries (list ["No menu" nil nil] nil :active)))
3852 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3853 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3855 str i entries current
3857 (case-fold-search t))
3859 (goto-char (point-min))
3860 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3861 (setq str (match-string 1))
3863 (while (setq i (string-match "[ \n\t]+" str i))
3864 (setq str (concat (substring str 0 i) " "
3865 (substring str (match-end 0))))
3869 (while (and items (< number 9))
3870 (setq current (car items)
3873 (setq entries (cons `[,current
3874 (Info-follow-reference ,current)
3878 (setq entries (cons ["Other..." Info-follow-reference t]
3881 (setq entries (list ["No references" nil nil] nil :active)))
3882 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3883 ;; Update last seen node.
3884 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3885 ;; Try to avoid entering infinite beep mode in case of errors.
3889 (defun Info-copy-current-node-name (&optional arg)
3890 "Put the name of the current Info node into the kill ring.
3891 The name of the Info file is prepended to the node name in parentheses.
3892 With a zero prefix arg, put the name inside a function call to `info'."
3894 (unless Info-current-node
3895 (error "No current Info node"))
3896 (let ((node (if (stringp Info-current-file)
3897 (concat "(" (file-name-nondirectory Info-current-file) ") "
3898 Info-current-node))))
3899 (if (zerop (prefix-numeric-value arg))
3900 (setq node (concat "(info \"" node "\")")))
3901 (unless (stringp Info-current-file)
3902 (setq node (format "(Info-find-node '%S '%S)"
3903 Info-current-file Info-current-node)))
3905 (message "%s" node)))
3908 ;; Info mode is suitable only for specially formatted data.
3909 (put 'Info-mode 'mode-class 'special)
3910 (put 'Info-mode 'no-clone-indirect t)
3912 (defvar tool-bar-map)
3913 (defvar bookmark-make-record-function)
3915 (defvar Info-mode-syntax-table
3916 (let ((st (copy-syntax-table text-mode-syntax-table)))
3917 ;; Use punctuation syntax for apostrophe because of
3918 ;; extensive use of quotes like `this' in Info manuals.
3919 (modify-syntax-entry ?' "." st)
3921 "Syntax table used in `Info-mode'.")
3923 ;; Autoload cookie needed by desktop.el
3925 (define-derived-mode Info-mode nil "Info"
3926 "Info mode provides commands for browsing through the Info documentation tree.
3927 Documentation in Info is divided into \"nodes\", each of which discusses
3928 one topic and contains references to other nodes which discuss related
3929 topics. Info has commands to follow the references and show you other nodes.
3932 \\[Info-help] Invoke the Info tutorial.
3933 \\[Info-exit] Quit Info: reselect previously selected buffer.
3935 Selecting other nodes:
3936 \\[Info-mouse-follow-nearest-node]
3937 Follow a node reference you click on.
3938 This works with menu items, cross references, and
3939 the \"next\", \"previous\" and \"up\", depending on where you click.
3940 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3941 \\[Info-next] Move to the \"next\" node of this node.
3942 \\[Info-prev] Move to the \"previous\" node of this node.
3943 \\[Info-up] Move \"up\" from this node.
3944 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3945 Picking a menu item causes another node to be selected.
3946 \\[Info-directory] Go to the Info directory node.
3947 \\[Info-top-node] Go to the Top node of this file.
3948 \\[Info-final-node] Go to the final node in this file.
3949 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3950 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3951 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3952 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3953 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3954 \\[Info-history-back] Move back in history to the last node you were at.
3955 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3956 \\[Info-history] Go to menu of visited nodes.
3957 \\[Info-toc] Go to table of contents of the current Info file.
3959 Moving within a node:
3960 \\[Info-scroll-up] Normally, scroll forward a full screen.
3961 Once you scroll far enough in a node that its menu appears on the
3962 screen but after point, the next scroll moves into its first
3963 subnode. When after all menu items (or if there is no menu),
3964 move up to the parent node.
3965 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3966 already visible, try to go to the previous menu entry, or up
3968 \\[beginning-of-buffer] Go to beginning of node.
3971 \\[Info-search] Search through this Info file for specified regexp,
3972 and select the node in which the next occurrence is found.
3973 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3974 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3975 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3976 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3977 \\[Info-virtual-index] Look for a string and display the index node with results.
3978 \\[info-apropos] Look for a string in the indices of all manuals.
3979 \\[Info-goto-node] Move to node specified by name.
3980 You may include a filename as well, as (FILENAME)NODENAME.
3981 1 .. 9 Pick first ... ninth item in node's menu.
3982 Every third `*' is highlighted to help pick the right number.
3983 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3984 \\[clone-buffer] Select a new cloned Info buffer in another window.
3985 \\[universal-argument] \\[info] Move to new Info file with completion.
3986 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3987 :syntax-table Info-mode-syntax-table
3988 :abbrev-table text-mode-abbrev-table
3990 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3991 (setq case-fold-search t)
3992 (setq buffer-read-only t)
3993 (make-local-variable 'Info-current-file)
3994 (make-local-variable 'Info-current-subfile)
3995 (make-local-variable 'Info-current-node)
3996 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
3997 (set (make-local-variable 'Info-tag-table-buffer) nil)
3998 (make-local-variable 'Info-history)
3999 (make-local-variable 'Info-history-forward)
4000 (make-local-variable 'Info-index-alternatives)
4001 (if Info-use-header-line ; do not override global header lines
4002 (setq header-line-format
4003 '(:eval (get-text-property (point-min) 'header-line))))
4004 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4005 ;; This is for the sake of the invisible text we use handling titles.
4006 (set (make-local-variable 'line-move-ignore-invisible) t)
4007 (set (make-local-variable 'desktop-save-buffer)
4008 'Info-desktop-buffer-misc-data)
4009 (set (make-local-variable 'widen-automatically) nil)
4010 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4011 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4012 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4013 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4014 (set (make-local-variable 'isearch-search-fun-function)
4015 'Info-isearch-search)
4016 (set (make-local-variable 'isearch-wrap-function)
4018 (set (make-local-variable 'isearch-push-state-function)
4019 'Info-isearch-push-state)
4020 (set (make-local-variable 'isearch-filter-predicate)
4021 'Info-isearch-filter)
4022 (set (make-local-variable 'search-whitespace-regexp)
4023 Info-search-whitespace-regexp)
4024 (set (make-local-variable 'revert-buffer-function)
4025 'Info-revert-buffer-function)
4026 (Info-set-mode-line)
4027 (set (make-local-variable 'bookmark-make-record-function)
4028 'Info-bookmark-make-record))
4030 ;; When an Info buffer is killed, make sure the associated tags buffer
4032 (defun Info-kill-buffer ()
4033 (and (eq major-mode 'Info-mode)
4034 Info-tag-table-buffer
4035 (kill-buffer Info-tag-table-buffer)))
4037 ;; Placed on `clone-buffer-hook'.
4038 (defun Info-clone-buffer ()
4039 (when (bufferp Info-tag-table-buffer)
4040 (setq Info-tag-table-buffer
4041 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4042 (let ((m Info-tag-table-marker))
4044 (setq Info-tag-table-marker
4045 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4046 (with-current-buffer Info-tag-table-buffer
4047 (copy-marker (marker-position m)))
4050 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4051 (set-keymap-parent map text-mode-map)
4052 (define-key map "\C-c\C-c" 'Info-cease-edit)
4054 "Local keymap used within `e' command of Info.")
4056 ;; Info-edit mode is suitable only for specially formatted data.
4057 (put 'Info-edit-mode 'mode-class 'special)
4059 (defun Info-edit-mode ()
4060 "Major mode for editing the contents of an Info node.
4061 Like text mode with the addition of `Info-cease-edit'
4062 which returns to Info mode for browsing.
4064 (use-local-map Info-edit-map)
4065 (setq major-mode 'Info-edit-mode)
4066 (setq mode-name "Info Edit")
4067 (kill-local-variable 'mode-line-buffer-identification)
4068 (setq buffer-read-only nil)
4069 (force-mode-line-update)
4070 (buffer-enable-undo (current-buffer))
4071 (run-mode-hooks 'Info-edit-mode-hook))
4074 "Edit the contents of this Info node.
4075 Allowed only if variable `Info-enable-edit' is non-nil."
4077 (or Info-enable-edit
4078 (error "Editing Info nodes is not enabled"))
4080 (message "%s" (substitute-command-keys
4081 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4083 (defun Info-cease-edit ()
4084 "Finish editing Info node; switch back to Info proper."
4086 ;; Do this first, so nothing has changed if user C-g's at query.
4087 (and (buffer-modified-p)
4088 (y-or-n-p "Save the file? ")
4090 (use-local-map Info-mode-map)
4091 (setq major-mode 'Info-mode)
4092 (setq mode-name "Info")
4093 (Info-set-mode-line)
4094 (setq buffer-read-only t)
4095 (force-mode-line-update)
4096 (and (marker-position Info-tag-table-marker)
4098 (message "Tags may have changed. Use Info-tagify if necessary")))
4100 (defvar Info-file-list-for-emacs
4101 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4102 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4103 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4104 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4105 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4106 ("copyright" . "autotype") ("executable" . "autotype")
4107 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4108 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4109 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4110 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4111 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4112 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4113 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4114 ("rfc2045" . "emacs-mime")
4115 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4116 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4117 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4118 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4119 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4120 ("mml" . "emacs-mime"))
4121 "List of Info files that describe Emacs commands.
4122 An element can be a file name, or a list of the form (PREFIX . FILE)
4123 where PREFIX is a name prefix and FILE is the file to look in.
4124 If the element is just a file name, the file name also serves as the prefix.")
4126 (defun Info-find-emacs-command-nodes (command)
4127 "Return a list of locations documenting COMMAND.
4128 The `info-file' property of COMMAND says which Info manual to search.
4129 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4130 defines heuristics for which Info manual to try.
4131 The locations are of the format used in `Info-history', i.e.
4132 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4133 in the first element of the returned list (which is treated specially in
4134 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4135 (let ((where '()) line-number
4136 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4137 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4138 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4139 (info-file "emacs")) ;default
4140 ;; Determine which Info file this command is documented in.
4141 (if (get command 'info-file)
4142 (setq info-file (get command 'info-file))
4143 ;; If it doesn't say explicitly, test its name against
4144 ;; various prefixes that we know.
4145 (let ((file-list Info-file-list-for-emacs))
4147 (let* ((elt (car file-list))
4148 (name (if (consp elt)
4151 (file (if (consp elt) (cdr elt) elt))
4152 (case-fold-search nil)
4153 (regexp (concat "\\`" (regexp-quote name)
4155 (if (string-match regexp (symbol-name command))
4156 (setq info-file file file-list nil))
4157 (setq file-list (cdr file-list))))))
4158 (Info-find-node info-file "Top")
4159 ;; Bind Info-history to nil, to prevent the index nodes from
4160 ;; getting into the node history.
4161 (let ((Info-history nil)
4162 (Info-history-list nil)
4163 node (nodes (Info-index-nodes)))
4164 (Info-goto-node (car nodes))
4167 (goto-char (point-min))
4168 (while (re-search-forward cmd-desc nil t)
4170 (cons (list Info-current-file
4171 (match-string-no-properties 2)
4174 (setq line-number (and (match-beginning 3)
4175 (string-to-number (match-string 3)))))
4176 (and (setq nodes (cdr nodes) node (car nodes))))
4177 (Info-goto-node node)))
4178 (if (and line-number where)
4179 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4183 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4185 (defun Info-goto-emacs-command-node (command)
4186 "Go to the Info node in the Emacs manual for command COMMAND.
4187 The command is found by looking up in Emacs manual's indices
4188 or in another manual found via COMMAND's `info-file' property or
4189 the variable `Info-file-list-for-emacs'.
4190 COMMAND must be a symbol or string."
4191 (interactive "CFind documentation for command: ")
4192 ;; If command is given as a string, convert it to a symbol.
4193 (if (stringp command)
4194 (setq command (intern command)))
4195 (or (commandp command)
4196 (signal 'wrong-type-argument (list 'commandp command)))
4197 (let ((where (Info-find-emacs-command-nodes command)))
4199 (let ((num-matches (length where)))
4200 ;; Get Info running, and pop to it in another window.
4201 (save-window-excursion
4203 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4204 ;; Bind Info-history to nil, to prevent the last Index node
4205 ;; visited by Info-find-emacs-command-nodes from being
4206 ;; pushed onto the history.
4207 (let ((Info-history nil) (Info-history-list nil)
4208 (line-number (nth 2 (car where))))
4209 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4210 (if (and (integerp line-number) (> line-number 0))
4211 (forward-line (1- line-number))))
4212 (if (> num-matches 1)
4214 ;; (car where) will be pushed onto Info-history
4215 ;; when/if they go to another node. Put the other
4216 ;; nodes that were found on the history.
4217 (setq Info-history (nconc (cdr where) Info-history))
4218 (message "Found %d other entr%s. Use %s to see %s."
4220 (if (> num-matches 2) "ies" "y")
4221 (substitute-command-keys "\\[Info-history-back]")
4222 (if (> num-matches 2) "them" "it")))))
4223 (error "Couldn't find documentation for %s" command))))
4225 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4227 (defun Info-goto-emacs-key-command-node (key)
4228 "Go to the node in the Emacs manual which describes the command bound to KEY.
4230 Interactively, if the binding is `execute-extended-command', a command is read.
4231 The command is found by looking up in Emacs manual's indices
4232 or in another manual found via COMMAND's `info-file' property or
4233 the variable `Info-file-list-for-emacs'."
4234 (interactive "kFind documentation for key: ")
4235 (let ((command (key-binding key)))
4236 (cond ((null command)
4237 (message "%s is undefined" (key-description key)))
4238 ((and (called-interactively-p 'interactive)
4239 (eq command 'execute-extended-command))
4240 (Info-goto-emacs-command-node
4241 (read-command "Find documentation for command: ")))
4243 (Info-goto-emacs-command-node command)))))
4245 (defvar Info-next-link-keymap
4246 (let ((keymap (make-sparse-keymap)))
4247 (define-key keymap [header-line mouse-1] 'Info-next)
4248 (define-key keymap [header-line mouse-2] 'Info-next)
4249 (define-key keymap [header-line down-mouse-1] 'ignore)
4250 (define-key keymap [mouse-2] 'Info-next)
4251 (define-key keymap [follow-link] 'mouse-face)
4253 "Keymap to put on the Next link in the text or the header line.")
4255 (defvar Info-prev-link-keymap
4256 (let ((keymap (make-sparse-keymap)))
4257 (define-key keymap [header-line mouse-1] 'Info-prev)
4258 (define-key keymap [header-line mouse-2] 'Info-prev)
4259 (define-key keymap [header-line down-mouse-1] 'ignore)
4260 (define-key keymap [mouse-2] 'Info-prev)
4261 (define-key keymap [follow-link] 'mouse-face)
4263 "Keymap to put on the Prev link in the text or the header line.")
4265 (defvar Info-up-link-keymap
4266 (let ((keymap (make-sparse-keymap)))
4267 (define-key keymap [header-line mouse-1] 'Info-up)
4268 (define-key keymap [header-line mouse-2] 'Info-up)
4269 (define-key keymap [header-line down-mouse-1] 'ignore)
4270 (define-key keymap [mouse-2] 'Info-up)
4271 (define-key keymap [follow-link] 'mouse-face)
4273 "Keymap to put on the Up link in the text or the header line.")
4275 (defvar Info-link-keymap
4276 (let ((keymap (make-sparse-keymap)))
4277 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4278 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4279 (define-key keymap [header-line down-mouse-1] 'ignore)
4280 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4281 (define-key keymap [follow-link] 'mouse-face)
4283 "Keymap to put on the link in the text or the header line.")
4285 (defun Info-breadcrumbs ()
4286 (let ((nodes (Info-toc-nodes Info-current-file))
4287 (node Info-current-node)
4289 (depth Info-breadcrumbs-depth)
4292 ;; Get ancestors from the cached parent-children node info
4293 (while (and (not (equal "Top" node)) (> depth 0))
4294 (setq node (nth 1 (assoc node nodes)))
4295 (if node (push node crumbs))
4296 (setq depth (1- depth)))
4299 (when Info-use-header-line
4300 ;; Let it disappear if crumbs is nil.
4301 (nconc crumbs (list Info-current-node)))
4302 (when (or Info-use-header-line crumbs)
4303 ;; Add top node (and continuation if needed).
4305 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4306 crumbs (cons nil crumbs))))
4307 ;; Eliminate duplicate.
4309 (dolist (node crumbs)
4311 (if (not (equal node "Top")) node
4313 (if (stringp Info-current-file)
4314 (file-name-nondirectory Info-current-file)
4315 ;; Some legacy code can still use a symbol.
4316 Info-current-file)))))
4319 (if (null line) "" " > ")
4322 ((equal node Info-current-node)
4323 ;; No point linking to ourselves.
4324 (propertize text 'font-lock-face 'info-header-node))
4327 'mouse-face 'highlight
4328 'font-lock-face 'info-header-xref
4329 'help-echo "mouse-2: Go to node"
4330 'keymap Info-link-keymap
4331 'link-args text)))))))
4332 (setq line (concat line "\n")))
4333 ;; (font-lock-append-text-property 0 (length line)
4334 ;; 'font-lock-face 'header-line line)
4337 (defun Info-fontify-node ()
4340 (let* ((inhibit-read-only t)
4341 (case-fold-search t)
4343 (not-fontified-p ; the node hasn't already been fontified
4344 (not (let ((where (next-single-property-change (point-min)
4346 (and where (not (= where (point-max)))))))
4347 (fontify-visited-p ; visited nodes need to be re-fontified
4348 (and Info-fontify-visited-nodes
4349 ;; Don't take time to refontify visited nodes in huge nodes
4350 Info-fontify-maximum-menu-size
4351 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4354 ;; Fontify header line
4355 (goto-char (point-min))
4356 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4357 (goto-char (match-end 0))
4358 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4359 (goto-char (match-end 0))
4360 (let* ((nbeg (match-beginning 2))
4361 (nend (match-end 2))
4362 (tbeg (match-beginning 1))
4363 (tag (match-string 1)))
4364 (if (string-equal (downcase tag) "node")
4365 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4366 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4367 (put-text-property tbeg nend 'mouse-face 'highlight)
4368 (put-text-property tbeg nend
4370 (concat "mouse-2: Go to node "
4371 (buffer-substring nbeg nend)))
4372 ;; Always set up the text property keymap.
4373 ;; It will either be used in the buffer
4374 ;; or copied in the header line.
4378 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4379 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4380 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4382 ;; (when (> Info-breadcrumbs-depth 0)
4383 ;; (insert (Info-breadcrumbs)))
4385 ;; Treat header line.
4386 (when Info-use-header-line
4387 (goto-char (point-min))
4388 (let* ((header-end (line-end-position))
4390 ;; If we find neither Next: nor Prev: link, show the entire
4391 ;; node header. Otherwise, don't show the File: and Node:
4392 ;; parts, to avoid wasting precious space on information that
4393 ;; is available in the mode line.
4394 (if (re-search-forward
4395 "\\(next\\|up\\|prev[ious]*\\): "
4398 (goto-char (match-beginning 1))
4399 (buffer-substring (point) header-end))
4400 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4402 (concat "No next, prev or up links -- "
4403 (buffer-substring (point) header-end))
4404 (buffer-substring (point) header-end)))))
4405 (put-text-property (point-min) (1+ (point-min))
4407 (replace-regexp-in-string
4409 ;; Preserve text properties on duplicated `%'.
4410 (lambda (s) (concat s s)) header))
4411 ;; Hide the part of the first line
4412 ;; that is in the header, if it is just part.
4414 ((> Info-breadcrumbs-depth 0)
4415 (let ((ov (make-overlay (point-min) (1+ header-end))))
4416 (overlay-put ov 'display (Info-breadcrumbs))
4417 (overlay-put ov 'evaporate t)))
4419 ;; Hide the punctuation at the end, too.
4420 (skip-chars-backward " \t,")
4421 (put-text-property (point) header-end 'invisible t))))))
4424 (goto-char (point-min))
4425 (when (and font-lock-mode not-fontified-p)
4426 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4428 ;; Only consider it as an underlined title if the ASCII
4429 ;; underline has the same size as the text. A typical
4430 ;; counter example is when a continuation "..." is alone
4432 (= (string-width (match-string 1))
4433 (string-width (match-string 2))))
4434 (let* ((c (preceding-char))
4436 (cond ((= c ?*) 'info-title-1)
4437 ((= c ?=) 'info-title-2)
4438 ((= c ?-) 'info-title-3)
4439 (t 'info-title-4))))
4440 (put-text-property (match-beginning 1) (match-end 1)
4441 'font-lock-face face))
4442 ;; This is a serious problem for trying to handle multiple
4443 ;; frame types at once. We want this text to be invisible
4444 ;; on frames that can display the font above.
4445 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4446 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4447 '(invisible t front-sticky nil rear-nonsticky t)))))
4449 ;; Fontify cross references
4450 (goto-char (point-min))
4451 (when (or not-fontified-p fontify-visited-p)
4452 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4453 (let ((start (match-beginning 0))
4456 (when not-fontified-p
4457 (when Info-hide-note-references
4458 (when (and (not (eq Info-hide-note-references 'hide))
4459 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4460 ;; *Note is often used where *note should have been
4462 (skip-syntax-backward " ")
4463 (when (memq (char-before) '(?\( ?\[ ?\{))
4464 ;; Check whether the paren is preceded by
4465 ;; an end of sentence
4466 (skip-syntax-backward " ("))
4468 (cond ((save-match-data (looking-back "\\<see"))
4470 ((save-match-data (looking-back "\\<in"))
4472 ((memq (char-before) '(nil ?\. ?! ??))
4476 (search-forward "\n\n" start t)))
4480 (add-text-properties
4482 (or (save-match-data
4483 ;; Don't hide \n after *Note
4484 (let ((start1 (match-beginning 1)))
4485 (if (string-match "\n" (match-string 1))
4486 (+ start1 (match-beginning 0)))))
4489 `(display ,other-tag front-sticky nil rear-nonsticky t)
4490 '(invisible t front-sticky nil rear-nonsticky t))))
4491 (add-text-properties
4492 (match-beginning 2) (match-end 2)
4494 'help-echo (if (or (match-end 5)
4495 (not (equal (match-string 4) "")))
4496 (concat "mouse-2: go to " (or (match-string 5)
4498 "mouse-2: go to this node")
4499 'mouse-face 'highlight)))
4500 (when (or not-fontified-p fontify-visited-p)
4501 (setq rbeg (match-beginning 2)
4506 ;; Display visited nodes in a different face
4507 (if (and Info-fontify-visited-nodes
4509 (let* ((node (replace-regexp-in-string
4511 (replace-regexp-in-string
4513 (or (match-string-no-properties 5)
4514 (and (not (equal (match-string 4) ""))
4515 (match-string-no-properties 4))
4516 (match-string-no-properties 2)))))
4518 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4519 (file (if external-link-p
4520 (file-name-nondirectory
4521 (match-string-no-properties 1 node))
4523 (hl Info-history-list)
4526 (setq node (if (equal (match-string 2 node) "")
4528 (match-string-no-properties 2 node))))
4530 (if (and (string-equal node (nth 1 (car hl)))
4532 (if (and external-link-p
4533 (stringp (caar hl)))
4534 (file-name-nondirectory
4537 (setq res (car hl) hl nil)
4538 (setq hl (cdr hl))))
4539 res))) 'info-xref-visited 'info-xref))
4540 ;; For multiline ref, unfontify newline and surrounding whitespace
4544 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4545 (remove-text-properties (match-beginning 0)
4547 '(font-lock-face t))))))
4548 (when not-fontified-p
4549 (when (memq Info-hide-note-references '(t hide))
4550 (add-text-properties (match-beginning 3) (match-end 3)
4551 '(invisible t front-sticky nil rear-nonsticky t))
4552 ;; Unhide the file name of the external reference in parens
4553 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4554 (remove-text-properties (match-beginning 6) (match-end 6)
4555 '(invisible t front-sticky nil rear-nonsticky t)))
4556 ;; Unhide newline because hidden newlines cause too long lines
4558 (let ((beg3 (match-beginning 3))
4559 (end3 (match-end 3)))
4560 (if (and (string-match "\n[ \t]*" (match-string 3))
4561 (not (save-match-data
4563 (goto-char (1+ end3))
4564 (looking-at "[.)]*$")))))
4565 (remove-text-properties (+ beg3 (match-beginning 0))
4566 (+ beg3 (match-end 0))
4567 '(invisible t front-sticky nil rear-nonsticky t))))))
4568 (when (and Info-refill-paragraphs Info-hide-note-references)
4569 (push (set-marker (make-marker) start)
4570 paragraph-markers))))))
4572 ;; Refill paragraphs (experimental feature)
4573 (when (and not-fontified-p
4574 Info-refill-paragraphs
4576 (let ((fill-nobreak-invisible t)
4577 (fill-individual-varying-indent nil)
4578 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4579 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4580 (adaptive-fill-mode nil))
4581 (goto-char (point-max))
4582 (dolist (m paragraph-markers)
4586 (let ((beg (point)))
4587 (when (zerop (forward-paragraph))
4588 (fill-individual-paragraphs beg (point) nil nil)
4590 (set-marker m nil))))
4592 ;; Fontify menu items
4593 (goto-char (point-min))
4594 (when (and (or not-fontified-p fontify-visited-p)
4595 (search-forward "\n* Menu:" nil t)
4596 ;; Don't take time to annotate huge menus
4597 Info-fontify-maximum-menu-size
4598 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4601 (while (re-search-forward
4602 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4603 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4605 (when (match-beginning 1)
4606 (when not-fontified-p
4608 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4609 (put-text-property (match-beginning 0)
4610 (1+ (match-beginning 0))
4611 'font-lock-face 'info-menu-star)))
4612 (when not-fontified-p
4613 (add-text-properties
4614 (match-beginning 1) (match-end 1)
4616 'help-echo (if (and (match-end 3)
4617 (not (equal (match-string 3) "")))
4618 (concat "mouse-2: go to " (match-string 3))
4619 "mouse-2: go to this node")
4620 'mouse-face 'highlight)))
4621 (when (or not-fontified-p fontify-visited-p)
4623 (match-beginning 1) (match-end 1)
4625 ;; Display visited menu items in a different face
4626 (if (and Info-fontify-visited-nodes
4628 (let* ((node (if (equal (match-string 3) "")
4629 (match-string-no-properties 1)
4630 (match-string-no-properties 3)))
4632 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4633 (file (if external-link-p
4634 (file-name-nondirectory
4635 (match-string-no-properties 1 node))
4637 (hl Info-history-list)
4640 (setq node (if (equal (match-string 2 node) "")
4642 (match-string-no-properties 2 node))))
4644 (if (and (string-equal node (nth 1 (car hl)))
4646 (if (and external-link-p
4647 (stringp (caar hl)))
4648 (file-name-nondirectory
4651 (setq res (car hl) hl nil)
4652 (setq hl (cdr hl))))
4653 res))) 'info-xref-visited 'info-xref)))
4654 (when (and not-fontified-p
4655 (memq Info-hide-note-references '(t hide))
4656 (not (Info-index-node)))
4657 (put-text-property (match-beginning 2) (1- (match-end 6))
4659 ;; Unhide the file name in parens
4660 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4661 (remove-text-properties (match-beginning 4) (match-end 4)
4663 ;; We need a stretchable space like :align-to but with
4665 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4666 (if (>= 22 (- (match-end 1)
4667 (match-beginning 0)))
4668 '(space :align-to 24)
4670 (setq cont (looking-at "."))
4671 (while (and (= (forward-line 1) 0)
4672 (looking-at "\\([ \t]+\\)[^*\n]"))
4673 (put-text-property (match-beginning 1) (1- (match-end 1))
4675 (put-text-property (1- (match-end 1)) (match-end 1)
4678 '(space :align-to 26)
4679 '(space :align-to 24)))
4682 ;; Fontify menu headers
4683 ;; Add the face `info-menu-header' to any header before a menu entry
4684 (goto-char (point-min))
4685 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4686 (put-text-property (match-beginning 0) (match-end 0)
4687 'font-lock-face 'info-menu-header)
4688 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4689 (put-text-property (match-beginning 1) (match-end 1)
4690 'font-lock-face 'info-menu-header)))
4692 ;; Hide index line numbers
4693 (goto-char (point-min))
4694 (when (and not-fontified-p (Info-index-node))
4695 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4696 (put-text-property (match-beginning 0) (match-end 0)
4699 ;; Fontify http and ftp references
4700 (goto-char (point-min))
4701 (when not-fontified-p
4702 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4704 (add-text-properties (match-beginning 0) (match-end 0)
4705 '(font-lock-face info-xref
4706 mouse-face highlight
4707 help-echo "mouse-2: go to this URL"))))
4709 (set-buffer-modified-p nil))))
4711 ;;; Speedbar support:
4712 ;; These functions permit speedbar to display the "tags" in the
4713 ;; current Info node.
4714 (eval-when-compile (require 'speedbar))
4716 (defvar Info-speedbar-key-map nil
4717 "Keymap used when in the Info display mode.")
4719 (defun Info-install-speedbar-variables ()
4720 "Install those variables used by speedbar to enhance Info."
4721 (if Info-speedbar-key-map
4723 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4725 ;; Basic tree features
4726 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4727 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4728 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4729 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4732 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4733 Info-speedbar-key-map
4734 Info-speedbar-hierarchy-buttons)))
4736 (defvar Info-speedbar-menu-items
4737 '(["Browse Node" speedbar-edit-line t]
4738 ["Expand Node" speedbar-expand-line
4739 (save-excursion (beginning-of-line)
4740 (looking-at "[0-9]+: *.\\+. "))]
4741 ["Contract Node" speedbar-contract-line
4742 (save-excursion (beginning-of-line)
4743 (looking-at "[0-9]+: *.-. "))]
4745 "Additional menu-items to add to speedbar frame.")
4747 ;; Make sure our special speedbar major mode is loaded
4748 (if (featurep 'speedbar)
4749 (Info-install-speedbar-variables)
4750 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4752 ;;; Info hierarchy display method
4754 (defun Info-speedbar-browser ()
4755 "Initialize speedbar to display an Info node browser.
4756 This will add a speedbar major display mode."
4759 ;; Make sure that speedbar is active
4760 (speedbar-frame-mode 1)
4761 ;; Now, throw us into Info mode on speedbar.
4762 (speedbar-change-initial-expansion-list "Info")
4765 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
4766 "Display an Info directory hierarchy in speedbar.
4767 DIRECTORY is the current directory in the attached frame.
4768 DEPTH is the current indentation depth.
4769 NODE is an optional argument that is used to represent the
4770 specific node to expand."
4772 (save-excursion (goto-char (point-min))
4773 (let ((case-fold-search t))
4774 (looking-at "Info Nodes:"))))
4775 ;; Update our "current node" maybe?
4777 ;; We cannot use the generic list code, that depends on all leaves
4778 ;; being known at creation time.
4780 (speedbar-with-writable (insert "Info Nodes:\n")))
4781 (let ((completions nil))
4782 (speedbar-select-attached-frame)
4783 (save-window-excursion
4785 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4786 (select-frame (speedbar-current-frame))
4788 (speedbar-with-writable
4789 (dolist (completion completions)
4790 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4793 'Info-speedbar-goto-node
4799 (defun Info-speedbar-goto-node (_text node _indent)
4800 "When user clicks on TEXT, go to an info NODE.
4801 The INDENT level is ignored."
4802 (speedbar-select-attached-frame)
4803 (let* ((buff (or (get-buffer "*info*")
4804 (progn (info) (get-buffer "*info*"))))
4805 (bwin (get-buffer-window buff 0)))
4808 (select-window bwin)
4809 (raise-frame (window-frame bwin)))
4810 (if speedbar-power-click
4811 (switch-to-buffer-other-frame buff)
4812 (speedbar-select-attached-frame)
4813 (switch-to-buffer buff)))
4814 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4815 (error "Invalid node %s" node)
4816 (Info-find-node (match-string 1 node) (match-string 2 node))
4817 ;; If we do a find-node, and we were in info mode, restore
4818 ;; the old default method. Once we are in info mode, it makes
4819 ;; sense to return to whatever method the user was using before.
4820 (if (string= speedbar-initial-expansion-list-name "Info")
4821 (speedbar-change-initial-expansion-list
4822 speedbar-previously-used-expansion-list-name)))))
4824 (defun Info-speedbar-expand-node (text token indent)
4825 "Expand the node the user clicked on.
4826 TEXT is the text of the button we clicked on, a + or - item.
4827 TOKEN is data related to this node (NAME . FILE).
4828 INDENT is the current indentation depth."
4829 (cond ((string-match "+" text) ;we have to expand this file
4830 (speedbar-change-expand-button-char ?-)
4831 (if (speedbar-with-writable
4833 (end-of-line) (forward-char 1)
4834 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4835 (speedbar-change-expand-button-char ?-)
4836 (speedbar-change-expand-button-char ??)))
4837 ((string-match "-" text) ;we have to contract this node
4838 (speedbar-change-expand-button-char ?+)
4839 (speedbar-delete-subblock indent))
4840 (t (error "Ooops... not sure what to do")))
4841 (speedbar-center-buffer-smartly))
4843 (defun Info-speedbar-fetch-file-nodes (nodespec)
4844 "Fetch the subnodes from the info NODESPEC.
4845 NODESPEC is a string of the form: (file)node."
4846 ;; Set up a buffer we can use to fake-out Info.
4847 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4848 (if (not (equal major-mode 'Info-mode))
4850 ;; Get the node into this buffer
4851 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4852 (error "Invalid node specification %s" nodespec)
4853 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4854 ;; Scan the created buffer
4855 (goto-char (point-min))
4856 (let ((completions nil)
4857 (case-fold-search t)
4858 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4859 (match-string 1 nodespec))))
4860 ;; Always skip the first one...
4861 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4862 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4863 (let ((name (match-string 1)))
4865 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4867 (if (looking-at " *\\(([^)]+)\\)\\.")
4868 (concat (match-string 1) "Top")
4869 (concat "(" thisfile ")"
4870 (if (looking-at " \\([^.]+\\).")
4874 (nreverse completions))))
4876 ;;; Info mode node listing
4877 ;; This is called by `speedbar-add-localized-speedbar-support'
4878 (defun Info-speedbar-buttons (_buffer)
4879 "Create a speedbar display to help navigation in an Info file.
4880 BUFFER is the buffer speedbar is requesting buttons for."
4881 (if (save-excursion (goto-char (point-min))
4882 (let ((case-fold-search t))
4883 (not (looking-at "Info Nodes:"))))
4885 (Info-speedbar-hierarchy-buttons nil 0))
4887 (dolist (mess '("^First node in file$"
4888 "^No `.*' in index$"
4889 "^No cross-reference named"
4890 "^No cross.references in this node$"
4891 "^No current Info node$"
4892 "^No menu in this node$"
4893 "^No more items in menu$"
4895 "^No pointer \\(?:forward\\|backward\\) from this node$"
4896 "^No previous `i' command$"
4897 "^No previous items in menu$"
4898 "^No previous nodes$"
4899 "^No such item in menu$"
4900 "^No such node or anchor"
4902 "^Point neither on reference nor in menu item description$"
4903 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4905 (add-to-list 'debug-ignored-errors mess))
4907 ;;;; Desktop support
4909 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
4910 "Auxiliary information to be saved in desktop file."
4911 (list Info-current-file
4913 ;; Additional data as an association list.
4916 (cons 'history Info-history))
4917 (and (Info-virtual-fun
4918 'slow Info-current-file Info-current-node)
4921 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
4923 desktop-buffer-misc)
4924 "Restore an Info buffer specified in a desktop file."
4925 (let* ((file (nth 0 desktop-buffer-misc))
4926 (node (nth 1 desktop-buffer-misc))
4927 (data (nth 2 desktop-buffer-misc))
4928 (hist (assq 'history data))
4929 (slow (assq 'slow data)))
4930 ;; Don't restore nodes slow to regenerate.
4932 (when (and file node)
4933 (when desktop-buffer-name
4934 (set-buffer (get-buffer-create desktop-buffer-name))
4936 (Info-find-node file node)
4938 (setq Info-history (cdr hist)))
4939 (current-buffer)))))
4941 (add-to-list 'desktop-buffer-mode-handlers
4942 '(Info-mode . Info-restore-desktop-buffer))
4944 ;;;; Bookmark support
4945 (declare-function bookmark-make-record-default
4946 "bookmark" (&optional no-file no-context posn))
4947 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4948 (declare-function bookmark-default-handler "bookmark" (bmk))
4949 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4951 (defun Info-bookmark-make-record ()
4952 "This implements the `bookmark-make-record-function' type (which see)
4954 `(,Info-current-node
4955 ,@(bookmark-make-record-default 'no-file)
4956 (filename . ,Info-current-file)
4957 (info-node . ,Info-current-node)
4958 (handler . Info-bookmark-jump)))
4961 (defun Info-bookmark-jump (bmk)
4962 "This implements the `handler' function interface for the record
4963 type returned by `Info-bookmark-make-record', which see."
4964 (let* ((file (bookmark-prop-get bmk 'filename))
4965 (info-node (bookmark-prop-get bmk 'info-node))
4966 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4967 (Info-find-node file info-node) (current-buffer))))
4968 ;; Use bookmark-default-handler to move to the appropriate location
4970 (bookmark-default-handler
4971 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4975 (defun info-display-manual (manual)
4976 "Go to Info buffer that displays MANUAL, creating it if none already exists."
4977 (interactive "sManual name: ")
4978 (let ((blist (buffer-list))
4979 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
4980 (case-fold-search t)
4982 (dolist (buffer blist)
4983 (with-current-buffer buffer
4984 (when (and (eq major-mode 'Info-mode)
4985 (stringp Info-current-file)
4986 (string-match manual-re Info-current-file))
4990 (switch-to-buffer found)
4992 (info (Info-find-file manual)))))
4996 ;;; info.el ends here