1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2012 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
))
234 :set
(lambda (sym val
)
236 (dolist (buffer (buffer-list))
237 (with-current-buffer buffer
238 (when (eq major-mode
'Info-mode
)
239 (revert-buffer t t
)))))
242 (defcustom Info-refill-paragraphs nil
243 "If non-nil, attempt to refill paragraphs with hidden references.
244 This refilling may accidentally remove explicit line breaks in the Info
245 file, so be prepared for a few surprises if you enable this feature.
246 This only has an effect if `Info-hide-note-references' is non-nil."
251 (defcustom Info-breadcrumbs-depth
4
252 "Depth of breadcrumbs to display.
253 0 means do not display breadcrumbs."
258 (defcustom Info-search-whitespace-regexp
"\\s-+"
259 "If non-nil, regular expression to match a sequence of whitespace chars.
260 This applies to Info search for regular expressions.
261 You might want to use something like \"[ \\t\\r\\n]+\" instead.
262 In the Customization buffer, that is `[' followed by a space,
263 a tab, a carriage return (control-M), a newline, and `]+'."
267 (defcustom Info-isearch-search t
268 "If non-nil, isearch in Info searches through multiple nodes.
269 Before leaving the initial Info node, where isearch was started,
270 it fails once with the error message [initial node], and with
271 subsequent C-s/C-r continues through other nodes without failing
272 with this error message in other nodes. When isearch fails for
273 the rest of the manual, it wraps around the whole manual and
274 restarts the search from the top/final node depending on
277 Setting this option to nil restores the default isearch behavior
278 with wrapping around the current Info node."
283 (defvar Info-isearch-initial-node nil
)
284 (defvar Info-isearch-initial-history nil
)
285 (defvar Info-isearch-initial-history-list nil
)
287 (defcustom Info-mode-hook
288 ;; Try to obey obsolete Info-fontify settings.
289 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
290 '(turn-on-font-lock))
291 "Hooks run when `Info-mode' is called."
295 (defcustom Info-selection-hook nil
296 "Hooks run when `Info-select-node' is called."
300 (defvar Info-edit-mode-hook nil
301 "Hooks run when `Info-edit-mode' is called.")
303 (defvar Info-current-file nil
304 "Info file that Info is now looking at, or nil.
305 This is the name that was specified in Info, not the actual file name.
306 It doesn't contain directory names or file name extensions added by Info.")
308 (defvar Info-current-subfile nil
309 "Info subfile that is actually in the *info* buffer now.
310 It is nil if current Info file is not split into subfiles.")
312 (defvar Info-current-node nil
313 "Name of node that Info is now looking at, or nil.")
315 (defvar Info-tag-table-marker nil
316 "Marker pointing at beginning of current Info file's tag table.
317 Marker points nowhere if file has no tag table.")
319 (defvar Info-tag-table-buffer nil
320 "Buffer used for indirect tag tables.")
322 (defvar Info-current-file-completions nil
323 "Cached completion list for current Info file.")
325 (defvar Info-file-supports-index-cookies nil
326 "Non-nil if current Info file supports index cookies.")
328 (defvar Info-file-supports-index-cookies-list nil
329 "List of Info files with information about index cookies support.
330 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
331 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
333 (defvar Info-index-alternatives nil
334 "List of possible matches for last `Info-index' command.")
336 (defvar Info-point-loc nil
337 "Point location within a selected node.
338 If string, the point is moved to the proper occurrence of the
339 name of the followed cross reference within a selected node.
340 If number, the point is moved to the corresponding line.")
342 (defvar Info-standalone nil
343 "Non-nil if Emacs was started solely as an Info browser.")
345 (defvar Info-virtual-files nil
346 "List of definitions of virtual Info files.
347 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
348 where FILENAME is a regexp that matches a class of virtual Info file names.
349 It should be carefully chosen to not cause file name clashes with
350 existing file names. OPERATION is one of the following operation
351 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
352 function to call instead of calling the default corresponding function
355 (defvar Info-virtual-nodes nil
356 "List of definitions of virtual Info nodes.
357 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
358 where NODENAME is a regexp that matches a class of virtual Info node names.
359 It should be carefully chosen to not cause node name clashes with
360 existing node names. OPERATION is one of the following operation
361 symbols `find-node' that define what HANDLER function to call instead
362 of calling the default corresponding function to override it.")
364 (defvar Info-current-node-virtual nil
365 "Non-nil if the current Info node is virtual.")
367 (defun Info-virtual-file-p (filename)
368 "Check if Info file FILENAME is virtual."
369 (Info-virtual-fun 'find-file filename nil
))
371 (defun Info-virtual-fun (op filename nodename
)
372 "Find a function that handles operations on virtual manuals.
373 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
374 FILENAME is a virtual Info file name, NODENAME is a virtual Info
375 node name. Return a function found either in `Info-virtual-files'
376 or `Info-virtual-nodes'."
377 (or (and (stringp filename
) ; some legacy code can still use a symbol
378 (cdr-safe (assoc op
(assoc-default filename
381 (and (stringp nodename
) ; some legacy code can still use a symbol
382 (cdr-safe (assoc op
(assoc-default nodename
386 (defun Info-virtual-call (virtual-fun &rest args
)
387 "Call a function that handles operations on virtual manuals."
388 (when (functionp virtual-fun
)
389 (or (apply virtual-fun args
) t
)))
392 (defvar Info-suffix-list
393 ;; The MS-DOS list should work both when long file names are
394 ;; supported (Windows 9X), and when only 8+3 file names are available.
395 (if (eq system-type
'ms-dos
)
396 '( (".gz" .
"gunzip")
398 (".bz2" .
("bzip2" "-dc"))
401 (".info.Z" .
"gunzip")
402 (".info.gz" .
"gunzip")
403 ("-info.Z" .
"gunzip")
404 ("-info.gz" .
"gunzip")
405 ("/index.gz" .
"gunzip")
406 ("/index.z" .
"gunzip")
412 '( (".info.Z" .
"uncompress")
413 (".info.Y" .
"unyabba")
414 (".info.gz" .
"gunzip")
415 (".info.z" .
"gunzip")
416 (".info.bz2" .
("bzip2" "-dc"))
417 (".info.xz" .
"unxz")
419 ("-info.Z" .
"uncompress")
420 ("-info.Y" .
"unyabba")
421 ("-info.gz" .
"gunzip")
422 ("-info.bz2" .
("bzip2" "-dc"))
423 ("-info.z" .
"gunzip")
424 ("-info.xz" .
"unxz")
426 ("/index.Z" .
"uncompress")
427 ("/index.Y" .
"unyabba")
428 ("/index.gz" .
"gunzip")
429 ("/index.z" .
"gunzip")
430 ("/index.bz2" .
("bzip2" "-dc"))
431 ("/index.xz" .
"unxz")
433 (".Z" .
"uncompress")
437 (".bz2" .
("bzip2" "-dc"))
440 "List of file name suffixes and associated decoding commands.
441 Each entry should be (SUFFIX . STRING); the file is given to
442 the command as standard input.
444 STRING may be a list of strings. In that case, the first element is
445 the command name, and the rest are arguments to that command.
447 If STRING is nil, no decoding is done.
448 Because the SUFFIXes are tried in order, the empty string should
449 be last in the list.")
451 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
452 ;; First, on MS-DOS with no long file names support, delete some of
453 ;; the extension in FILENAME to make room.
454 (defun info-insert-file-contents-1 (filename suffix lfn
)
455 (if lfn
; long file names are supported
456 (concat filename suffix
)
457 (let* ((sans-exts (file-name-sans-extension filename
))
458 ;; How long is the extension in FILENAME (not counting the dot).
459 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
461 ;; SUFFIX starts with a dot. If FILENAME already has one,
462 ;; get rid of the one in SUFFIX (unless suffix is empty).
463 (or (and (<= ext-len
0)
464 (not (eq (aref filename
(1- (length filename
))) ?.
)))
465 (= (length suffix
) 0)
466 (setq suffix
(substring suffix
1)))
467 ;; How many chars of that extension should we keep?
468 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
469 ;; Get rid of the rest of the extension, and add SUFFIX.
470 (concat (substring filename
0 (- (length filename
)
471 (- ext-len ext-left
)))
474 (defun info-file-exists-p (filename)
475 (and (file-exists-p filename
)
476 (not (file-directory-p filename
))))
478 (defun info-insert-file-contents (filename &optional visit
)
479 "Insert the contents of an Info file in the current buffer.
480 Do the right thing if the file has been compressed or zipped."
481 (let* ((tail Info-suffix-list
)
482 (jka-compr-verbose nil
)
483 (lfn (if (fboundp 'msdos-long-file-names
)
484 (msdos-long-file-names)
486 (check-short (and (fboundp 'msdos-long-file-names
)
488 fullname decoder done
)
489 (if (info-file-exists-p filename
)
490 ;; FILENAME exists--see if that name contains a suffix.
491 ;; If so, set DECODE accordingly.
495 (concat (regexp-quote (car (car tail
))) "$")
497 (setq tail
(cdr tail
)))
498 (setq fullname filename
499 decoder
(cdr (car tail
))))
500 ;; Try adding suffixes to FILENAME and see if we can find something.
501 (while (and tail
(not done
))
502 (setq fullname
(info-insert-file-contents-1 filename
503 (car (car tail
)) lfn
))
504 (if (info-file-exists-p fullname
)
506 ;; If we found a file with a suffix, set DECODER
507 ;; according to the suffix.
508 decoder
(cdr (car tail
)))
509 ;; When the MS-DOS port runs on Windows, we need to check
510 ;; the short variant of a long file name as well.
512 (setq fullname
(info-insert-file-contents-1 filename
513 (car (car tail
)) nil
))
514 (if (info-file-exists-p fullname
)
516 decoder
(cdr (car tail
))))))
517 (setq tail
(cdr tail
)))
519 (error "Can't find %s or any compressed version of it" filename
)))
520 ;; check for conflict with jka-compr
521 (if (and (jka-compr-installed-p)
522 (jka-compr-get-compression-info fullname
))
526 (insert-file-contents-literally fullname visit
)
527 (let ((inhibit-read-only t
)
528 (coding-system-for-write 'no-conversion
)
529 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
530 (default-directory (or (file-name-directory fullname
)
533 (setq decoder
(list decoder
)))
534 (apply 'call-process-region
(point-min) (point-max)
535 (car decoder
) t t nil
(cdr decoder
))))
536 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
537 (insert-file-contents fullname visit
)))))
539 (defun Info-file-supports-index-cookies (&optional file
)
540 "Return non-nil value if FILE supports Info index cookies.
541 Info index cookies were first introduced in 4.7, and all later
542 makeinfo versions output them in index nodes, so we can rely
543 solely on the makeinfo version. This function caches the information
544 in `Info-file-supports-index-cookies-list'."
545 (or file
(setq file Info-current-file
))
546 (or (assoc file Info-file-supports-index-cookies-list
)
547 ;; Skip virtual Info files
548 (and (or (not (stringp file
))
549 (Info-virtual-file-p file
))
550 (setq Info-file-supports-index-cookies-list
551 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
554 (goto-char (point-min))
556 (if (and (re-search-forward
557 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
558 (line-beginning-position 4) t
)
559 (not (version< (match-string 1) "4.7")))
562 (setq Info-file-supports-index-cookies-list
563 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
564 (cdr (assoc file Info-file-supports-index-cookies-list
)))
567 (defun Info-default-dirs ()
568 (let ((source (expand-file-name "info/" source-directory
))
569 (sibling (if installation-directory
570 (expand-file-name "info/" installation-directory
)
571 (if invocation-directory
572 (let ((infodir (expand-file-name
574 invocation-directory
)))
575 (if (file-exists-p infodir
)
577 (setq infodir
(expand-file-name
578 "../../../share/info/"
579 invocation-directory
))
580 (and (file-exists-p infodir
)
584 (if (and sibling
(file-exists-p sibling
))
585 ;; Uninstalled, Emacs builddir != srcdir.
587 ;; Uninstalled, builddir == srcdir
589 (if (or (member alternative Info-default-directory-list
)
590 ;; On DOS/NT, we use movable executables always,
591 ;; and we must always find the Info dir at run time.
592 (if (memq system-type
'(ms-dos windows-nt
))
594 ;; Use invocation-directory for Info
595 ;; only if we used it for exec-directory also.
596 (not (string= exec-directory
597 (expand-file-name "lib-src/"
598 installation-directory
))))
599 (not (file-exists-p alternative
)))
600 Info-default-directory-list
601 ;; `alternative' contains the Info files that came with this
602 ;; version, so we should look there first. `Info-insert-dir'
603 ;; currently expects to find `alternative' first on the list.
605 ;; Don't drop the last part, it might contain non-Emacs stuff.
606 ;; (reverse (cdr (reverse
607 Info-default-directory-list
)))) ;; )))
609 (defun info-initialize ()
610 "Initialize `Info-directory-list', if that hasn't been done yet."
611 (unless Info-directory-list
612 (let ((path (getenv "INFOPATH"))
613 (sep (regexp-quote path-separator
)))
614 (setq Info-directory-list
615 (prune-directory-list
617 (if (string-match-p (concat sep
"\\'") path
)
618 (append (split-string (substring path
0 -
1) sep
)
620 (split-string path sep
))
621 (Info-default-dirs)))))))
624 (defun info-other-window (&optional file-or-node
)
625 "Like `info' but show the Info buffer in another window."
626 (interactive (if current-prefix-arg
627 (list (read-file-name "Info file name: " nil nil t
))))
628 (info-setup file-or-node
(switch-to-buffer-other-window "*info*")))
630 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
632 (defun info (&optional file-or-node buffer
)
633 "Enter Info, the documentation browser.
634 Optional argument FILE-OR-NODE specifies the file to examine;
635 the default is the top-level directory of Info.
636 Called from a program, FILE-OR-NODE may specify an Info node of the form
637 \"(FILENAME)NODENAME\".
638 Optional argument BUFFER specifies the Info buffer name;
639 the default buffer name is *info*. If BUFFER exists,
640 just switch to BUFFER. Otherwise, create a new buffer
641 with the top-level Info directory.
643 In interactive use, a non-numeric prefix argument directs
644 this command to read a file name from the minibuffer.
645 A numeric prefix argument selects an Info buffer with the prefix number
646 appended to the Info buffer name.
648 The search path for Info files is in the variable `Info-directory-list'.
649 The top-level Info directory is made by combining all the files named `dir'
650 in all the directories in that path.
652 See a list of available Info commands in `Info-mode'."
654 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
655 (read-file-name "Info file name: " nil nil t
))
656 (if (numberp current-prefix-arg
)
657 (format "*info*<%s>" current-prefix-arg
))))
658 (info-setup file-or-node
659 (pop-to-buffer-same-window (or buffer
"*info*"))))
661 (defun info-setup (file-or-node buffer
)
662 "Display Info node FILE-OR-NODE in BUFFER."
663 (if (and buffer
(not (eq major-mode
'Info-mode
)))
666 ;; If argument already contains parentheses, don't add another set
667 ;; since the argument will then be parsed improperly. This also
668 ;; has the added benefit of allowing node names to be included
669 ;; following the parenthesized filename.
671 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
673 (concat "(" file-or-node
")")))
674 (if (and (zerop (buffer-size))
676 ;; If we just created the Info buffer, go to the directory.
680 (defun info-emacs-manual ()
681 "Display the Emacs manual in Info mode."
686 (defun info-standalone ()
687 "Run Emacs as a standalone Info reader.
688 Usage: emacs -f info-standalone [filename]
689 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
690 (setq Info-standalone t
)
691 (if (and command-line-args-left
692 (not (string-match "^-" (car command-line-args-left
))))
695 (info (car command-line-args-left
))
696 (setq command-line-args-left
(cdr command-line-args-left
)))
697 (error (send-string-to-terminal
698 (format "%s\n" (if (eq (car-safe err
) 'error
)
700 (save-buffers-kill-emacs)))
703 ;; See if the accessible portion of the buffer begins with a node
704 ;; delimiter, and the node header line which follows matches REGEXP.
705 ;; Typically, this test will be followed by a loop that examines the
706 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
707 ;; to have the overhead of this special test inside the loop.
709 ;; This function changes match-data, but supposedly the caller might
710 ;; want to use the results of re-search-backward.
712 ;; The return value is the value of point at the beginning of matching
713 ;; REGEXP, if the function succeeds, nil otherwise.
714 (defun Info-node-at-bob-matching (regexp)
715 (and (bobp) ; are we at beginning of buffer?
716 (looking-at "\^_") ; does it begin with node delimiter?
720 (forward-line 1) ; does the line after delimiter match REGEXP?
721 (re-search-backward regexp beg t
))))
723 (defun Info-find-file (filename &optional noerror
)
724 "Return expanded FILENAME, or t if FILENAME is \"dir\".
725 Optional second argument NOERROR, if t, means if file is not found
726 just return nil (no error)."
727 ;; Convert filename to lower case if not found as specified.
731 (Info-virtual-fun 'find-file filename nil
)
734 (let (temp temp-downcase found
)
735 (setq filename
(substitute-in-file-name filename
))
736 (let ((dirs (if (string-match "^\\./" filename
)
737 ;; If specified name starts with `./'
738 ;; then just try current directory.
740 (if (file-name-absolute-p filename
)
741 ;; No point in searching for an
742 ;; absolute file name
744 (if Info-additional-directory-list
745 (append Info-directory-list
746 Info-additional-directory-list
)
747 Info-directory-list
)))))
748 ;; Fall back on the installation directory if we can't find
749 ;; the info node anywhere else.
750 (when installation-directory
751 (setq dirs
(append dirs
(list (expand-file-name
752 "info" installation-directory
)))))
753 ;; Search the directory list for file FILENAME.
754 (while (and dirs
(not found
))
755 (setq temp
(expand-file-name filename
(car dirs
)))
757 (expand-file-name (downcase filename
) (car dirs
)))
758 ;; Try several variants of specified name.
759 (let ((suffix-list Info-suffix-list
)
760 (lfn (if (fboundp 'msdos-long-file-names
)
761 (msdos-long-file-names)
763 (while (and suffix-list
(not found
))
764 (cond ((info-file-exists-p
765 (info-insert-file-contents-1
766 temp
(car (car suffix-list
)) lfn
))
769 (info-insert-file-contents-1
770 temp-downcase
(car (car suffix-list
)) lfn
))
771 (setq found temp-downcase
))
772 ((and (fboundp 'msdos-long-file-names
)
775 (info-insert-file-contents-1
776 temp
(car (car suffix-list
)) nil
)))
778 (setq suffix-list
(cdr suffix-list
))))
779 (setq dirs
(cdr dirs
))))
781 (setq filename found
)
784 (error "Info file %s does not exist" filename
)))
787 (defun Info-find-node (filename nodename
&optional no-going-back
)
788 "Go to an Info node specified as separate FILENAME and NODENAME.
789 NO-GOING-BACK is non-nil if recovering from an error in this function;
790 it says do not attempt further (recursive) error recovery."
792 (setq filename
(Info-find-file filename
))
793 ;; Go into Info buffer.
794 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
795 ;; Record the node we are leaving, if we were in one.
796 (and (not no-going-back
)
798 (push (list Info-current-file Info-current-node
(point))
800 (Info-find-node-2 filename nodename no-going-back
))
803 (defun Info-on-current-buffer (&optional nodename
)
804 "Use Info mode to browse the current Info buffer.
805 With a prefix arg, this queries for the node name to visit first;
806 otherwise, that defaults to `Top'."
808 (list (if current-prefix-arg
809 (completing-read "Node name: " (Info-build-node-completions)
811 (unless nodename
(setq nodename
"Top"))
814 (set (make-local-variable 'Info-current-file
)
816 ;; If called on a non-file buffer, make a fake file name.
817 (concat default-directory
(buffer-name))))
818 (Info-find-node-2 nil nodename
))
820 (defun Info-revert-find-node (filename nodename
)
821 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
822 When *info* is already displaying FILENAME and NODENAME, the window position
823 is preserved, if possible."
824 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
825 (let ((old-filename Info-current-file
)
826 (old-nodename Info-current-node
)
827 (window-selected (eq (selected-window) (get-buffer-window)))
828 (pcolumn (current-column))
829 (pline (count-lines (point-min) (line-beginning-position)))
830 (wline (count-lines (point-min) (window-start)))
831 (new-history (and Info-current-file
832 (list Info-current-file Info-current-node
(point)))))
833 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
834 (setq Info-current-file nil
)
835 (Info-find-node filename nodename
)
836 (if (and (equal old-filename Info-current-file
)
837 (equal old-nodename Info-current-node
))
839 ;; note goto-line is no good, we want to measure from point-min
840 (when window-selected
841 (goto-char (point-min))
843 (set-window-start (selected-window) (point)))
844 (goto-char (point-min))
846 (move-to-column pcolumn
))
847 ;; only add to the history when coming from a different file+node
849 (setq Info-history
(cons new-history Info-history
))))))
851 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
852 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
853 (Info-revert-find-node Info-current-file Info-current-node
)
854 (message "Reverted %s" Info-current-file
)))
856 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
857 "Find a node in a tag table.
858 MARKER specifies the buffer and position to start searching at.
859 REGEXP is a regular expression matching nodes or references. Its first
860 group should match `Node:' or `Ref:'.
861 CASE-FOLD t means search for a case-insensitive match.
862 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
863 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
864 where the match was found, and MODE is `major-mode' of the buffer in
865 which the match was found."
866 (let ((case-fold-search case-fold
))
867 (with-current-buffer (marker-buffer marker
)
872 (when (re-search-forward regexp nil t
)
873 (list (string-equal "Ref:" (match-string 1))
874 (+ (point-min) (read (current-buffer)))
877 (defun Info-find-in-tag-table (marker regexp
)
878 "Find a node in a tag table.
879 MARKER specifies the buffer and position to start searching at.
880 REGEXP is a regular expression matching nodes or references. Its first
881 group should match `Node:' or `Ref:'.
882 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
883 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
884 where the match was found, and MODE is `major-mode' of the buffer in
885 which the match was found.
886 This function tries to find a case-sensitive match first, then a
887 case-insensitive match is tried."
888 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
889 (when (null (car result
))
890 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
893 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
894 "Find a node or anchor in the current buffer.
895 REGEXP is a regular expression matching nodes or references. Its first
896 group should match `Node:' or `Ref:'.
897 CASE-FOLD t means search for a case-insensitive match.
898 Value is the position at which a match was found, or nil if not found."
899 (let ((case-fold-search case-fold
)
902 (if (Info-node-at-bob-matching regexp
)
904 (while (and (not found
)
905 (search-forward "\n\^_" nil t
))
909 (if (re-search-backward regexp beg t
)
910 (setq found
(line-beginning-position)))))))
913 (defun Info-find-node-in-buffer (regexp)
914 "Find a node or anchor in the current buffer.
915 REGEXP is a regular expression matching nodes or references. Its first
916 group should match `Node:' or `Ref:'.
917 Value is the position at which a match was found, or nil if not found.
918 This function looks for a case-sensitive match first. If none is found,
919 a case-insensitive match is tried."
920 (or (Info-find-node-in-buffer-1 regexp nil
)
921 (Info-find-node-in-buffer-1 regexp t
)))
923 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
924 (buffer-disable-undo (current-buffer))
925 (or (eq major-mode
'Info-mode
)
928 (setq Info-current-node nil
)
930 (let ((case-fold-search t
)
931 (virtual-fun (Info-virtual-fun 'find-node
932 (or filename Info-current-file
)
936 ((functionp virtual-fun
)
937 (let ((filename (or filename Info-current-file
)))
938 (setq buffer-read-only nil
)
939 (setq Info-current-file filename
940 Info-current-subfile nil
941 Info-current-file-completions nil
942 buffer-file-name nil
)
944 (Info-virtual-call virtual-fun filename nodename no-going-back
)
945 (set-marker Info-tag-table-marker nil
)
946 (setq buffer-read-only t
)
947 (set-buffer-modified-p nil
)
948 (set (make-local-variable 'Info-current-node-virtual
) t
)))
950 ;; Reread a file when moving from a virtual node.
951 (not Info-current-node-virtual
)
953 (equal Info-current-file filename
))))
954 ;; Switch files if necessary
955 (let ((inhibit-read-only t
))
956 (when Info-current-node-virtual
957 ;; When moving from a virtual node.
958 (set (make-local-variable 'Info-current-node-virtual
) nil
)
960 (setq filename Info-current-file
)))
961 (setq Info-current-file nil
962 Info-current-subfile nil
963 Info-current-file-completions nil
964 buffer-file-name nil
)
966 (info-insert-file-contents filename nil
)
967 (setq default-directory
(file-name-directory filename
))
968 (set-buffer-modified-p nil
)
969 (set (make-local-variable 'Info-file-supports-index-cookies
)
970 (Info-file-supports-index-cookies filename
))
972 ;; See whether file has a tag table. Record the location if yes.
973 (goto-char (point-max))
975 ;; Use string-equal, not equal, to ignore text props.
976 (if (not (or (string-equal nodename
"*")
978 (search-forward "\^_\nEnd tag table\n" nil t
))))
980 ;; We have a tag table. Find its beginning.
981 ;; Is this an indirect file?
982 (search-backward "\nTag table:\n")
986 (looking-at "(Indirect)\n"))
987 ;; It is indirect. Copy it to another buffer
988 ;; and record that the tag table is in that buffer.
989 (let ((buf (current-buffer))
991 (or Info-tag-table-buffer
992 (generate-new-buffer " *info tag table*"))))
993 (setq Info-tag-table-buffer tagbuf
)
994 (with-current-buffer tagbuf
995 (buffer-disable-undo (current-buffer))
996 (setq case-fold-search t
)
998 (insert-buffer-substring buf
))
999 (set-marker Info-tag-table-marker
1000 (match-end 0) tagbuf
))
1001 (set-marker Info-tag-table-marker pos
)))
1002 (set-marker Info-tag-table-marker nil
))
1003 (setq Info-current-file filename
)
1006 ;; Use string-equal, not equal, to ignore text props.
1007 (if (string-equal nodename
"*")
1008 (progn (setq Info-current-node nodename
)
1009 (Info-set-mode-line))
1012 ;; 1. Anchor found in tag table
1013 ;; 2. Anchor *not* in tag table
1015 ;; 3. Node found in tag table
1016 ;; 4. Node *not* found in tag table, but found in file
1017 ;; 5. Node *not* in tag table, and *not* in file
1019 ;; *Or* the same, but in an indirect subfile.
1021 ;; Search file for a suitable node.
1022 (let ((guesspos (point-min))
1023 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1024 (if (stringp nodename
)
1025 (regexp-quote nodename
)
1027 "\\) *[,\t\n\177]")))
1031 ;; First, search a tag table, if any
1032 (when (marker-position Info-tag-table-marker
)
1033 (let* ((m Info-tag-table-marker
)
1034 (found (Info-find-in-tag-table m regexp
)))
1037 ;; FOUND is (ANCHOR POS MODE).
1038 (setq guesspos
(nth 1 found
))
1040 ;; If this is an indirect file, determine which
1041 ;; file really holds this node and read it in.
1042 (unless (eq (nth 2 found
) 'Info-mode
)
1043 ;; Note that the current buffer must be the
1044 ;; *info* buffer on entry to
1045 ;; Info-read-subfile. Thus the hackery above.
1046 (setq guesspos
(Info-read-subfile guesspos
)))
1050 (goto-char (setq anchorpos guesspos
))
1053 ;; Else we may have a node, which we search for:
1054 (goto-char (max (point-min)
1055 (- (byte-to-position guesspos
) 1000)))
1057 ;; Now search from our advised position (or from beg of
1058 ;; buffer) to find the actual node. First, check
1059 ;; whether the node is right where we are, in case the
1060 ;; buffer begins with a node.
1061 (let ((pos (Info-find-node-in-buffer regexp
)))
1066 (when (string-match "\\([^.]+\\)\\." nodename
)
1067 (let (Info-point-loc)
1069 filename
(match-string 1 nodename
) no-going-back
))
1073 ;; No such anchor in tag table or node in tag table or file
1074 (error "No such node or anchor: %s" nodename
))
1077 (goto-char (point-min))
1078 (forward-line 1) ; skip header line
1079 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1080 ;; (forward-line 1))
1083 (let ((new-history (list Info-current-file
1084 (substring-no-properties nodename
))))
1085 ;; Add anchors to the history too
1086 (setq Info-history-list
1088 (remove new-history Info-history-list
))))
1089 (goto-char anchorpos
))
1090 ((numberp Info-point-loc
)
1091 (forward-line (- Info-point-loc
2))
1092 (setq Info-point-loc nil
))
1093 ((stringp Info-point-loc
)
1094 (Info-find-index-name Info-point-loc
)
1095 (setq Info-point-loc nil
))))))
1096 ;; If we did not finish finding the specified node,
1097 ;; go back to the previous one.
1098 (or Info-current-node no-going-back
(null Info-history
)
1099 (let ((hist (car Info-history
)))
1100 (setq Info-history
(cdr Info-history
))
1101 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1102 (goto-char (nth 2 hist
))))))
1104 ;; Cache the contents of the (virtual) dir file, once we have merged
1105 ;; it for the first time, so we can save time subsequently.
1106 (defvar Info-dir-contents nil
)
1108 ;; Cache for the directory we decided to use for the default-directory
1109 ;; of the merged dir text.
1110 (defvar Info-dir-contents-directory nil
)
1112 ;; Record the file attributes of all the files from which we
1113 ;; constructed Info-dir-contents.
1114 (defvar Info-dir-file-attributes nil
)
1116 (defvar Info-dir-file-name nil
)
1118 ;; Construct the Info directory node by merging the files named `dir'
1119 ;; from various directories. Set the *info* buffer's
1120 ;; default-directory to the first directory we actually get any text
1122 (defun Info-insert-dir ()
1123 (if (and Info-dir-contents Info-dir-file-attributes
1124 ;; Verify that none of the files we used has changed
1125 ;; since we used it.
1127 (mapcar (lambda (elt)
1128 (let ((curr (file-attributes
1130 (file-truename (car elt
)))))
1132 ;; Don't compare the access time.
1133 (if curr
(setcar (nthcdr 4 curr
) 0))
1134 (setcar (nthcdr 4 (cdr elt
)) 0)
1135 (equal (cdr elt
) curr
)))
1136 Info-dir-file-attributes
))))
1138 (insert Info-dir-contents
)
1139 (goto-char (point-min)))
1140 (let ((dirs (if Info-additional-directory-list
1141 (append Info-directory-list
1142 Info-additional-directory-list
)
1143 Info-directory-list
))
1144 (dir-file-attrs nil
)
1145 ;; Bind this in case the user sets it to nil.
1146 (case-fold-search t
)
1147 ;; This is set non-nil if we find a problem in some input files.
1149 buffers buffer others nodes dirs-done
)
1151 ;; Search the directory list for the directory file.
1153 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1154 (or (member truename dirs-done
)
1155 (member (directory-file-name truename
) dirs-done
)
1156 ;; Try several variants of specified name.
1157 ;; Try upcasing, appending `.info', or both.
1161 (progn (setq file
(expand-file-name "dir" truename
))
1162 (file-attributes file
))
1163 (progn (setq file
(expand-file-name "DIR" truename
))
1164 (file-attributes file
))
1165 (progn (setq file
(expand-file-name "dir.info" truename
))
1166 (file-attributes file
))
1167 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1168 (file-attributes file
))
1169 ;; Shouldn't really happen, but sometimes does,
1170 ;; eg on Debian systems with buggy packages;
1171 ;; so may as well try it.
1172 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1173 (progn (setq file
(expand-file-name "dir.gz" truename
))
1174 (file-attributes file
)))))
1177 (cons (directory-file-name truename
)
1180 (with-current-buffer (generate-new-buffer " info dir")
1182 (message "Composing main Info directory..."))
1184 ;; Index nodes include null bytes. DIR
1185 ;; files should not have indices, but who
1187 (let ((inhibit-null-byte-detection t
))
1188 (insert-file-contents file
)
1189 (set (make-local-variable 'Info-dir-file-name
)
1191 (push (current-buffer) buffers
)
1192 (push (cons file attrs
) dir-file-attrs
))
1193 (error (kill-buffer (current-buffer))))))))
1195 (set (make-local-variable 'Info-dir-contents-directory
)
1196 (file-name-as-directory (car dirs
))))
1197 (setq dirs
(cdr dirs
))))
1200 (error "Can't find the Info directory node"))
1202 ;; Distinguish the dir file that comes with Emacs from all the
1203 ;; others. Yes, that is really what this is supposed to do.
1204 ;; The definition of `Info-directory-list' puts it first on that
1205 ;; list and so last in `buffers' at this point.
1206 (setq buffer
(car (last buffers
))
1207 others
(delq buffer buffers
))
1209 ;; Insert the entire original dir file as a start; note that we've
1210 ;; already saved its default directory to use as the default
1211 ;; directory for the whole concatenation.
1212 (save-excursion (insert-buffer-substring buffer
))
1214 ;; Look at each of the other buffers one by one.
1215 (dolist (other others
)
1216 (let (this-buffer-nodes)
1217 ;; In each, find all the menus.
1218 (with-current-buffer other
1219 (goto-char (point-min))
1220 ;; Find each menu, and add an elt to NODES for it.
1221 (while (re-search-forward "^\\* Menu:" nil t
)
1222 (while (and (zerop (forward-line 1)) (eolp)))
1225 (re-search-backward "^\^_")
1226 (search-forward "Node: ")
1227 (setq nodename
(Info-following-node-name))
1228 (search-forward "\n\^_" nil
'move
)
1231 (push (list nodename other beg end
) this-buffer-nodes
)))
1232 (if (assoc-string "top" this-buffer-nodes t
)
1233 (setq nodes
(nconc this-buffer-nodes nodes
))
1235 (message "No `top' node in %s" Info-dir-file-name
)))))
1236 ;; Add to the main menu a menu item for each other node.
1237 (re-search-forward "^\\* Menu:")
1239 (let ((menu-items '("top"))
1240 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1241 (dolist (node nodes
)
1242 (let ((nodename (car node
)))
1244 (or (member (downcase nodename
) menu-items
)
1245 (re-search-forward (concat "^\\* +"
1246 (regexp-quote nodename
)
1250 (insert "* " nodename
"::" "\n")
1251 (push nodename menu-items
)))))))
1252 ;; Now take each node of each of the other buffers
1253 ;; and merge it into the main buffer.
1254 (dolist (node nodes
)
1255 (let ((case-fold-search t
)
1256 (nodename (car node
)))
1257 (goto-char (point-min))
1258 ;; Find the like-named node in the main buffer.
1259 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1260 (regexp-quote nodename
)
1264 (search-forward "\n\^_" nil
'move
)
1267 ;; If none exists, add one.
1268 (goto-char (point-max))
1269 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1270 ;; Merge the text from the other buffer's menu
1271 ;; into the menu in the like-named node in the main buffer.
1272 (apply 'insert-buffer-substring
(cdr node
))))
1273 (Info-dir-remove-duplicates)
1274 ;; Kill all the buffers we just made, including the special one excised.
1275 (mapc 'kill-buffer
(cons buffer buffers
))
1276 (goto-char (point-min))
1278 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1279 (message "Composing main Info directory...done"))
1280 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1281 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1282 (setq default-directory Info-dir-contents-directory
))
1284 (defvar Info-streamline-headings
1285 '(("Emacs" .
"Emacs")
1286 ("Programming" .
"Programming")
1287 ("Libraries" .
"Libraries")
1288 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1289 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1291 (defun Info-dir-remove-duplicates ()
1293 (goto-char (point-min))
1294 ;; Remove duplicate headings in the same menu.
1295 (while (search-forward "\n* Menu:" nil t
)
1296 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1297 ;; Look for the next heading to unify.
1298 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1299 (let ((name (match-string 1))
1300 (start (match-beginning 0))
1302 ;; Check whether this heading should be streamlined.
1304 (dolist (x Info-streamline-headings
)
1305 (when (string-match (car x
) name
)
1307 (setq re
(car x
)))))
1308 (if re
(replace-match name t t nil
1))
1309 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1311 (or limit
(point-max))))
1312 ;; Look for other headings of the same category and merge them.
1314 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1315 (when (if re
(save-match-data (string-match re
(match-string 1)))
1316 (equal name
(match-string 1)))
1318 ;; Delete redundant heading.
1319 (delete-region (match-beginning 0) (point))
1320 ;; Push the entries onto `text'.
1322 (delete-and-extract-region
1324 (if (re-search-forward "^[^* \n\t]" nil t
)
1326 (or limit
(point-max))))
1329 ;; Insert the entries just found.
1330 (while (= (line-beginning-position 0) (1- (point)))
1332 (dolist (entry (nreverse entries
))
1334 (while (= (line-beginning-position 0) (1- (point)))
1335 (delete-region (1- (point)) (point))))
1337 ;; Now remove duplicate entries under the same heading.
1340 (narrow-to-region start
(point))
1341 (goto-char (point-min))
1342 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1343 ;; Fold case straight away; `member-ignore-case' here wasteful.
1344 (let ((x (downcase (match-string 1))))
1348 (if (re-search-forward "^[^ \t]" nil
'move
)
1349 (goto-char (match-beginning 0))
1351 (push x seen
)))))))))))
1353 ;; Note that on entry to this function the current-buffer must be the
1354 ;; *info* buffer; not the info tags buffer.
1355 (defun Info-read-subfile (nodepos)
1356 ;; NODEPOS is either a position (in the Info file as a whole,
1357 ;; not relative to a subfile) or the name of a subfile.
1360 (if (numberp nodepos
)
1361 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1362 (goto-char (point-min))
1363 (or (looking-at "\^_")
1364 (search-forward "\n\^_"))
1367 (while (not (looking-at "\^_"))
1370 thisfilepos thisfilename
)
1371 (search-forward ": ")
1372 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1373 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1374 ;; read in version 19 stops at the end of number.
1375 ;; Advance to the next line.
1377 (if (> thisfilepos nodepos
)
1379 (setq lastfilename thisfilename
)
1380 (setq lastfilepos thisfilepos
))
1381 (forward-line 1)))))
1382 (setq lastfilename nodepos
)
1383 (setq lastfilepos
0))
1384 ;; Assume previous buffer is in Info-mode.
1385 ;; (set-buffer (get-buffer "*info*"))
1386 (or (equal Info-current-subfile lastfilename
)
1387 (let ((inhibit-read-only t
))
1388 (setq buffer-file-name nil
)
1391 (info-insert-file-contents lastfilename
)
1392 (set-buffer-modified-p nil
)
1393 (setq Info-current-subfile lastfilename
)))
1394 ;; Widen in case we are in the same subfile as before.
1396 (goto-char (point-min))
1397 (if (looking-at "\^_")
1399 (search-forward "\n\^_"))
1400 (if (numberp nodepos
)
1401 (+ (- nodepos lastfilepos
) (point)))))
1403 (defun Info-unescape-quotes (value)
1404 "Unescape double quotes and backslashes in VALUE."
1407 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1408 (setq unquote
(replace-match "" t t unquote
1))
1409 (setq start
(- (match-end 0) 1)))
1412 ;; As of Texinfo 4.6, makeinfo writes constructs like
1413 ;; \0\h[image param=value ...\h\0]
1414 ;; into the Info file for handling images.
1415 (defun Info-split-parameter-string (parameter-string)
1416 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1417 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1418 If VALUE contains whitespace or double quotes, it must be quoted
1419 in double quotes and any double quotes or backslashes must be
1420 escaped (\\\",\\\\)."
1423 (while (string-match
1424 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1425 parameter-string start
)
1426 (setq start
(match-end 0))
1427 (push (cons (match-string 1 parameter-string
)
1428 (or (match-string 2 parameter-string
)
1429 (Info-unescape-quotes
1430 (match-string 3 parameter-string
))))
1434 (defun Info-display-images-node ()
1435 "Display images in current node."
1437 (let ((inhibit-read-only t
)
1438 (case-fold-search t
))
1439 (goto-char (point-min))
1440 (while (re-search-forward
1441 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1443 (let* ((start (match-beginning 1))
1444 (parameter-alist (Info-split-parameter-string (match-string 2)))
1445 (src (cdr (assoc-string "src" parameter-alist
))))
1446 (if (display-images-p)
1447 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1448 (concat default-directory src
))
1450 (image (if (file-exists-p image-file
)
1451 (create-image image-file
)
1453 (if (not (get-text-property start
'display
))
1454 (add-text-properties
1455 start
(point) `(display ,image rear-nonsticky
(display)))))
1456 ;; text-only display, show alternative text if provided, or
1457 ;; otherwise a clue that there's meant to be a picture
1458 (delete-region start
(point))
1459 (insert (or (cdr (assoc-string "text" parameter-alist
))
1460 (cdr (assoc-string "alt" parameter-alist
))
1462 (concat "[image:" src
"]"))
1464 (set-buffer-modified-p nil
)))
1466 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1467 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1468 ;; including one optional trailing newline.
1469 (defun Info-hide-cookies-node ()
1470 "Hide unrecognized cookies in current node."
1472 (let ((inhibit-read-only t
)
1473 (case-fold-search t
))
1474 (goto-char (point-min))
1475 (while (re-search-forward
1476 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1478 (let* ((start (match-beginning 1)))
1479 (if (and (not (get-text-property start
'invisible
))
1480 (not (get-text-property start
'display
)))
1481 (put-text-property start
(point) 'invisible t
)))))
1482 (set-buffer-modified-p nil
)))
1484 (defun Info-select-node ()
1485 "Select the Info node that point is in."
1486 ;; Bind this in case the user sets it to nil.
1487 (let ((case-fold-search t
))
1489 ;; Find beginning of node.
1490 (if (search-backward "\n\^_" nil
'move
)
1492 (if (looking-at "\^_")
1494 (signal 'search-failed
(list "\n\^_"))))
1495 ;; Get nodename spelled as it is in the node.
1496 (re-search-forward "Node:[ \t]*")
1497 (setq Info-current-node
1498 (buffer-substring-no-properties (point)
1500 (skip-chars-forward "^,\t\n")
1502 (Info-set-mode-line)
1503 ;; Find the end of it, and narrow.
1505 (let (active-expression)
1506 ;; Narrow to the node contents
1507 (narrow-to-region (point)
1508 (if (re-search-forward "\n[\^_\f]" nil t
)
1511 (if (looking-at "[\n\^_\f]*execute: ")
1513 (goto-char (match-end 0))
1514 (setq active-expression
1515 (read (current-buffer))))))
1517 (if Info-enable-active-nodes
(eval active-expression
))
1518 ;; Add a new unique history item to full history list
1519 (let ((new-history (list Info-current-file Info-current-node
)))
1520 (setq Info-history-list
1521 (cons new-history
(remove new-history Info-history-list
)))
1522 (setq Info-history-forward nil
))
1523 (if (not (eq Info-fontify-maximum-menu-size nil
))
1524 (Info-fontify-node))
1525 (Info-display-images-node)
1526 (Info-hide-cookies-node)
1527 (run-hooks 'Info-selection-hook
)))))
1529 (defvar Info-mode-line-node-keymap
1530 (let ((map (make-sparse-keymap)))
1531 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1532 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1534 "Keymap to put on the Info node name in the mode line.")
1536 (defun Info-set-mode-line ()
1537 (setq mode-line-buffer-identification
1538 (nconc (propertized-buffer-identification "%b")
1542 (if (stringp Info-current-file
)
1543 (replace-regexp-in-string
1544 "%" "%%" (file-name-nondirectory Info-current-file
))
1545 (format "*%S*" Info-current-file
))
1547 (if Info-current-node
1548 (propertize (replace-regexp-in-string
1549 "%" "%%" Info-current-node
)
1550 'face
'mode-line-buffer-id
1552 "mouse-1: scroll forward, mouse-3: scroll back"
1553 'mouse-face
'mode-line-highlight
1554 'local-map Info-mode-line-node-keymap
)
1557 ;; Go to an Info node specified with a filename-and-nodename string
1558 ;; of the sort that is found in pointers in nodes.
1560 ;; Don't autoload this function: the correct entry point for other packages
1561 ;; to use is `info'. --Stef
1563 (defun Info-goto-node (nodename &optional fork
)
1564 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1565 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1566 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1568 Completion is available, but only for node names in the current Info file.
1569 If FORK is non-nil (interactively with a prefix arg), show the node in
1571 If FORK is a string, it is the name to use for the new buffer."
1572 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1576 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1578 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1580 (setq filename
(if (= (match-beginning 1) (match-end 1))
1582 (match-string 2 nodename
))
1583 nodename
(match-string 3 nodename
))
1584 (let ((trim (string-match "\\s +\\'" filename
)))
1585 (if trim
(setq filename
(substring filename
0 trim
))))
1586 (let ((trim (string-match "\\s +\\'" nodename
)))
1587 (if trim
(setq nodename
(substring nodename
0 trim
))))
1588 (if transient-mark-mode
(deactivate-mark))
1589 (Info-find-node (if (equal filename
"") nil filename
)
1590 (if (equal nodename
"") "Top" nodename
))))
1592 (defvar Info-read-node-completion-table
)
1594 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1595 "Internal function used to complete Info node names.
1596 Return a completion table for Info files---the FILENAME part of a
1597 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1598 directories to search if FILENAME is not absolute; SUFFIXES is a
1599 list of valid filename suffixes for Info files. See
1600 `try-completion' for a description of the remaining arguments."
1601 (setq suffixes
(remove "" suffixes
))
1602 (when (file-name-absolute-p string
)
1603 (setq dirs
(list (file-name-directory string
))))
1605 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1606 (string-dir (file-name-directory string
)))
1609 (setq dir default-directory
))
1610 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1611 (when (file-directory-p dir
)
1612 (dolist (file (file-name-all-completions
1613 (file-name-nondirectory string
) dir
))
1614 ;; If the file name has no suffix or a standard suffix,
1616 (and (or (null (file-name-extension file
))
1617 (string-match suffix file
))
1618 ;; But exclude subfiles of split Info files.
1619 (not (string-match "-[0-9]+\\'" file
))
1620 ;; And exclude backup files.
1621 (not (string-match "~\\'" file
))
1622 (push (if string-dir
(concat string-dir file
) file
) names
))
1623 ;; If the file name ends in a standard suffix,
1624 ;; add the unsuffixed name as a completion option.
1625 (when (string-match suffix file
)
1626 (setq file
(substring file
0 (match-beginning 0)))
1627 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1628 (complete-with-action action names string pred
)))
1630 (defun Info-read-node-name-1 (string predicate code
)
1631 "Internal function used by `Info-read-node-name'.
1632 See `completing-read' for a description of arguments and usage."
1634 ;; First complete embedded file names.
1635 ((string-match "\\`([^)]*\\'" string
)
1636 (completion-table-with-context
1638 (apply-partially 'completion-table-with-terminator
")"
1639 (apply-partially 'Info-read-node-name-2
1641 (mapcar 'car Info-suffix-list
)))
1642 (substring string
1)
1645 ;; If a file name was given, then any node is fair game.
1646 ((string-match "\\`(" string
)
1648 ((eq code nil
) string
)
1651 ;; Otherwise use Info-read-node-completion-table.
1652 (t (complete-with-action
1653 code Info-read-node-completion-table string predicate
))))
1655 ;; Arrange to highlight the proper letters in the completion list buffer.
1656 (defun Info-read-node-name (prompt)
1657 "Read an Info node name with completion, prompting with PROMPT.
1658 A node name can have the form \"NODENAME\", referring to a node
1659 in the current Info file, or \"(FILENAME)NODENAME\"."
1660 (let* ((completion-ignore-case t
)
1661 (Info-read-node-completion-table (Info-build-node-completions))
1662 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1663 (if (equal nodename
"")
1664 (Info-read-node-name prompt
)
1667 (defun Info-build-node-completions ()
1668 (or Info-current-file-completions
1670 ;; Bind this in case the user sets it to nil.
1671 (case-fold-search t
)
1672 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1675 (or Info-tag-table-marker
1676 (error "No Info tags found"))
1677 (if (marker-buffer Info-tag-table-marker
)
1678 (let ((marker Info-tag-table-marker
))
1679 (set-buffer (marker-buffer marker
))
1682 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1684 (cons (list (match-string-no-properties 2))
1687 (goto-char (point-min))
1688 ;; If the buffer begins with a node header, process that first.
1689 (if (Info-node-at-bob-matching node-regexp
)
1690 (setq compl
(list (match-string-no-properties 1))))
1691 ;; Now for the rest of the nodes.
1692 (while (search-forward "\n\^_" nil t
)
1694 (let ((beg (point)))
1696 (if (re-search-backward node-regexp beg t
)
1698 (cons (list (match-string-no-properties 1))
1700 (setq compl
(cons '("*") compl
))
1701 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1703 (defun Info-restore-point (hl)
1704 "If this node has been visited, restore the point value when we left."
1706 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1707 ;; Use string-equal, not equal, to ignore text props.
1708 (string-equal (nth 1 (car hl
)) Info-current-node
))
1710 (goto-char (nth 2 (car hl
)))
1711 (setq hl nil
)) ;terminate the while at next iter
1712 (setq hl
(cdr hl
)))))
1714 (defvar Info-search-history nil
1715 "The history list for `Info-search'.")
1717 (defvar Info-search-case-fold nil
1718 "The value of `case-fold-search' from previous `Info-search' command.")
1720 (defun Info-search (regexp &optional bound _noerror _count direction
)
1721 "Search for REGEXP, starting from point, and select node it's found in.
1722 If DIRECTION is `backward', search in the reverse direction."
1723 (interactive (list (read-string
1724 (if Info-search-history
1725 (format "Regexp search%s (default %s): "
1726 (if case-fold-search
"" " case-sensitively")
1727 (car Info-search-history
))
1728 (format "Regexp search%s: "
1729 (if case-fold-search
"" " case-sensitively")))
1730 nil
'Info-search-history
)))
1732 (when (equal regexp
"")
1733 (setq regexp
(car Info-search-history
)))
1735 (let (found beg-found give-up
1736 (backward (eq direction
'backward
))
1737 (onode Info-current-node
)
1738 (ofile Info-current-file
)
1740 (opoint-min (point-min))
1741 (opoint-max (point-max))
1742 (ostart (window-start))
1743 (osubfile Info-current-subfile
))
1744 (setq Info-search-case-fold case-fold-search
)
1749 ;; Hide Info file header for backward search
1750 (narrow-to-region (save-excursion
1751 (goto-char (point-min))
1752 (search-forward "\n\^_")
1755 (while (and (not give-up
)
1757 (not (funcall isearch-filter-predicate beg-found found
))))
1758 (let ((search-spaces-regexp
1759 (if (or (not isearch-mode
) isearch-regexp
)
1760 Info-search-whitespace-regexp
)))
1762 (re-search-backward regexp bound t
)
1763 (re-search-forward regexp bound t
))
1764 (setq found
(point) beg-found
(if backward
(match-end 0)
1765 (match-beginning 0)))
1766 (setq give-up t
))))))
1768 (when (and isearch-mode Info-isearch-search
1769 (not Info-isearch-initial-node
)
1771 (or give-up
(and found
(not (and (> found opoint-min
)
1772 (< found opoint-max
))))))
1773 (signal 'search-failed
(list regexp
"initial node")))
1775 ;; If no subfiles, give error now.
1777 (if (null Info-current-subfile
)
1779 (signal 'search-failed
(list regexp
"end of manual"))
1780 (let ((search-spaces-regexp
1781 (if (or (not isearch-mode
) isearch-regexp
)
1782 Info-search-whitespace-regexp
)))
1784 (re-search-backward regexp
)
1785 (re-search-forward regexp
))))
1788 (if (and bound
(not found
))
1789 (signal 'search-failed
(list regexp
)))
1791 (unless (or found bound
)
1793 ;; Try other subfiles.
1795 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1796 (goto-char (point-min))
1797 (search-forward "\n\^_\nIndirect:")
1799 (narrow-to-region (point)
1800 (progn (search-forward "\n\^_")
1802 (goto-char (point-min))
1803 ;; Find the subfile we just searched.
1804 (search-forward (concat "\n" osubfile
": "))
1806 (forward-line (if backward
0 1))
1807 (if backward
(forward-char -
1))
1808 ;; Make a list of all following subfiles.
1809 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1810 (while (not (if backward
(bobp) (eobp)))
1812 (re-search-backward "\\(^.*\\): [0-9]+$")
1813 (re-search-forward "\\(^.*\\): [0-9]+$"))
1814 (goto-char (+ (match-end 1) 2))
1815 (setq list
(cons (cons (+ (point-min)
1816 (read (current-buffer)))
1817 (match-string-no-properties 1))
1819 (goto-char (if backward
1820 (1- (match-beginning 0))
1821 (1+ (match-end 0)))))
1822 ;; Put in forward order
1823 (setq list
(nreverse list
))))
1825 (message "Searching subfile %s..." (cdr (car list
)))
1826 (Info-read-subfile (car (car list
)))
1828 ;; Hide Info file header for backward search
1829 (narrow-to-region (save-excursion
1830 (goto-char (point-min))
1831 (search-forward "\n\^_")
1834 (goto-char (point-max)))
1835 (setq list
(cdr list
))
1836 (setq give-up nil found nil
)
1837 (while (and (not give-up
)
1839 (not (funcall isearch-filter-predicate beg-found found
))))
1840 (let ((search-spaces-regexp
1841 (if (or (not isearch-mode
) isearch-regexp
)
1842 Info-search-whitespace-regexp
)))
1844 (re-search-backward regexp nil t
)
1845 (re-search-forward regexp nil t
))
1846 (setq found
(point) beg-found
(if backward
(match-end 0)
1847 (match-beginning 0)))
1855 (signal 'search-failed
(if isearch-mode
1856 (list regexp
"end of manual")
1859 (progn (Info-read-subfile osubfile
)
1862 (set-window-start (selected-window) ostart
)))))
1864 (if (and (string= osubfile Info-current-subfile
)
1865 (> found opoint-min
)
1866 (< found opoint-max
))
1867 ;; Search landed in the same node
1871 (save-match-data (Info-select-node)))
1873 ;; Use string-equal, not equal, to ignore text props.
1874 (or (and (string-equal onode Info-current-node
)
1875 (equal ofile Info-current-file
))
1876 (and isearch-mode isearch-wrapped
1877 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1878 (setq Info-history
(cons (list ofile onode opoint
)
1881 (defun Info-search-case-sensitively ()
1882 "Search for a regexp case-sensitively."
1884 (let ((case-fold-search nil
))
1885 (call-interactively 'Info-search
)))
1887 (defun Info-search-next ()
1888 "Search for next regexp from a previous `Info-search' command."
1890 (let ((case-fold-search Info-search-case-fold
))
1891 (if Info-search-history
1892 (Info-search (car Info-search-history
))
1893 (call-interactively 'Info-search
))))
1895 (defun Info-search-backward (regexp &optional bound noerror count
)
1896 "Search for REGEXP in the reverse direction."
1897 (interactive (list (read-string
1898 (if Info-search-history
1899 (format "Regexp search%s backward (default %s): "
1900 (if case-fold-search
"" " case-sensitively")
1901 (car Info-search-history
))
1902 (format "Regexp search%s backward: "
1903 (if case-fold-search
"" " case-sensitively")))
1904 nil
'Info-search-history
)))
1905 (Info-search regexp bound noerror count
'backward
))
1907 (defun Info-isearch-search ()
1908 (if Info-isearch-search
1909 (lambda (string &optional bound noerror count
)
1911 (Info-search (concat "\\b" (replace-regexp-in-string
1913 (replace-regexp-in-string
1914 "^\\W+\\|\\W+$" "" string
)
1916 ;; Lax version of word search
1917 (if (or isearch-nonincremental
1919 (length (isearch-string-state
1920 (car isearch-cmds
)))))
1923 (unless isearch-forward
'backward
))
1924 (Info-search (if isearch-regexp string
(regexp-quote string
))
1926 (unless isearch-forward
'backward
)))
1928 (let ((isearch-search-fun-function nil
))
1929 (isearch-search-fun))))
1931 (defun Info-isearch-wrap ()
1932 (if Info-isearch-search
1933 (if Info-isearch-initial-node
1935 (if isearch-forward
(Info-top-node) (Info-final-node))
1936 (goto-char (if isearch-forward
(point-min) (point-max))))
1937 (setq Info-isearch-initial-node Info-current-node
)
1938 (setq isearch-wrapped nil
))
1939 (goto-char (if isearch-forward
(point-min) (point-max)))))
1941 (defun Info-isearch-push-state ()
1943 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
1945 (defun Info-isearch-pop-state (_cmd file node
)
1946 (or (and (equal Info-current-file file
)
1947 (equal Info-current-node node
))
1948 (progn (Info-find-node file node
) (sit-for 0))))
1950 (defun Info-isearch-start ()
1951 (setq Info-isearch-initial-node
1952 ;; Don't stop at initial node for nonincremental search.
1953 ;; Otherwise this variable is set after first search failure.
1954 (and isearch-nonincremental Info-current-node
))
1955 (setq Info-isearch-initial-history Info-history
1956 Info-isearch-initial-history-list Info-history-list
)
1957 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
1959 (defun Info-isearch-end ()
1960 ;; Remove intermediate nodes (visited while searching)
1961 ;; from the history. Add only the last node (where Isearch ended).
1962 (if (> (length Info-history
)
1963 (length Info-isearch-initial-history
))
1965 (nthcdr (- (length Info-history
)
1966 (length Info-isearch-initial-history
)
1969 (if (> (length Info-history-list
)
1970 (length Info-isearch-initial-history-list
))
1971 (setq Info-history-list
1972 (cons (car Info-history-list
)
1973 Info-isearch-initial-history-list
)))
1974 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
1976 (defun Info-isearch-filter (beg-found found
)
1977 "Test whether the current search hit is a visible useful text.
1978 Return non-nil if the text from BEG-FOUND to FOUND is visible
1979 and is not in the header line or a tag table."
1981 (let ((backward (< found beg-found
)))
1984 (and (not (eq search-invisible t
))
1986 (or (text-property-not-all found beg-found
'invisible nil
)
1987 (text-property-not-all found beg-found
'display nil
))
1988 (or (text-property-not-all beg-found found
'invisible nil
)
1989 (text-property-not-all beg-found found
'display nil
))))
1990 ;; Skip node header line
1991 (and (save-excursion (forward-line -
1)
1993 (forward-line (if backward -
1 1)))
1994 ;; Skip Tag Table node
1996 (and (search-backward "\^_" nil t
)
1998 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2001 (defun Info-extract-pointer (name &optional errorname
)
2002 "Extract the value of the node-pointer named NAME.
2003 If there is none, use ERRORNAME in the error message;
2004 if ERRORNAME is nil, just return nil."
2005 ;; Bind this in case the user sets it to nil.
2006 (let ((case-fold-search t
))
2008 (goto-char (point-min))
2009 (let ((bound (point)))
2011 (cond ((re-search-backward
2012 (concat name
":" (Info-following-node-name-re)) bound t
)
2013 (match-string-no-properties 1))
2014 ((not (eq errorname t
))
2015 (error "Node has no %s"
2016 (capitalize (or errorname name
)))))))))
2018 (defun Info-following-node-name-re (&optional allowedchars
)
2019 "Return a regexp matching a node name.
2020 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2021 saying which chars may appear in the node name.
2022 Submatch 1 is the complete node name.
2023 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2024 Submatch 3 is the local part of the node name.
2025 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2026 (concat "[ \t\n]*" ;Skip leading space.
2027 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2028 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2029 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2030 "\\|\\)\\)")) ;Allow empty node names.
2032 ;;; For compatibility; other files have used this name.
2033 (defun Info-following-node-name ()
2034 (and (looking-at (Info-following-node-name-re))
2035 (match-string-no-properties 1)))
2038 "Go to the next 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 "next"))))
2046 "Go to the previous node of this node."
2048 ;; In case another window is currently selected
2049 (save-window-excursion
2050 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2051 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2053 (defun Info-up (&optional same-file
)
2054 "Go to the superior node of this node.
2055 If SAME-FILE is non-nil, do not move to a different Info file."
2057 ;; In case another window is currently selected
2058 (save-window-excursion
2059 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2060 (let ((old-node Info-current-node
)
2061 (old-file Info-current-file
)
2062 (node (Info-extract-pointer "up")) p
)
2064 (string-match "^(" node
)
2065 (error "Up node is in another Info file"))
2066 (Info-goto-node node
)
2068 (goto-char (point-min))
2069 (if (and (stringp old-file
)
2070 (search-forward "\n* Menu:" nil t
)
2072 (if (string-equal old-node
"Top")
2073 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2074 (concat "\n\\* +\\(" (regexp-quote old-node
)
2075 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2077 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2079 (Info-restore-point Info-history
)))))
2081 (defun Info-history-back ()
2082 "Go back in the history to the last node visited."
2085 (error "This is the first Info node you looked at"))
2086 (let ((history-forward
2087 (cons (list Info-current-file Info-current-node
(point))
2088 Info-history-forward
))
2089 filename nodename opoint
)
2090 (setq filename
(car (car Info-history
)))
2091 (setq nodename
(car (cdr (car Info-history
))))
2092 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2093 (setq Info-history
(cdr Info-history
))
2094 (Info-find-node filename nodename
)
2095 (setq Info-history
(cdr Info-history
))
2096 (setq Info-history-forward history-forward
)
2097 (goto-char opoint
)))
2099 (defalias 'Info-last
'Info-history-back
)
2101 (defun Info-history-forward ()
2102 "Go forward in the history of visited nodes."
2104 (or Info-history-forward
2105 (error "This is the last Info node you looked at"))
2106 (let ((history-forward (cdr Info-history-forward
))
2107 filename nodename opoint
)
2108 (setq filename
(car (car Info-history-forward
)))
2109 (setq nodename
(car (cdr (car Info-history-forward
))))
2110 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2111 (Info-find-node filename nodename
)
2112 (setq Info-history-forward history-forward
)
2113 (goto-char opoint
)))
2115 (add-to-list 'Info-virtual-files
2117 (toc-nodes . Info-directory-toc-nodes
)
2118 (find-file . Info-directory-find-file
)
2119 (find-node . Info-directory-find-node
)
2122 (defun Info-directory-toc-nodes (filename)
2123 "Directory-specific implementation of `Info-toc-nodes'."
2125 ("Top" nil nil nil
)))
2127 (defun Info-directory-find-file (filename &optional _noerror
)
2128 "Directory-specific implementation of `Info-find-file'."
2131 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2132 "Directory-specific implementation of `Info-find-node-2'."
2136 (defun Info-directory ()
2137 "Go to the Info directory node."
2139 (Info-find-node "dir" "top"))
2141 (add-to-list 'Info-virtual-files
2142 '("\\`\\*History\\*\\'"
2143 (toc-nodes . Info-history-toc-nodes
)
2144 (find-file . Info-history-find-file
)
2145 (find-node . Info-history-find-node
)
2148 (defun Info-history-toc-nodes (filename)
2149 "History-specific implementation of `Info-toc-nodes'."
2151 ("Top" nil nil nil
)))
2153 (defun Info-history-find-file (filename &optional _noerror
)
2154 "History-specific implementation of `Info-find-file'."
2157 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2158 "History-specific implementation of `Info-find-node-2'."
2159 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2160 (or filename Info-current-file
) nodename
))
2161 (insert "Recently Visited Nodes\n")
2162 (insert "**********************\n\n")
2163 (insert "* Menu:\n\n")
2164 (let ((hl (remove '("*History*" "Top") Info-history-list
)))
2166 (let ((file (nth 0 (car hl
)))
2167 (node (nth 1 (car hl
))))
2169 (insert "* " node
": ("
2170 (propertize (or (file-name-directory file
) "") 'invisible t
)
2171 (file-name-nondirectory file
)
2173 (setq hl
(cdr hl
)))))
2175 (defun Info-history ()
2176 "Go to a node with a menu of visited nodes."
2178 (Info-find-node "*History*" "Top")
2179 (Info-next-reference)
2180 (Info-next-reference))
2182 (add-to-list 'Info-virtual-nodes
2184 (find-node . Info-toc-find-node
)
2187 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2188 "Toc-specific implementation of `Info-find-node-2'."
2189 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2190 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2191 (node-list (Info-toc-nodes curr-file
)))
2192 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2193 curr-file curr-node
))
2194 (insert "Table of Contents\n")
2195 (insert "*****************\n\n")
2196 (insert "*Note Top::\n")
2198 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2199 node-list
0 curr-file
)
2201 (let ((Info-hide-note-references 'hide
)
2202 (Info-fontify-visited-nodes nil
))
2203 (setq Info-current-file filename Info-current-node
"*TOC*")
2204 (goto-char (point-min))
2205 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2212 "Go to a node with table of contents of the current Info file.
2213 Table of contents is created from the tree structure of menus."
2215 (Info-find-node Info-current-file
"*TOC*")
2216 (let ((prev-node (nth 1 (car Info-history
))) p
)
2217 (goto-char (point-min))
2218 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2219 (setq p
(- p
(length prev-node
) 2)))
2220 (goto-char (or p
(point-min)))))
2222 (defun Info-toc-insert (nodes node-list level curr-file
)
2223 "Insert table of contents with references to nodes."
2224 (let ((section "Top"))
2226 (let ((node (assoc (car nodes
) node-list
)))
2227 (unless (member (nth 2 node
) (list nil section
))
2228 (insert (setq section
(nth 2 node
)) "\n"))
2229 (insert (make-string level ?
\t))
2230 (insert "*Note " (car nodes
) ":: \n")
2231 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2232 (setq nodes
(cdr nodes
))))))
2234 (defun Info-toc-build (file)
2235 "Build table of contents from menus of Info FILE and its subfiles."
2237 (let* ((file (and (stringp file
) (Info-find-file file
)))
2238 (default-directory (or (and (stringp file
)
2239 (file-name-directory file
))
2241 (main-file (and (stringp file
) file
))
2242 (sections '(("Top" "Top")))
2244 (while (or main-file subfiles
)
2245 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2247 (info-insert-file-contents (or main-file
(car subfiles
)))
2248 (goto-char (point-min))
2249 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2250 (search-forward "Node: " nil
'move
))
2251 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2252 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2254 (upnode (and (re-search-forward
2255 (concat "Up:" (Info-following-node-name-re))
2257 (match-string-no-properties 1)))
2260 (when (and upnode
(string-match "(" upnode
)) (setq upnode nil
))
2261 (when (and (not (Info-index-node nodename file
))
2262 (re-search-forward "^\\* Menu:" bound t
))
2265 (setq bound
(or (and (equal nodename
"Top")
2268 "^[ \t-]*The Detailed Node Listing" nil t
)))
2270 (while (< (point) bound
)
2273 ((looking-at "^\\* +[^:]+:")
2276 (let ((menu-node-name (substring-no-properties
2277 (Info-extract-menu-node-name))))
2278 (setq menu-items
(cons menu-node-name menu-items
))
2279 (if (equal nodename
"Top")
2281 (cons (list menu-node-name section
) sections
)))))
2282 ;; Other non-empty strings in the Top node are section names
2283 ((and (equal nodename
"Top")
2284 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2285 (setq section
(match-string-no-properties 1))))
2287 (beginning-of-line)))
2288 (setq nodes
(cons (list nodename upnode
2289 (cadr (assoc nodename sections
))
2290 (nreverse menu-items
))
2295 (goto-char (point-min))
2296 (if (search-forward "\n\^_\nIndirect:" nil t
)
2297 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2298 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2299 (setq subfiles
(cons (match-string-no-properties 1)
2301 (setq subfiles
(nreverse subfiles
)
2303 (setq subfiles
(cdr subfiles
))))
2307 (defvar Info-toc-nodes nil
2308 "Alist of cached parent-children node information in visited Info files.
2309 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2310 where PARENT is the parent node extracted from the Up pointer,
2311 SECTION is the section name in the Top node where this node is placed,
2312 CHILDREN is a list of child nodes extracted from the node menu.")
2314 (defun Info-toc-nodes (filename)
2315 "Return a node list of Info FILENAME with parent-children information.
2316 This information is cached in the variable `Info-toc-nodes' with the help
2317 of the function `Info-toc-build'."
2320 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2323 (or filename
(setq filename Info-current-file
))
2324 (or (assoc filename Info-toc-nodes
)
2325 ;; Skip virtual Info files
2326 (and (or (not (stringp filename
))
2327 (Info-virtual-file-p filename
))
2328 (push (cons filename nil
) Info-toc-nodes
))
2329 ;; Scan the entire manual and cache the result in Info-toc-nodes
2330 (let ((nodes (Info-toc-build filename
)))
2331 (push (cons filename nodes
) Info-toc-nodes
)
2333 ;; If there is an error, still add nil to the cache
2334 (push (cons filename nil
) Info-toc-nodes
))
2335 (cdr (assoc filename Info-toc-nodes
)))))
2338 (defun Info-follow-reference (footnotename &optional fork
)
2339 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2340 FOOTNOTENAME may be an abbreviation of the reference name.
2341 If FORK is non-nil (interactively with a prefix arg), show the node in
2342 a new Info buffer. If FORK is a string, it is the name to use for the
2345 (let ((completion-ignore-case t
)
2346 (case-fold-search t
)
2347 completions default alt-default
(start-point (point)) str i bol eol
)
2349 ;; Store end and beginning of line.
2350 (setq eol
(line-end-position)
2351 bol
(line-beginning-position))
2352 (goto-char (point-min))
2353 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2354 (setq str
(match-string-no-properties 1))
2355 ;; See if this one should be the default.
2357 (<= (match-beginning 0) start-point
)
2358 (<= start-point
(point))
2360 ;; See if this one should be the alternate default.
2361 (and (null alt-default
)
2362 (and (<= bol
(match-beginning 0))
2364 (setq alt-default t
))
2366 (while (setq i
(string-match "[ \n\t]+" str i
))
2367 (setq str
(concat (substring str
0 i
) " "
2368 (substring str
(match-end 0))))
2370 ;; Record as a completion and perhaps as default.
2371 (if (eq default t
) (setq default str
))
2372 (if (eq alt-default t
) (setq alt-default str
))
2373 ;; Don't add this string if it's a duplicate.
2374 (or (assoc-string str completions t
)
2375 (push str completions
))))
2376 ;; If no good default was found, try an alternate.
2378 (setq default alt-default
))
2379 ;; If only one cross-reference found, then make it default.
2380 (if (eq (length completions
) 1)
2381 (setq default
(car completions
)))
2383 (let ((input (completing-read (if default
2385 "Follow reference named (default "
2387 "Follow reference named: ")
2388 completions nil t
)))
2389 (list (if (equal input
"")
2390 default input
) current-prefix-arg
))
2391 (error "No cross-references in this node"))))
2393 (unless footnotename
2394 (error "No reference was specified"))
2396 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2397 (case-fold-search t
))
2398 (while (setq i
(string-match " " str i
))
2399 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2402 ;; Move point to the beginning of reference if point is on reference
2403 (or (looking-at "\\*note[ \n\t]+")
2404 (and (looking-back "\\*note[ \n\t]+")
2405 (goto-char (match-beginning 0)))
2406 (if (and (save-excursion
2407 (goto-char (+ (point) 5)) ; skip a possible *note
2408 (re-search-backward "\\*note[ \n\t]+" nil t
)
2410 (<= (point) (match-end 0)))
2411 (goto-char (match-beginning 0))))
2412 ;; Go to the reference closest to point
2413 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2414 (+ (match-beginning 0) 5))))
2415 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2416 (+ (match-beginning 0) 5)))))
2417 (goto-char (cond ((and next-ref prev-ref
)
2418 (if (< (abs (- next-ref
(point)))
2419 (abs (- prev-ref
(point))))
2421 ((or next-ref prev-ref
))
2422 ((error "No cross-reference named %s" footnotename
))))
2423 (setq target
(Info-extract-menu-node-name t
))))
2424 (while (setq i
(string-match "[ \t\n]+" target i
))
2425 (setq target
(concat (substring target
0 i
) " "
2426 (substring target
(match-end 0))))
2428 (Info-goto-node target fork
)))
2430 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2431 ;; We allow newline because this is also used in Info-follow-reference,
2432 ;; where the xref name might be wrapped over two lines.
2433 "Regexp that matches a menu entry name upto but not including the colon.
2434 Because of ambiguities, this should be concatenated with something like
2435 `:' and `Info-following-node-name-re'.")
2437 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2438 (skip-chars-forward " \t\n")
2439 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2440 (Info-following-node-name-re
2442 (index-node "^,\t\n")
2443 (multi-line "^.,\t")
2447 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2450 (setq Info-point-loc
2451 (if (match-beginning 5)
2452 (string-to-number (match-string 5))
2453 (buffer-substring-no-properties
2454 (match-beginning 0) (1- (match-beginning 1)))))
2455 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2456 ;;; (setq Info-point-loc
2457 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2459 (replace-regexp-in-string
2461 (or (and (not (equal (match-string-no-properties 2) ""))
2462 (match-string-no-properties 2))
2463 ;; If the node name is the menu entry name (using `entry::').
2464 (buffer-substring-no-properties
2465 (match-beginning 0) (1- (match-beginning 1)))))))
2467 ;; No one calls this.
2468 ;;(defun Info-menu-item-sequence (list)
2470 ;; (Info-menu (car list))
2471 ;; (setq list (cdr list))))
2473 (defvar Info-complete-menu-buffer
)
2474 (defvar Info-complete-next-re nil
)
2475 (defvar Info-complete-nodes nil
)
2476 (defvar Info-complete-cache nil
)
2478 (defconst Info-node-spec-re
2479 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2480 "Regexp to match the text after a : until the terminating `.'.")
2482 (defun Info-complete-menu-item (string predicate action
)
2483 ;; This uses two dynamically bound variables:
2484 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2485 ;; is the menu of items we're trying to complete.
2486 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2487 ;; also look for menu items in subsequent nodes as long as those
2488 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2490 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2491 ;; also look for menu items in these nodes. This feature is currently
2492 ;; only used for completion in Info-index.
2494 ;; Note that `Info-complete-menu-buffer' could be current already,
2495 ;; so we want to save point.
2496 (with-current-buffer Info-complete-menu-buffer
2498 (let ((completion-ignore-case t
)
2499 (case-fold-search t
)
2500 (orignode Info-current-node
)
2502 (goto-char (point-min))
2503 (search-forward "\n* Menu:")
2505 ((eq (car-safe action
) 'boundaries
) nil
)
2506 ((eq action
'lambda
)
2508 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2510 (let ((pattern (concat "\n\\* +\\("
2511 (regexp-quote string
)
2512 Info-menu-entry-name-re
"\\):"
2515 (complete-nodes Info-complete-nodes
))
2517 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2518 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2519 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2520 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2521 (let ((prev (nth 3 Info-complete-cache
)))
2522 (eq t
(compare-strings string
0 (length prev
)
2524 ;; We can reuse the previous list.
2525 (setq completions
(nth 4 Info-complete-cache
))
2526 ;; The cache can't be used.
2529 (while (re-search-forward pattern nil t
)
2530 (push (match-string-no-properties 1)
2532 ;; Check subsequent nodes if applicable.
2533 (or (and Info-complete-next-re
2534 (setq nextnode
(Info-extract-pointer "next" t
))
2535 (string-match Info-complete-next-re nextnode
))
2537 (setq complete-nodes
(cdr complete-nodes
)
2538 nextnode
(car complete-nodes
)))))
2539 (Info-goto-node nextnode
))
2540 ;; Go back to the start node (for the next completion).
2541 (unless (equal Info-current-node orignode
)
2542 (Info-goto-node orignode
))
2543 ;; Update the cache.
2544 (set (make-local-variable 'Info-complete-cache
)
2545 (list Info-current-file Info-current-node
2546 Info-complete-next-re string completions
2547 Info-complete-nodes
)))
2548 (complete-with-action action completions string predicate
))))))))
2551 (defun Info-menu (menu-item &optional fork
)
2552 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2553 The menu item should one of those listed in the current node's menu.
2554 Completion is allowed, and the default menu item is the one point is on.
2555 If FORK is non-nil (interactively with a prefix arg), show the node in
2556 a new Info buffer. If FORK is a string, it is the name to use for the
2559 (let (;; If point is within a menu item, use that item as the default
2563 (case-fold-search t
))
2565 (goto-char (point-min))
2566 (if (not (search-forward "\n* menu:" nil t
))
2567 (error "No menu in this node"))
2573 (if (re-search-backward (concat "\n\\* +\\("
2574 Info-menu-entry-name-re
2576 (setq default
(match-string-no-properties 1))))))
2579 (setq item
(let ((completion-ignore-case t
)
2580 (Info-complete-menu-buffer (current-buffer)))
2581 (completing-read (if default
2582 (format "Menu item (default %s): "
2585 'Info-complete-menu-item nil t
)))
2586 ;; we rely on the fact that completing-read accepts an input
2587 ;; of "" even when the require-match argument is true and ""
2588 ;; is not a valid possibility
2589 (if (string= item
"")
2594 (list item current-prefix-arg
))))
2595 ;; there is a problem here in that if several menu items have the same
2596 ;; name you can only go to the node of the first with this command.
2597 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2599 (defun Info-extract-menu-item (menu-item)
2600 (setq menu-item
(regexp-quote menu-item
))
2601 (let ((case-fold-search t
))
2603 (let ((case-fold-search t
))
2604 (goto-char (point-min))
2605 (or (search-forward "\n* menu:" nil t
)
2606 (error "No menu in this node"))
2607 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2608 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2609 (error "No such item in menu"))
2612 (Info-extract-menu-node-name nil
(Info-index-node))))))
2614 ;; If COUNT is nil, use the last item in the menu.
2615 (defun Info-extract-menu-counting (count &optional no-detail
)
2616 (let ((case-fold-search t
))
2618 (let ((case-fold-search t
)
2619 (bound (when (and no-detail
2621 "^[ \t-]*The Detailed Node Listing" nil t
))
2622 (match-beginning 0))))
2623 (goto-char (point-min))
2624 (or (search-forward "\n* menu:" bound t
)
2625 (error "No menu in this node"))
2627 (or (search-forward "\n* " bound t count
)
2628 (error "Too few items in menu"))
2629 (while (search-forward "\n* " bound t
)
2631 (Info-extract-menu-node-name nil
(Info-index-node))))))
2633 (defun Info-nth-menu-item ()
2634 "Go to the node of the Nth menu item.
2635 N is the digit argument used to invoke this command."
2638 (Info-extract-menu-counting
2639 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2641 (defun Info-top-node ()
2642 "Go to the Top node of this file."
2644 (Info-goto-node "Top"))
2646 (defun Info-final-node ()
2647 "Go to the final node in this file."
2649 (Info-goto-node "Top")
2650 (let ((Info-history nil
)
2651 (case-fold-search t
))
2652 ;; Go to the last node in the menu of Top. But don't delve into
2653 ;; detailed node listings.
2654 (Info-goto-node (Info-extract-menu-counting nil t
))
2655 ;; If the last node in the menu is not last in pointer structure,
2656 ;; move forward (but not down- or upward - see bug#1116) until we
2657 ;; can't go any farther.
2658 (while (Info-forward-node t t t
) nil
)
2659 ;; Then keep moving down to last subnode, unless we reach an index.
2660 (while (and (not (Info-index-node))
2661 (save-excursion (search-forward "\n* Menu:" nil t
)))
2662 (Info-goto-node (Info-extract-menu-counting nil
)))))
2664 (defun Info-forward-node (&optional not-down not-up no-error
)
2665 "Go forward one node, considering all nodes as forming one sequence."
2667 (goto-char (point-min))
2669 (let ((case-fold-search t
))
2670 ;; three possibilities, in order of priority:
2671 ;; 1. next node is in a menu in this node (but not in an index)
2672 ;; 2. next node is next at same level
2673 ;; 3. next node is up and next
2674 (cond ((and (not not-down
)
2675 (save-excursion (search-forward "\n* menu:" nil t
))
2676 (not (Info-index-node)))
2677 (Info-goto-node (Info-extract-menu-counting 1))
2679 ((save-excursion (search-backward "next:" nil t
))
2683 (save-excursion (search-backward "up:" nil t
))
2684 ;; Use string-equal, not equal, to ignore text props.
2685 (not (string-equal (downcase (Info-extract-pointer "up"))
2687 (let ((old-node Info-current-node
))
2689 (let ((old-history Info-history
)
2692 (setq success
(Info-forward-node t nil no-error
))
2693 (or success
(Info-goto-node old-node
)))
2694 (if Info-history-skip-intermediate-nodes
2695 (setq Info-history old-history
)))))
2697 (t (error "No pointer forward from this node")))))
2699 (defun Info-backward-node ()
2700 "Go backward one node, considering all nodes as forming one sequence."
2702 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2703 (upnode (Info-extract-pointer "up" t
))
2704 (case-fold-search t
))
2705 (cond ((and upnode
(string-match "(" upnode
))
2706 (error "First node in file"))
2707 ((and upnode
(or (null prevnode
)
2708 ;; Use string-equal, not equal,
2709 ;; to ignore text properties.
2710 (string-equal (downcase prevnode
)
2711 (downcase upnode
))))
2714 ;; If we move back at the same level,
2715 ;; go down to find the last subnode*.
2717 (let ((old-history Info-history
))
2718 (while (and (not (Info-index-node))
2719 (save-excursion (search-forward "\n* Menu:" nil t
)))
2720 (Info-goto-node (Info-extract-menu-counting nil
)))
2721 (if Info-history-skip-intermediate-nodes
2722 (setq Info-history old-history
))))
2724 (error "No pointer backward from this node")))))
2727 "Exit Info by selecting some other buffer."
2730 (save-buffers-kill-emacs)
2733 (defun Info-next-menu-item ()
2734 "Go to the node of the next menu item."
2736 ;; Bind this in case the user sets it to nil.
2737 (let* ((case-fold-search t
)
2741 (search-forward "\n* menu:" nil t
)
2742 (and (search-forward "\n* " nil t
)
2743 (Info-extract-menu-node-name)))))
2744 (if node
(Info-goto-node node
)
2745 (error "No more items in menu"))))
2747 (defun Info-last-menu-item ()
2748 "Go to the node of the previous menu item."
2752 ;; Bind this in case the user sets it to nil.
2753 (let* ((case-fold-search t
)
2754 (beg (save-excursion
2755 (and (search-backward "\n* menu:" nil t
)
2757 (or (and beg
(search-backward "\n* " beg t
))
2758 (error "No previous items in menu")))
2759 (Info-goto-node (save-excursion
2760 (goto-char (match-end 0))
2761 (Info-extract-menu-node-name)))))
2763 (defmacro Info-no-error
(&rest body
)
2764 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2766 (defun Info-next-preorder ()
2767 "Go to the next subnode or the next node, or go up a level."
2769 (cond ((Info-no-error (Info-next-menu-item)))
2770 ((Info-no-error (Info-next)))
2771 ((Info-no-error (Info-up t
))
2772 ;; Since we have already gone thru all the items in this menu,
2773 ;; go up to the end of this node.
2774 (goto-char (point-max))
2775 ;; Since logically we are done with the node with that menu,
2776 ;; move on from it. But don't add intermediate nodes
2777 ;; to the history on recursive calls.
2778 (let ((old-history Info-history
))
2779 (Info-next-preorder)
2780 (if Info-history-skip-intermediate-nodes
2781 (setq Info-history old-history
))))
2783 (error "No more nodes"))))
2785 (defun Info-last-preorder ()
2786 "Go to the last node, popping up a level if there is none."
2788 (cond ((and Info-scroll-prefer-subnodes
2790 (Info-last-menu-item)
2791 ;; If we go down a menu item, go to the end of the node
2792 ;; so we can scroll back through it.
2793 (goto-char (point-max))))
2794 ;; Keep going down, as long as there are nested menu nodes.
2795 (let ((old-history Info-history
))
2796 (while (Info-no-error
2797 (Info-last-menu-item)
2798 ;; If we go down a menu item, go to the end of the node
2799 ;; so we can scroll back through it.
2800 (goto-char (point-max))))
2801 (if Info-history-skip-intermediate-nodes
2802 (setq Info-history old-history
)))
2804 ((and (Info-no-error (Info-extract-pointer "prev"))
2805 (not (equal (Info-extract-pointer "up")
2806 (Info-extract-pointer "prev"))))
2807 (Info-no-error (Info-prev))
2808 (goto-char (point-max))
2809 (let ((old-history Info-history
))
2810 (while (Info-no-error
2811 (Info-last-menu-item)
2812 ;; If we go down a menu item, go to the end of the node
2813 ;; so we can scroll back through it.
2814 (goto-char (point-max))))
2815 (if Info-history-skip-intermediate-nodes
2816 (setq Info-history old-history
)))
2818 ((Info-no-error (Info-up t
))
2819 (goto-char (point-min))
2820 (let ((case-fold-search t
))
2821 (or (search-forward "\n* Menu:" nil t
)
2822 (goto-char (point-max)))))
2823 (t (error "No previous nodes"))))
2825 (defun Info-scroll-up ()
2826 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2827 Once you scroll far enough in a node that its menu appears on the screen
2828 but after point, the next scroll moves into its first subnode, unless
2829 `Info-scroll-prefer-subnodes' is nil.
2831 When you scroll past the end of a node, that goes to the next node if
2832 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2833 if this node has no successor, it moves to the parent node's successor,
2834 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2835 the menu of a node, it moves to subnode indicated by the following menu
2836 item. (That case won't normally result from this command, but can happen
2840 (if (or (< (window-start) (point-min))
2841 (> (window-start) (point-max)))
2842 (set-window-start (selected-window) (point)))
2843 (let* ((case-fold-search t
)
2844 (virtual-end (save-excursion
2845 (goto-char (point-min))
2846 (if (and Info-scroll-prefer-subnodes
2847 (search-forward "\n* Menu:" nil t
))
2850 (if (or (< virtual-end
(window-start))
2851 (pos-visible-in-window-p virtual-end
))
2853 (Info-scroll-prefer-subnodes (Info-next-preorder))
2854 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2855 (t (Info-next-preorder)))
2858 (defun Info-mouse-scroll-up (e)
2859 "Scroll one screenful forward in Info, using the mouse.
2860 See `Info-scroll-up'."
2862 (save-selected-window
2864 (select-window (posn-window (event-start e
))))
2867 (defun Info-scroll-down ()
2868 "Scroll one screenful back in Info, considering all nodes as one sequence.
2869 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2870 is non-nil, this goes to its last subnode. When you scroll past the
2871 beginning of a node, that goes to the previous node or back up to the
2874 (if (or (< (window-start) (point-min))
2875 (> (window-start) (point-max)))
2876 (set-window-start (selected-window) (point)))
2877 (let* ((case-fold-search t
)
2878 (current-point (point))
2880 (and Info-scroll-prefer-subnodes
2882 (setq current-point
(line-beginning-position))
2883 (goto-char (point-min))
2884 (search-forward "\n* Menu:" current-point t
)))))
2886 (pos-visible-in-window-p (point-min) nil t
))
2887 (Info-last-preorder)
2890 (defun Info-mouse-scroll-down (e)
2891 "Scroll one screenful backward in Info, using the mouse.
2892 See `Info-scroll-down'."
2894 (save-selected-window
2896 (select-window (posn-window (event-start e
))))
2897 (Info-scroll-down)))
2899 (defun Info-next-reference (&optional recur
)
2900 "Move cursor to the next cross-reference or menu item in the node."
2902 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2904 (case-fold-search t
))
2905 (or (eobp) (forward-char 1))
2906 (or (re-search-forward pat nil t
)
2908 (goto-char (point-min))
2909 (or (re-search-forward pat nil t
)
2912 (error "No cross references in this node")))))
2913 (goto-char (or (match-beginning 1) (match-beginning 0)))
2914 (if (looking-at "\\* Menu:")
2916 (error "No cross references in this node")
2917 (Info-next-reference t
))
2918 (if (looking-at "^\\* ")
2919 (forward-char 2)))))
2921 (defun Info-prev-reference (&optional recur
)
2922 "Move cursor to the previous cross-reference or menu item in the node."
2924 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2926 (case-fold-search t
))
2927 (or (re-search-backward pat nil t
)
2929 (goto-char (point-max))
2930 (or (re-search-backward pat nil t
)
2933 (error "No cross references in this node")))))
2934 (goto-char (or (match-beginning 1) (match-beginning 0)))
2935 (if (looking-at "\\* Menu:")
2937 (error "No cross references in this node")
2938 (Info-prev-reference t
))
2939 (if (looking-at "^\\* ")
2940 (forward-char 2)))))
2942 (defvar Info-index-nodes nil
2943 "Alist of cached index node names of visited Info files.
2944 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2946 (defun Info-index-nodes (&optional file
)
2947 "Return a list of names of all index nodes in Info FILE.
2948 If FILE is omitted, it defaults to the current Info file.
2949 First look in a list of cached index node names. Then scan Info
2950 file and its subfiles for nodes with the index cookie. Then try
2951 to find index nodes starting from the first node in the top level
2952 menu whose name contains the word \"Index\", plus any immediately
2953 following nodes whose names also contain the word \"Index\"."
2954 (or file
(setq file Info-current-file
))
2955 (or (assoc file Info-index-nodes
)
2956 ;; Skip virtual Info files
2957 (and (or (not (stringp file
))
2958 (Info-virtual-file-p file
))
2959 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2960 (if (Info-file-supports-index-cookies file
)
2961 ;; Find nodes with index cookie
2962 (let* ((default-directory (or (and (stringp file
)
2963 (file-name-directory
2964 (setq file
(Info-find-file file
))))
2966 Info-history Info-history-list Info-fontify-maximum-menu-size
2967 (main-file file
) subfiles nodes
)
2970 (while (or main-file subfiles
)
2972 (info-insert-file-contents (or main-file
(car subfiles
)))
2973 (goto-char (point-min))
2974 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2976 (re-search-backward "^\^_")
2977 (search-forward "Node: ")
2978 (setq nodes
(cons (Info-following-node-name) nodes
))))
2981 (goto-char (point-min))
2982 (if (search-forward "\n\^_\nIndirect:" nil t
)
2983 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2984 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2985 (setq subfiles
(cons (match-string-no-properties 1)
2987 (setq subfiles
(nreverse subfiles
)
2989 (setq subfiles
(cdr subfiles
)))))
2992 (setq nodes
(nreverse nodes
)
2993 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2995 ;; Else find nodes with the word "Index" in the node name
2996 (let ((case-fold-search t
)
2997 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3002 (Info-find-node file
"Top")
3003 (when (and (search-forward "\n* menu:" nil t
)
3004 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
3005 (goto-char (match-beginning 1))
3006 (setq nodes
(list (Info-extract-menu-node-name)))
3007 (Info-goto-node (car nodes
))
3008 (while (and (setq node
(Info-extract-pointer "next" t
))
3009 (string-match "\\<Index\\>" node
))
3011 (Info-goto-node node
))))
3014 (setq nodes
(nreverse nodes
)
3015 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3017 ;; If file has no index nodes, still add it to the cache
3018 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3019 (cdr (assoc file Info-index-nodes
)))
3021 (defun Info-index-node (&optional node file
)
3022 "Return non-nil value if NODE is an index node.
3023 If NODE is nil, check the current Info node.
3024 If FILE is nil, check the current Info file."
3025 (or file
(setq file Info-current-file
))
3026 (if (and (or (and node
(not (equal node Info-current-node
)))
3027 (assoc file Info-index-nodes
))
3028 (not Info-current-node-virtual
))
3029 (member (or node Info-current-node
) (Info-index-nodes file
))
3030 ;; Don't search all index nodes if request is only for the current node
3031 ;; and file is not in the cache of index nodes
3033 (if (Info-file-supports-index-cookies file
)
3035 (goto-char (+ (or (save-excursion
3036 (search-backward "\n\^_" nil t
))
3038 (search-forward "\0\b[index\0\b]"
3040 (search-forward "\n\^_" nil t
))
3042 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3044 (defun Info-goto-index ()
3045 "Go to the first index node."
3046 (let ((node (car (Info-index-nodes))))
3047 (or node
(error "No index"))
3048 (Info-goto-node node
)))
3051 (defun Info-index (topic)
3052 "Look up a string TOPIC in the index for this manual and go to that entry.
3053 If there are no exact matches to the specified topic, this chooses
3054 the first match which is a case-insensitive substring of a topic.
3055 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3056 Give an empty topic name to go to the Index node itself."
3059 (let ((completion-ignore-case t
)
3060 (Info-complete-menu-buffer (clone-buffer))
3061 (Info-complete-nodes (Info-index-nodes))
3062 (Info-history-list nil
))
3063 (if (equal Info-current-file
"dir")
3064 (error "The Info directory node has no index; use m to select a manual"))
3066 (with-current-buffer Info-complete-menu-buffer
3068 (completing-read "Index topic: " 'Info-complete-menu-item
))
3069 (kill-buffer Info-complete-menu-buffer
)))))
3070 (if (equal Info-current-file
"dir")
3071 (error "The Info directory node has no index; use m to select a manual"))
3072 ;; Strip leading colon in topic; index format does not allow them.
3073 (if (and (stringp topic
)
3074 (> (length topic
) 0)
3075 (= (aref topic
0) ?
:))
3076 (setq topic
(substring topic
1)))
3077 (let ((orignode Info-current-node
)
3078 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3079 (regexp-quote topic
)))
3080 node
(nodes (Info-index-nodes))
3081 (ohist-list Info-history-list
)
3082 (case-fold-search t
))
3084 (or (equal topic
"")
3087 ;; We bind Info-history to nil for internal node-switches so
3088 ;; that we don't put junk in the history. In the first
3089 ;; Info-goto-index call, above, we do update the history
3090 ;; because that is what the user's previous node choice into it.
3095 (goto-char (point-min))
3096 (while (re-search-forward pattern nil t
)
3097 (push (list (match-string-no-properties 1)
3098 (match-string-no-properties 2)
3100 (string-to-number (concat "0"
3103 (setq nodes
(cdr nodes
) node
(car nodes
)))
3104 (Info-goto-node node
))
3107 (Info-goto-node orignode
)
3108 (error "No `%s' in index" topic
)))
3109 ;; Here it is a feature that assoc is case-sensitive.
3110 (while (setq found
(assoc topic matches
))
3111 (setq exact
(cons found exact
)
3112 matches
(delq found matches
)))
3113 (setq Info-history-list ohist-list
)
3114 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3115 (Info-index-next 0)))))
3117 (defun Info-index-next (num)
3118 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3120 (or Info-index-alternatives
3121 (error "No previous `i' command"))
3123 (setq num
(+ num
(length Info-index-alternatives
))))
3125 (setq Info-index-alternatives
3126 (nconc (cdr Info-index-alternatives
)
3127 (list (car Info-index-alternatives
)))
3129 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3130 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3131 ;; Forward 2 lines less because `Info-find-node-2' initially
3132 ;; puts point to the 2nd line.
3133 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3134 (forward-line 3) ; don't search in headers
3135 (let ((name (car (car Info-index-alternatives
))))
3136 (Info-find-index-name name
)))
3137 (message "Found `%s' in %s. %s"
3138 (car (car Info-index-alternatives
))
3139 (nth 2 (car Info-index-alternatives
))
3140 (if (cdr Info-index-alternatives
)
3141 (format "(%s total; use `%s' for next)"
3142 (length Info-index-alternatives
)
3143 (key-description (where-is-internal
3144 'Info-index-next overriding-local-map
3148 (defun Info-find-index-name (name)
3149 "Move point to the place within the current node where NAME is defined."
3150 (let ((case-fold-search t
))
3151 (if (or (re-search-forward (format
3152 "[a-zA-Z]+: %s\\( \\|$\\)"
3153 (regexp-quote name
)) nil t
)
3154 ;; Find a function definition with a return type.
3155 (re-search-forward (format
3156 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3157 (regexp-quote name
)) nil t
)
3158 (search-forward (format "`%s'" name
) nil t
)
3159 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3161 (format "`%s'" (substring name
0 (match-beginning 1)))
3163 (search-forward name nil t
)
3164 ;; Try again without the " <1>" makeinfo can append
3165 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3166 (Info-find-index-name (match-string 1 name
))))
3167 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3168 (goto-char (point-min)))))
3170 (add-to-list 'Info-virtual-nodes
3171 '("\\`\\*Index.*\\*\\'"
3172 (find-node . Info-virtual-index-find-node
)
3176 (defvar Info-virtual-index-nodes nil
3177 "Alist of cached matched index search nodes.
3178 Each element is ((FILENAME . TOPIC) MATCHES) where
3179 FILENAME is the file name of the manual,
3180 TOPIC is the search string given as an argument to `Info-virtual-index',
3181 MATCHES is a list of index matches found by `Info-index'.")
3183 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3184 "Index-specific implementation of `Info-find-node-2'."
3185 ;; Generate Index-like menu of matches
3186 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3187 ;; Generate Index-like menu of matches
3188 (let* ((topic (match-string 1 nodename
))
3189 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3190 Info-virtual-index-nodes
))))
3191 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3192 (or filename Info-current-file
) nodename
))
3193 (insert "Info Virtual Index\n")
3194 (insert "******************\n\n")
3195 (insert "Index entries that match `" topic
"':\n\n")
3196 (insert "\0\b[index\0\b]\n")
3198 (insert "No matches found.\n")
3199 (insert "* Menu:\n\n")
3200 (dolist (entry matches
)
3201 (insert (format "* %-38s %s.%s\n"
3202 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3205 (format " (line %s)" (nth 3 entry
))
3207 ;; Else, Generate a list of previous search results
3208 (let ((nodes (reverse Info-virtual-index-nodes
)))
3209 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3210 (or filename Info-current-file
) nodename
))
3211 (insert "Info Virtual Index\n")
3212 (insert "******************\n\n")
3213 (insert "This is a list of search results produced by\n"
3214 "`Info-virtual-index' for the current manual.\n\n")
3215 (insert "* Menu:\n\n")
3216 (dolist (nodeinfo nodes
)
3217 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3219 (format "* %-20s %s.\n"
3220 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3221 (cdr (nth 0 nodeinfo
)))))))))
3223 (defun Info-virtual-index (topic)
3224 "Show a node with all lines in the index containing a string TOPIC.
3225 Like `Info-index' but displays a node with index search results.
3226 Give an empty topic name to go to the node with links to previous
3228 ;; `interactive' is a copy from `Info-index'
3231 (let ((completion-ignore-case t
)
3232 (Info-complete-menu-buffer (clone-buffer))
3233 (Info-complete-nodes (Info-index-nodes))
3234 (Info-history-list nil
))
3235 (if (equal Info-current-file
"dir")
3236 (error "The Info directory node has no index; use m to select a manual"))
3238 (with-current-buffer Info-complete-menu-buffer
3240 (completing-read "Index topic: " 'Info-complete-menu-item
))
3241 (kill-buffer Info-complete-menu-buffer
)))))
3242 (if (equal topic
"")
3243 (Info-find-node Info-current-file
"*Index*")
3244 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3245 (let ((orignode Info-current-node
)
3246 (ohist-list Info-history-list
))
3247 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3249 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3250 Info-virtual-index-nodes
)
3251 ;; Clean up unnecessary side-effects of `Info-index'.
3252 (setq Info-history-list ohist-list
)
3253 (Info-goto-node orignode
)
3255 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3257 (add-to-list 'Info-virtual-files
3258 '("\\`\\*Apropos\\*\\'"
3259 (toc-nodes . Info-apropos-toc-nodes
)
3260 (find-file . Info-apropos-find-file
)
3261 (find-node . Info-apropos-find-node
)
3265 (defvar Info-apropos-file
"*Apropos*"
3266 "Info file name of the virtual manual for matches of `info-apropos'.")
3268 (defvar Info-apropos-nodes nil
3269 "Alist of cached apropos matched nodes.
3270 Each element is (NODENAME STRING MATCHES) where
3271 NODENAME is the name of the node that holds the search result,
3272 STRING is the search string given as an argument to `info-apropos',
3273 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3275 (defun Info-apropos-toc-nodes (filename)
3276 "Apropos-specific implementation of `Info-toc-nodes'."
3277 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3279 ("Top" nil nil
,nodes
)
3280 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3282 (defun Info-apropos-find-file (filename &optional _noerror
)
3283 "Apropos-specific implementation of `Info-find-file'."
3286 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3287 "Apropos-specific implementation of `Info-find-node-2'."
3288 (if (equal nodename
"Top")
3289 ;; Generate Top menu
3290 (let ((nodes (reverse Info-apropos-nodes
)))
3291 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3292 Info-apropos-file nodename
))
3293 (insert "Apropos Index\n")
3294 (insert "*************\n\n")
3295 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3296 (insert "* Menu:\n\n")
3297 (dolist (nodeinfo nodes
)
3298 (insert (format "* %-20s %s.\n"
3299 (format "%s::" (nth 0 nodeinfo
))
3300 (nth 1 nodeinfo
)))))
3301 ;; Else, Generate Index-like menu of matches
3302 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3303 (matches (nth 2 nodeinfo
)))
3305 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3306 Info-apropos-file nodename
))
3307 (insert "Apropos Index\n")
3308 (insert "*************\n\n")
3309 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3310 (insert "\0\b[index\0\b]\n")
3312 (insert "No matches found.\n")
3313 (insert "* Menu:\n\n")
3314 (dolist (entry matches
)
3315 (insert (format "* %-38s (%s)%s.%s\n"
3316 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3320 (format " (line %s)" (nth 3 entry
))
3323 (defun Info-apropos-matches (string)
3324 "Collect STRING matches from all known Info files on your system.
3325 Return a list of matches where each element is in the format
3326 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3327 (unless (string= string
"")
3328 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3329 (regexp-quote string
)))
3330 (ohist Info-history
)
3331 (ohist-list Info-history-list
)
3332 (current-node Info-current-node
)
3333 (current-file Info-current-file
)
3334 manuals matches node nodes
)
3335 (let ((Info-fontify-maximum-menu-size nil
))
3337 ;; current-node and current-file are nil when they invoke info-apropos
3338 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3339 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3340 ;; the search is complete.
3341 (when (null current-node
)
3342 (setq current-file Info-current-file
)
3343 (setq current-node Info-current-node
))
3344 (message "Searching indices...")
3345 (goto-char (point-min))
3346 (re-search-forward "\\* Menu: *\n" nil t
)
3347 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3348 ;; add-to-list makes sure we don't have duplicates in `manuals',
3349 ;; so that the following dolist loop runs faster.
3350 (add-to-list 'manuals
(match-string 1)))
3351 (dolist (manual (nreverse manuals
))
3352 (message "Searching %s" manual
)
3354 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3356 (Info-find-node manual
(car nodes
))
3359 (goto-char (point-min))
3360 (while (re-search-forward pattern nil t
)
3363 (match-string-no-properties 1)
3364 (match-string-no-properties 2)
3365 (match-string-no-properties 3))
3367 (setq nodes
(cdr nodes
) node
(car nodes
)))
3368 (Info-goto-node node
))))
3370 (message "%s" (if (eq (car-safe err
) 'error
)
3373 (Info-find-node current-file current-node
)
3374 (setq Info-history ohist
3375 Info-history-list ohist-list
)
3376 (message "Searching indices...done")
3377 (or (nreverse matches
) t
))))
3380 (defun info-apropos (string)
3381 "Grovel indices of all known Info files on your system for STRING.
3382 Build a menu of the possible matches."
3383 (interactive "sIndex apropos: ")
3384 (if (equal string
"")
3385 (Info-find-node Info-apropos-file
"Top")
3386 (let* ((nodes Info-apropos-nodes
) nodename
)
3387 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3388 (setq nodes
(cdr nodes
)))
3390 (Info-find-node Info-apropos-file
(car (car nodes
)))
3391 (setq nodename
(format "Index for `%s'" string
))
3392 (push (list nodename string
(Info-apropos-matches string
))
3394 (Info-find-node Info-apropos-file nodename
)))))
3396 (add-to-list 'Info-virtual-files
3397 '("\\`\\*Finder.*\\*\\'"
3398 (find-file . Info-finder-find-file
)
3399 (find-node . Info-finder-find-node
)
3402 (defvar Info-finder-file
"*Finder*"
3403 "Info file name of the virtual Info keyword finder manual.")
3405 (defun Info-finder-find-file (filename &optional _noerror
)
3406 "Finder-specific implementation of `Info-find-file'."
3409 (defvar finder-known-keywords
)
3410 (declare-function find-library-name
"find-func" (library))
3411 (declare-function finder-unknown-keywords
"finder" ())
3412 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3413 (defvar finder-keywords-hash
)
3414 (defvar package--builtins
) ; finder requires package
3416 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3417 "Finder-specific implementation of `Info-find-node-2'."
3420 ((equal nodename
"Top")
3421 ;; Display Top menu with descriptions of the keywords
3422 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3423 Info-finder-file nodename
))
3424 (insert "Finder Keywords\n")
3425 (insert "***************\n\n")
3426 (insert "* Menu:\n\n")
3427 (dolist (assoc (append '((all .
"All package info")
3428 (unknown .
"Unknown keywords"))
3429 finder-known-keywords
))
3430 (let ((keyword (car assoc
)))
3431 (insert (format "* %s %s.\n"
3432 (concat (symbol-name keyword
) ": "
3433 "Keyword " (symbol-name keyword
) ".")
3435 ((equal nodename
"Keyword unknown")
3436 ;; Display unknown keywords
3437 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3438 Info-finder-file nodename
))
3439 (insert "Finder Unknown Keywords\n")
3440 (insert "***********************\n\n")
3441 (insert "* Menu:\n\n")
3444 (insert (format "* %-14s %s.\n"
3445 (concat (symbol-name (car assoc
)) ": "
3446 "Keyword " (symbol-name (car assoc
)) ".")
3448 (finder-unknown-keywords)))
3449 ((equal nodename
"Keyword all")
3450 ;; Display all package info.
3451 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3452 Info-finder-file nodename
))
3453 (insert "Finder Package Info\n")
3454 (insert "*******************\n\n")
3455 (insert "* Menu:\n\n")
3457 (dolist (package package--builtins
)
3458 (setq desc
(cdr-safe package
))
3459 (when (vectorp desc
)
3460 (insert (format "* %-16s %s.\n"
3461 (concat (symbol-name (car package
)) "::")
3463 ((string-match "\\`Keyword " nodename
)
3464 (setq nodename
(substring nodename
(match-end 0)))
3465 ;; Display packages that match the keyword
3466 ;; or the list of keywords separated by comma.
3467 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3468 Info-finder-file nodename
))
3469 (insert "Finder Packages\n")
3470 (insert "***************\n\n")
3472 "The following packages match the keyword `" nodename
"':\n\n")
3473 (insert "* Menu:\n\n")
3475 (mapcar 'intern
(if (string-match-p "," nodename
)
3476 (split-string nodename
",[ \t\n]*" t
)
3479 (dolist (keyword keywords
)
3480 (push (copy-tree (gethash keyword finder-keywords-hash
)) hits
))
3481 (setq hits
(delete-dups (apply 'append hits
)))
3482 (dolist (package hits
)
3483 (setq desc
(cdr-safe (assq package package--builtins
)))
3484 (when (vectorp desc
)
3485 (insert (format "* %-16s %s.\n"
3486 (concat (symbol-name package
) "::")
3489 ;; Display commentary section
3490 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3491 Info-finder-file nodename
))
3492 (insert "Finder Commentary\n")
3493 (insert "*****************\n\n")
3495 "Commentary section of the package `" nodename
"':\n\n")
3496 (let ((str (lm-commentary (find-library-name nodename
))))
3498 (insert "Can't find any Commentary section\n\n")
3502 (goto-char (point-min))
3503 (delete-blank-lines)
3504 (goto-char (point-max))
3505 (delete-blank-lines)
3506 (goto-char (point-min))
3507 (while (re-search-forward "^;+ ?" nil t
)
3508 (replace-match "" nil nil
))
3509 (buffer-string))))))))
3512 (defun info-finder (&optional keywords
)
3513 "Display descriptions of the keywords in the Finder virtual manual.
3514 In interactive use, a prefix argument directs this command to read
3515 a list of keywords separated by comma. After that, it displays a node
3516 with a list of packages that contain all specified keywords."
3518 (when current-prefix-arg
3521 (completing-read-multiple
3522 "Keywords (separated by comma): "
3523 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3524 (finder-unknown-keywords))))
3528 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3529 (Info-find-node Info-finder-file
"Top")))
3532 (defun Info-undefined ()
3533 "Make command be undefined in Info."
3538 "Enter the Info tutorial."
3540 (delete-other-windows)
3541 (Info-find-node "info"
3542 (if (< (window-height) 23)
3546 (defun Info-summary ()
3547 "Display a brief summary of all Info commands."
3549 (save-window-excursion
3550 (switch-to-buffer "*Help*")
3551 (setq buffer-read-only nil
)
3553 (insert (documentation 'Info-mode
))
3555 (goto-char (point-min))
3557 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3558 (message (if flag
"Type Space to see more"
3559 "Type Space to return to Info"))
3560 (if (not (eq ?\s
(setq ch
(read-event))))
3561 (progn (setq unread-command-events
(list ch
)) nil
)
3564 (bury-buffer "*Help*")))
3566 (defun Info-get-token (pos start all
&optional errorstring
)
3567 "Return the token around POS.
3568 POS must be somewhere inside the token.
3569 START is a regular expression which will match the
3570 beginning of the tokens delimited string.
3571 ALL is a regular expression with a single
3572 parenthesized subpattern which is the token to be
3573 returned. E.g. '{\(.*\)}' would return any string
3574 enclosed in braces around POS.
3575 ERRORSTRING optional fourth argument, controls action on no match:
3578 a string: signal an error, using that string."
3579 (let ((case-fold-search t
))
3582 ;; First look for a match for START that goes across POS.
3583 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3584 (not (looking-at start
)))
3586 ;; If we did not find one, search back for START
3587 ;; (this finds only matches that end at or before POS).
3588 (or (looking-at start
)
3591 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3593 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3594 (not (setq found
(and (<= (match-beginning 0) pos
)
3595 (> (match-end 0) pos
))))))
3596 (if (and found
(<= (match-beginning 0) pos
)
3597 (> (match-end 0) pos
))
3598 (match-string-no-properties 1)
3599 (cond ((null errorstring
)
3605 (error "No %s around position %d" errorstring pos
))))))))
3607 (defun Info-mouse-follow-nearest-node (click)
3608 "\\<Info-mode-map>Follow a node reference near point.
3609 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3610 At end of the node's text, moves to the next node, or up if none."
3612 (mouse-set-point click
)
3613 (and (not (Info-follow-nearest-node))
3614 (save-excursion (forward-line 1) (eobp))
3615 (Info-next-preorder)))
3617 (defun Info-follow-nearest-node (&optional fork
)
3618 "Follow a node reference near point.
3619 If point is on a reference, follow that reference. Otherwise,
3620 if point is in a menu item description, follow that menu item.
3622 If FORK is non-nil (interactively with a prefix arg), show the node in
3624 If FORK is a string, it is the name to use for the new buffer."
3626 (or (Info-try-follow-nearest-node fork
)
3627 (when (save-excursion
3628 (search-backward "\n* menu:" nil t
))
3631 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3632 (beginning-of-line 0))
3633 (when (looking-at "\\* +\\([^\t\n]*\\):")
3635 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3637 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3638 ;; Don't raise an error when mouse-1 is bound to this - it's
3639 ;; often used to simply select the window or frame.
3640 (eq 'mouse-1
(event-basic-type last-input-event
)))
3641 (error "Point neither on reference nor in menu item description")))
3643 ;; Common subroutine.
3644 (defun Info-try-follow-nearest-node (&optional fork
)
3645 "Follow a node reference near point. Return non-nil if successful.
3646 If FORK is non-nil, it is passed to `Info-goto-node'."
3649 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3650 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3653 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3654 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3655 (Info-follow-reference node fork
))
3656 ;; menu item: node name
3657 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3658 (Info-goto-node node fork
))
3659 ;; menu item: node name or index entry
3660 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3663 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3664 (Info-goto-node node fork
))
3665 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3666 (Info-goto-node node fork
))
3667 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3668 (Info-goto-node node fork
))
3669 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3670 (Info-goto-node "Top" fork
))
3671 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3672 (Info-goto-node node fork
)))
3675 (defun Info-mouse-follow-link (click)
3676 "Follow a link where you click."
3678 (let* ((position (event-start click
))
3679 (posn-string (and position
(posn-string position
)))
3680 (string (car-safe posn-string
))
3681 (string-pos (cdr-safe posn-string
))
3682 (link-args (and string string-pos
3683 (get-text-property string-pos
'link-args string
))))
3685 (Info-goto-node link-args
))))
3688 (defvar Info-mode-map
3689 (let ((map (make-keymap)))
3690 (suppress-keymap map
)
3691 (define-key map
"." 'beginning-of-buffer
)
3692 (define-key map
" " 'Info-scroll-up
)
3693 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3694 (define-key map
"\t" 'Info-next-reference
)
3695 (define-key map
"\e\t" 'Info-prev-reference
)
3696 (define-key map
[backtab] 'Info-prev-reference)
3697 (define-key map "1" 'Info-nth-menu-item)
3698 (define-key map "2" 'Info-nth-menu-item)
3699 (define-key map "3" 'Info-nth-menu-item)
3700 (define-key map "4" 'Info-nth-menu-item)
3701 (define-key map "5" 'Info-nth-menu-item)
3702 (define-key map "6" 'Info-nth-menu-item)
3703 (define-key map "7" 'Info-nth-menu-item)
3704 (define-key map "8" 'Info-nth-menu-item)
3705 (define-key map "9" 'Info-nth-menu-item)
3706 (define-key map "0" 'undefined)
3707 (define-key map "?" 'Info-summary)
3708 (define-key map "]" 'Info-forward-node)
3709 (define-key map "[" 'Info-backward-node)
3710 (define-key map "<" 'Info-top-node)
3711 (define-key map ">" 'Info-final-node)
3712 (define-key map "b" 'beginning-of-buffer)
3713 (put 'beginning-of-buffer :advertised-binding "b")
3714 (define-key map "d" 'Info-directory)
3715 (define-key map "e" 'end-of-buffer)
3716 (define-key map "f" 'Info-follow-reference)
3717 (define-key map "g" 'Info-goto-node)
3718 (define-key map "h" 'Info-help)
3719 (define-key map "i" 'Info-index)
3720 (define-key map "I" 'Info-virtual-index)
3721 (define-key map "l" 'Info-history-back)
3722 (define-key map "L" 'Info-history)
3723 (define-key map "m" 'Info-menu)
3724 (define-key map "n" 'Info-next)
3725 (define-key map "p" 'Info-prev)
3726 (define-key map "q" 'Info-exit)
3727 (define-key map "r" 'Info-history-forward)
3728 (define-key map "s" 'Info-search)
3729 (define-key map "S" 'Info-search-case-sensitively)
3730 (define-key map "\M-n" 'clone-buffer)
3731 (define-key map "t" 'Info-top-node)
3732 (define-key map "T" 'Info-toc)
3733 (define-key map "u" 'Info-up)
3734 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3735 (define-key map "w" 'Info-copy-current-node-name)
3736 (define-key map "c" 'Info-copy-current-node-name)
3737 ;; `^' for consistency with `dired-up-directory'.
3738 (define-key map "^" 'Info-up)
3739 (define-key map "," 'Info-index-next)
3740 (define-key map "\177" 'Info-scroll-down)
3741 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3742 (define-key map [follow-link] 'mouse-face)
3744 "Keymap containing Info commands.")
3747 (defun Info-check-pointer (item)
3748 "Non-nil if ITEM is present in this node."
3750 (Info-extract-pointer item)
3754 Info-mode-menu Info-mode-map
3755 "Menu for Info files."
3757 ["Up" Info-up :active (Info-check-pointer "up")
3758 :help "Go up in the Info tree"]
3759 ["Next" Info-next :active (Info-check-pointer "next")
3760 :help "Go to the next node"]
3761 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3762 :help "Go to the previous node"]
3763 ["Backward" Info-backward-node
3764 :help "Go backward one node, considering all as a sequence"]
3765 ["Forward" Info-forward-node
3766 :help "Go forward one node, considering all as a sequence"]
3767 ["Beginning" beginning-of-buffer
3768 :help "Go to beginning of this node"]
3769 ["Top" Info-top-node
3770 :help "Go to top node of file"]
3771 ["Final Node" Info-final-node
3772 :help "Go to final node in this file"]
3773 ("Menu Item" ["You should never see this" report-emacs-bug t])
3774 ("Reference" ["You should never see this" report-emacs-bug t])
3775 ["Search..." Info-search
3776 :help "Search for regular expression in this Info file"]
3777 ["Search Next" Info-search-next
3778 :help "Search for another occurrence of regular expression"]
3779 ["Go to Node..." Info-goto-node
3780 :help "Go to a named node"]
3781 ["Back in history" Info-history-back :active Info-history
3782 :help "Go back in history to the last node you were at"]
3783 ["Forward in history" Info-history-forward :active Info-history-forward
3784 :help "Go forward in history"]
3785 ["History" Info-history :active Info-history-list
3786 :help "Go to menu of visited nodes"]
3787 ["Table of Contents" Info-toc
3788 :help "Go to table of contents"]
3790 ["Lookup a String..." Info-index
3791 :help "Look for a string in the index items"]
3792 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3793 :help "Look for another occurrence of previous item"]
3794 ["Lookup a string and display index of results..." Info-virtual-index
3795 :help "Look for a string in the index items and display node with results"]
3796 ["Lookup a string in all indices..." info-apropos
3797 :help "Look for a string in the indices of all manuals"])
3798 ["Copy Node Name" Info-copy-current-node-name
3799 :help "Copy the name of the current node into the kill ring"]
3800 ["Clone Info buffer" clone-buffer
3801 :help "Create a twin copy of the current Info buffer."]
3802 ["Exit" Info-exit :help "Stop reading Info"]))
3805 (defvar info-tool-bar-map
3806 (let ((map (make-sparse-keymap)))
3807 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3811 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3815 (define-key-after map [separator-1] menu-bar-separator)
3816 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3818 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3820 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
3822 (define-key-after map [separator-2] menu-bar-separator)
3823 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
3825 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3826 (define-key-after map [separator-3] menu-bar-separator)
3827 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3829 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
3831 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
3835 (defvar Info-menu-last-node nil)
3836 ;; Last node the menu was created for.
3837 ;; Value is a list, (FILE-NAME NODE-NAME).
3839 (defun Info-menu-update ()
3840 "Update the Info menu for the current node."
3842 (if (or (not (eq major-mode 'Info-mode))
3843 (equal (list Info-current-file Info-current-node)
3844 Info-menu-last-node))
3846 ;; Update menu menu.
3847 (let* ((Info-complete-menu-buffer (current-buffer))
3848 (items (nreverse (condition-case nil
3849 (Info-complete-menu-item "" nil t)
3853 (while (and items (< number 9))
3854 (setq current (car items)
3857 (setq entries (cons `[,current
3858 (Info-menu ,current)
3859 :keys ,(format "%d" number)]
3862 (setq entries (cons ["Other..." Info-menu t] entries)))
3864 (setq entries (list ["No menu" nil nil] nil :active)))
3865 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3866 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3868 str i entries current
3870 (case-fold-search t))
3872 (goto-char (point-min))
3873 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3874 (setq str (match-string 1))
3876 (while (setq i (string-match "[ \n\t]+" str i))
3877 (setq str (concat (substring str 0 i) " "
3878 (substring str (match-end 0))))
3882 (while (and items (< number 9))
3883 (setq current (car items)
3886 (setq entries (cons `[,current
3887 (Info-follow-reference ,current)
3891 (setq entries (cons ["Other..." Info-follow-reference t]
3894 (setq entries (list ["No references" nil nil] nil :active)))
3895 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3896 ;; Update last seen node.
3897 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3898 ;; Try to avoid entering infinite beep mode in case of errors.
3902 (defun Info-copy-current-node-name (&optional arg)
3903 "Put the name of the current Info node into the kill ring.
3904 The name of the Info file is prepended to the node name in parentheses.
3905 With a zero prefix arg, put the name inside a function call to `info'."
3907 (unless Info-current-node
3908 (error "No current Info node"))
3909 (let ((node (if (stringp Info-current-file)
3910 (concat "(" (file-name-nondirectory Info-current-file) ") "
3911 Info-current-node))))
3912 (if (zerop (prefix-numeric-value arg))
3913 (setq node (concat "(info \"" node "\")")))
3914 (unless (stringp Info-current-file)
3915 (setq node (format "(Info-find-node '%S '%S)"
3916 Info-current-file Info-current-node)))
3918 (message "%s" node)))
3921 ;; Info mode is suitable only for specially formatted data.
3922 (put 'Info-mode 'mode-class 'special)
3923 (put 'Info-mode 'no-clone-indirect t)
3925 (defvar tool-bar-map)
3926 (defvar bookmark-make-record-function)
3928 (defvar Info-mode-syntax-table
3929 (let ((st (copy-syntax-table text-mode-syntax-table)))
3930 ;; Use punctuation syntax for apostrophe because of
3931 ;; extensive use of quotes like `this' in Info manuals.
3932 (modify-syntax-entry ?' "." st)
3934 "Syntax table used in `Info-mode'.")
3936 ;; Autoload cookie needed by desktop.el
3938 (define-derived-mode Info-mode nil "Info"
3939 "Info mode provides commands for browsing through the Info documentation tree.
3940 Documentation in Info is divided into \"nodes\", each of which discusses
3941 one topic and contains references to other nodes which discuss related
3942 topics. Info has commands to follow the references and show you other nodes.
3945 \\[Info-help] Invoke the Info tutorial.
3946 \\[Info-exit] Quit Info: reselect previously selected buffer.
3948 Selecting other nodes:
3949 \\[Info-mouse-follow-nearest-node]
3950 Follow a node reference you click on.
3951 This works with menu items, cross references, and
3952 the \"next\", \"previous\" and \"up\", depending on where you click.
3953 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3954 \\[Info-next] Move to the \"next\" node of this node.
3955 \\[Info-prev] Move to the \"previous\" node of this node.
3956 \\[Info-up] Move \"up\" from this node.
3957 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3958 Picking a menu item causes another node to be selected.
3959 \\[Info-directory] Go to the Info directory node.
3960 \\[Info-top-node] Go to the Top node of this file.
3961 \\[Info-final-node] Go to the final node in this file.
3962 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3963 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3964 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3965 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3966 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3967 \\[Info-history-back] Move back in history to the last node you were at.
3968 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3969 \\[Info-history] Go to menu of visited nodes.
3970 \\[Info-toc] Go to table of contents of the current Info file.
3972 Moving within a node:
3973 \\[Info-scroll-up] Normally, scroll forward a full screen.
3974 Once you scroll far enough in a node that its menu appears on the
3975 screen but after point, the next scroll moves into its first
3976 subnode. When after all menu items (or if there is no menu),
3977 move up to the parent node.
3978 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3979 already visible, try to go to the previous menu entry, or up
3981 \\[beginning-of-buffer] Go to beginning of node.
3984 \\[Info-search] Search through this Info file for specified regexp,
3985 and select the node in which the next occurrence is found.
3986 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3987 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3988 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3989 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3990 \\[Info-virtual-index] Look for a string and display the index node with results.
3991 \\[info-apropos] Look for a string in the indices of all manuals.
3992 \\[Info-goto-node] Move to node specified by name.
3993 You may include a filename as well, as (FILENAME)NODENAME.
3994 1 .. 9 Pick first ... ninth item in node's menu.
3995 Every third `*' is highlighted to help pick the right number.
3996 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3997 \\[clone-buffer] Select a new cloned Info buffer in another window.
3998 \\[universal-argument] \\[info] Move to new Info file with completion.
3999 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4000 :syntax-table Info-mode-syntax-table
4001 :abbrev-table text-mode-abbrev-table
4003 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4004 (setq case-fold-search t)
4005 (setq buffer-read-only t)
4006 (make-local-variable 'Info-current-file)
4007 (make-local-variable 'Info-current-subfile)
4008 (make-local-variable 'Info-current-node)
4009 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
4010 (set (make-local-variable 'Info-tag-table-buffer) nil)
4011 (make-local-variable 'Info-history)
4012 (make-local-variable 'Info-history-forward)
4013 (make-local-variable 'Info-index-alternatives)
4014 (if Info-use-header-line ; do not override global header lines
4015 (setq header-line-format
4016 '(:eval (get-text-property (point-min) 'header-line))))
4017 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4018 ;; This is for the sake of the invisible text we use handling titles.
4019 (set (make-local-variable 'line-move-ignore-invisible) t)
4020 (set (make-local-variable 'desktop-save-buffer)
4021 'Info-desktop-buffer-misc-data)
4022 (set (make-local-variable 'widen-automatically) nil)
4023 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4024 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4025 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4026 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4027 (set (make-local-variable 'isearch-search-fun-function)
4028 'Info-isearch-search)
4029 (set (make-local-variable 'isearch-wrap-function)
4031 (set (make-local-variable 'isearch-push-state-function)
4032 'Info-isearch-push-state)
4033 (set (make-local-variable 'isearch-filter-predicate)
4034 'Info-isearch-filter)
4035 (set (make-local-variable 'search-whitespace-regexp)
4036 Info-search-whitespace-regexp)
4037 (set (make-local-variable 'revert-buffer-function)
4038 'Info-revert-buffer-function)
4039 (Info-set-mode-line)
4040 (set (make-local-variable 'bookmark-make-record-function)
4041 'Info-bookmark-make-record))
4043 ;; When an Info buffer is killed, make sure the associated tags buffer
4045 (defun Info-kill-buffer ()
4046 (and (eq major-mode 'Info-mode)
4047 Info-tag-table-buffer
4048 (kill-buffer Info-tag-table-buffer)))
4050 ;; Placed on `clone-buffer-hook'.
4051 (defun Info-clone-buffer ()
4052 (when (bufferp Info-tag-table-buffer)
4053 (setq Info-tag-table-buffer
4054 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4055 (let ((m Info-tag-table-marker))
4057 (setq Info-tag-table-marker
4058 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4059 (with-current-buffer Info-tag-table-buffer
4060 (copy-marker (marker-position m)))
4063 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4064 (set-keymap-parent map text-mode-map)
4065 (define-key map "\C-c\C-c" 'Info-cease-edit)
4067 "Local keymap used within `e' command of Info.")
4069 ;; Info-edit mode is suitable only for specially formatted data.
4070 (put 'Info-edit-mode 'mode-class 'special)
4072 (defun Info-edit-mode ()
4073 "Major mode for editing the contents of an Info node.
4074 Like text mode with the addition of `Info-cease-edit'
4075 which returns to Info mode for browsing.
4077 (use-local-map Info-edit-map)
4078 (setq major-mode 'Info-edit-mode)
4079 (setq mode-name "Info Edit")
4080 (kill-local-variable 'mode-line-buffer-identification)
4081 (setq buffer-read-only nil)
4082 (force-mode-line-update)
4083 (buffer-enable-undo (current-buffer))
4084 (run-mode-hooks 'Info-edit-mode-hook))
4087 "Edit the contents of this Info node.
4088 Allowed only if variable `Info-enable-edit' is non-nil."
4090 (or Info-enable-edit
4091 (error "Editing Info nodes is not enabled"))
4093 (message "%s" (substitute-command-keys
4094 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4096 (defun Info-cease-edit ()
4097 "Finish editing Info node; switch back to Info proper."
4099 ;; Do this first, so nothing has changed if user C-g's at query.
4100 (and (buffer-modified-p)
4101 (y-or-n-p "Save the file? ")
4103 (use-local-map Info-mode-map)
4104 (setq major-mode 'Info-mode)
4105 (setq mode-name "Info")
4106 (Info-set-mode-line)
4107 (setq buffer-read-only t)
4108 (force-mode-line-update)
4109 (and (marker-position Info-tag-table-marker)
4111 (message "Tags may have changed. Use Info-tagify if necessary")))
4113 (defvar Info-file-list-for-emacs
4114 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4115 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4116 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4117 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4118 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4119 ("copyright" . "autotype") ("executable" . "autotype")
4120 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4121 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4122 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4123 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4124 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4125 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4126 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4127 ("rfc2045" . "emacs-mime")
4128 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4129 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4130 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4131 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4132 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4133 ("mml" . "emacs-mime"))
4134 "List of Info files that describe Emacs commands.
4135 An element can be a file name, or a list of the form (PREFIX . FILE)
4136 where PREFIX is a name prefix and FILE is the file to look in.
4137 If the element is just a file name, the file name also serves as the prefix.")
4139 (defun Info-find-emacs-command-nodes (command)
4140 "Return a list of locations documenting COMMAND.
4141 The `info-file' property of COMMAND says which Info manual to search.
4142 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4143 defines heuristics for which Info manual to try.
4144 The locations are of the format used in `Info-history', i.e.
4145 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4146 in the first element of the returned list (which is treated specially in
4147 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4148 (let ((where '()) line-number
4149 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4150 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4151 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4152 (info-file "emacs")) ;default
4153 ;; Determine which Info file this command is documented in.
4154 (if (get command 'info-file)
4155 (setq info-file (get command 'info-file))
4156 ;; If it doesn't say explicitly, test its name against
4157 ;; various prefixes that we know.
4158 (let ((file-list Info-file-list-for-emacs))
4160 (let* ((elt (car file-list))
4161 (name (if (consp elt)
4164 (file (if (consp elt) (cdr elt) elt))
4165 (case-fold-search nil)
4166 (regexp (concat "\\`" (regexp-quote name)
4168 (if (string-match regexp (symbol-name command))
4169 (setq info-file file file-list nil))
4170 (setq file-list (cdr file-list))))))
4171 (Info-find-node info-file "Top")
4172 ;; Bind Info-history to nil, to prevent the index nodes from
4173 ;; getting into the node history.
4174 (let ((Info-history nil)
4175 (Info-history-list nil)
4176 node (nodes (Info-index-nodes)))
4177 (Info-goto-node (car nodes))
4180 (goto-char (point-min))
4181 (while (re-search-forward cmd-desc nil t)
4183 (cons (list Info-current-file
4184 (match-string-no-properties 2)
4187 (setq line-number (and (match-beginning 3)
4188 (string-to-number (match-string 3)))))
4189 (and (setq nodes (cdr nodes) node (car nodes))))
4190 (Info-goto-node node)))
4191 (if (and line-number where)
4192 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4196 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4198 (defun Info-goto-emacs-command-node (command)
4199 "Go to the Info node in the Emacs manual for command COMMAND.
4200 The command is found by looking up in Emacs manual's indices
4201 or in another manual found via COMMAND's `info-file' property or
4202 the variable `Info-file-list-for-emacs'.
4203 COMMAND must be a symbol or string."
4204 (interactive "CFind documentation for command: ")
4205 ;; If command is given as a string, convert it to a symbol.
4206 (if (stringp command)
4207 (setq command (intern command)))
4208 (or (commandp command)
4209 (signal 'wrong-type-argument (list 'commandp command)))
4210 (let ((where (Info-find-emacs-command-nodes command)))
4212 (let ((num-matches (length where)))
4213 ;; Get Info running, and pop to it in another window.
4214 (save-window-excursion
4216 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4217 ;; Bind Info-history to nil, to prevent the last Index node
4218 ;; visited by Info-find-emacs-command-nodes from being
4219 ;; pushed onto the history.
4220 (let ((Info-history nil) (Info-history-list nil)
4221 (line-number (nth 2 (car where))))
4222 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4223 (if (and (integerp line-number) (> line-number 0))
4224 (forward-line (1- line-number))))
4225 (if (> num-matches 1)
4227 ;; (car where) will be pushed onto Info-history
4228 ;; when/if they go to another node. Put the other
4229 ;; nodes that were found on the history.
4230 (setq Info-history (nconc (cdr where) Info-history))
4231 (message "Found %d other entr%s. Use %s to see %s."
4233 (if (> num-matches 2) "ies" "y")
4234 (substitute-command-keys "\\[Info-history-back]")
4235 (if (> num-matches 2) "them" "it")))))
4236 (error "Couldn't find documentation for %s" command))))
4238 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4240 (defun Info-goto-emacs-key-command-node (key)
4241 "Go to the node in the Emacs manual which describes the command bound to KEY.
4243 Interactively, if the binding is `execute-extended-command', a command is read.
4244 The command is found by looking up in Emacs manual's indices
4245 or in another manual found via COMMAND's `info-file' property or
4246 the variable `Info-file-list-for-emacs'."
4247 (interactive "kFind documentation for key: ")
4248 (let ((command (key-binding key)))
4249 (cond ((null command)
4250 (message "%s is undefined" (key-description key)))
4251 ((and (called-interactively-p 'interactive)
4252 (eq command 'execute-extended-command))
4253 (Info-goto-emacs-command-node
4254 (read-command "Find documentation for command: ")))
4256 (Info-goto-emacs-command-node command)))))
4258 (defvar Info-next-link-keymap
4259 (let ((keymap (make-sparse-keymap)))
4260 (define-key keymap [header-line mouse-1] 'Info-next)
4261 (define-key keymap [header-line mouse-2] 'Info-next)
4262 (define-key keymap [header-line down-mouse-1] 'ignore)
4263 (define-key keymap [mouse-2] 'Info-next)
4264 (define-key keymap [follow-link] 'mouse-face)
4266 "Keymap to put on the Next link in the text or the header line.")
4268 (defvar Info-prev-link-keymap
4269 (let ((keymap (make-sparse-keymap)))
4270 (define-key keymap [header-line mouse-1] 'Info-prev)
4271 (define-key keymap [header-line mouse-2] 'Info-prev)
4272 (define-key keymap [header-line down-mouse-1] 'ignore)
4273 (define-key keymap [mouse-2] 'Info-prev)
4274 (define-key keymap [follow-link] 'mouse-face)
4276 "Keymap to put on the Prev link in the text or the header line.")
4278 (defvar Info-up-link-keymap
4279 (let ((keymap (make-sparse-keymap)))
4280 (define-key keymap [header-line mouse-1] 'Info-up)
4281 (define-key keymap [header-line mouse-2] 'Info-up)
4282 (define-key keymap [header-line down-mouse-1] 'ignore)
4283 (define-key keymap [mouse-2] 'Info-up)
4284 (define-key keymap [follow-link] 'mouse-face)
4286 "Keymap to put on the Up link in the text or the header line.")
4288 (defvar Info-link-keymap
4289 (let ((keymap (make-sparse-keymap)))
4290 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4291 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4292 (define-key keymap [header-line down-mouse-1] 'ignore)
4293 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4294 (define-key keymap [follow-link] 'mouse-face)
4296 "Keymap to put on the link in the text or the header line.")
4298 (defun Info-breadcrumbs ()
4299 (let ((nodes (Info-toc-nodes Info-current-file))
4300 (node Info-current-node)
4302 (depth Info-breadcrumbs-depth)
4305 ;; Get ancestors from the cached parent-children node info
4306 (while (and (not (equal "Top" node)) (> depth 0))
4307 (setq node (nth 1 (assoc node nodes)))
4308 (if node (push node crumbs))
4309 (setq depth (1- depth)))
4312 (when Info-use-header-line
4313 ;; Let it disappear if crumbs is nil.
4314 (nconc crumbs (list Info-current-node)))
4315 (when (or Info-use-header-line crumbs)
4316 ;; Add top node (and continuation if needed).
4318 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4319 crumbs (cons nil crumbs))))
4320 ;; Eliminate duplicate.
4322 (dolist (node crumbs)
4324 (if (not (equal node "Top")) node
4326 (if (stringp Info-current-file)
4327 (file-name-nondirectory Info-current-file)
4328 ;; Some legacy code can still use a symbol.
4329 Info-current-file)))))
4332 (if (null line) "" " > ")
4335 ((equal node Info-current-node)
4336 ;; No point linking to ourselves.
4337 (propertize text 'font-lock-face 'info-header-node))
4340 'mouse-face 'highlight
4341 'font-lock-face 'info-header-xref
4342 'help-echo "mouse-2: Go to node"
4343 'keymap Info-link-keymap
4344 'link-args text)))))))
4345 (setq line (concat line "\n")))
4346 ;; (font-lock-append-text-property 0 (length line)
4347 ;; 'font-lock-face 'header-line line)
4350 (defun Info-fontify-node ()
4353 (let* ((inhibit-read-only t)
4354 (case-fold-search t)
4356 (not-fontified-p ; the node hasn't already been fontified
4357 (not (let ((where (next-single-property-change (point-min)
4359 (and where (not (= where (point-max)))))))
4360 (fontify-visited-p ; visited nodes need to be re-fontified
4361 (and Info-fontify-visited-nodes
4362 ;; Don't take time to refontify visited nodes in huge nodes
4363 Info-fontify-maximum-menu-size
4364 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4367 ;; Fontify header line
4368 (goto-char (point-min))
4369 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4370 (goto-char (match-end 0))
4371 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4372 (goto-char (match-end 0))
4373 (let* ((nbeg (match-beginning 2))
4374 (nend (match-end 2))
4375 (tbeg (match-beginning 1))
4376 (tag (match-string 1)))
4377 (if (string-equal (downcase tag) "node")
4378 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4379 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4380 (put-text-property tbeg nend 'mouse-face 'highlight)
4381 (put-text-property tbeg nend
4383 (concat "mouse-2: Go to node "
4384 (buffer-substring nbeg nend)))
4385 ;; Always set up the text property keymap.
4386 ;; It will either be used in the buffer
4387 ;; or copied in the header line.
4391 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4392 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4393 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4395 ;; (when (> Info-breadcrumbs-depth 0)
4396 ;; (insert (Info-breadcrumbs)))
4398 ;; Treat header line.
4399 (when Info-use-header-line
4400 (goto-char (point-min))
4401 (let* ((header-end (line-end-position))
4403 ;; If we find neither Next: nor Prev: link, show the entire
4404 ;; node header. Otherwise, don't show the File: and Node:
4405 ;; parts, to avoid wasting precious space on information that
4406 ;; is available in the mode line.
4407 (if (re-search-forward
4408 "\\(next\\|up\\|prev[ious]*\\): "
4411 (goto-char (match-beginning 1))
4412 (buffer-substring (point) header-end))
4413 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4415 (concat "No next, prev or up links -- "
4416 (buffer-substring (point) header-end))
4417 (buffer-substring (point) header-end)))))
4418 (put-text-property (point-min) (1+ (point-min))
4420 (replace-regexp-in-string
4422 ;; Preserve text properties on duplicated `%'.
4423 (lambda (s) (concat s s)) header))
4424 ;; Hide the part of the first line
4425 ;; that is in the header, if it is just part.
4427 ((> Info-breadcrumbs-depth 0)
4428 (let ((ov (make-overlay (point-min) (1+ header-end))))
4429 (overlay-put ov 'display (Info-breadcrumbs))
4430 (overlay-put ov 'evaporate t)))
4432 ;; Hide the punctuation at the end, too.
4433 (skip-chars-backward " \t,")
4434 (put-text-property (point) header-end 'invisible t))))))
4437 (goto-char (point-min))
4438 (when (and font-lock-mode not-fontified-p)
4439 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4441 ;; Only consider it as an underlined title if the ASCII
4442 ;; underline has the same size as the text. A typical
4443 ;; counter example is when a continuation "..." is alone
4445 (= (string-width (match-string 1))
4446 (string-width (match-string 2))))
4447 (let* ((c (preceding-char))
4449 (cond ((= c ?*) 'info-title-1)
4450 ((= c ?=) 'info-title-2)
4451 ((= c ?-) 'info-title-3)
4452 (t 'info-title-4))))
4453 (put-text-property (match-beginning 1) (match-end 1)
4454 'font-lock-face face))
4455 ;; This is a serious problem for trying to handle multiple
4456 ;; frame types at once. We want this text to be invisible
4457 ;; on frames that can display the font above.
4458 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4459 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4460 '(invisible t front-sticky nil rear-nonsticky t)))))
4462 ;; Fontify cross references
4463 (goto-char (point-min))
4464 (when (or not-fontified-p fontify-visited-p)
4465 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4466 (let ((start (match-beginning 0))
4469 (when not-fontified-p
4470 (when Info-hide-note-references
4471 (when (and (not (eq Info-hide-note-references 'hide))
4472 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4473 ;; *Note is often used where *note should have been
4475 (skip-syntax-backward " ")
4476 (when (memq (char-before) '(?\( ?\[ ?\{))
4477 ;; Check whether the paren is preceded by
4478 ;; an end of sentence
4479 (skip-syntax-backward " ("))
4481 (cond ((save-match-data (looking-back "\\<see"))
4483 ((save-match-data (looking-back "\\<in"))
4485 ((memq (char-before) '(nil ?\. ?! ??))
4489 (search-forward "\n\n" start t)))
4493 (add-text-properties
4495 (or (save-match-data
4496 ;; Don't hide \n after *Note
4497 (let ((start1 (match-beginning 1)))
4498 (if (string-match "\n" (match-string 1))
4499 (+ start1 (match-beginning 0)))))
4502 `(display ,other-tag front-sticky nil rear-nonsticky t)
4503 '(invisible t front-sticky nil rear-nonsticky t))))
4504 (add-text-properties
4505 (match-beginning 2) (match-end 2)
4507 'help-echo (if (or (match-end 5)
4508 (not (equal (match-string 4) "")))
4509 (concat "mouse-2: go to " (or (match-string 5)
4511 "mouse-2: go to this node")
4512 'mouse-face 'highlight)))
4513 (when (or not-fontified-p fontify-visited-p)
4514 (setq rbeg (match-beginning 2)
4519 ;; Display visited nodes in a different face
4520 (if (and Info-fontify-visited-nodes
4522 (let* ((node (replace-regexp-in-string
4524 (replace-regexp-in-string
4526 (or (match-string-no-properties 5)
4527 (and (not (equal (match-string 4) ""))
4528 (match-string-no-properties 4))
4529 (match-string-no-properties 2)))))
4531 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4532 (file (if external-link-p
4533 (file-name-nondirectory
4534 (match-string-no-properties 1 node))
4536 (hl Info-history-list)
4539 (setq node (if (equal (match-string 2 node) "")
4541 (match-string-no-properties 2 node))))
4543 (if (and (string-equal node (nth 1 (car hl)))
4545 (if (and external-link-p
4546 (stringp (caar hl)))
4547 (file-name-nondirectory
4550 (setq res (car hl) hl nil)
4551 (setq hl (cdr hl))))
4552 res))) 'info-xref-visited 'info-xref))
4553 ;; For multiline ref, unfontify newline and surrounding whitespace
4557 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4558 (remove-text-properties (match-beginning 0)
4560 '(font-lock-face t))))))
4561 (when not-fontified-p
4562 (when (memq Info-hide-note-references '(t hide))
4563 (add-text-properties (match-beginning 3) (match-end 3)
4564 '(invisible t front-sticky nil rear-nonsticky t))
4565 ;; Unhide the file name of the external reference in parens
4566 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4567 (remove-text-properties (match-beginning 6) (match-end 6)
4568 '(invisible t front-sticky nil rear-nonsticky t)))
4569 ;; Unhide newline because hidden newlines cause too long lines
4571 (let ((beg3 (match-beginning 3))
4572 (end3 (match-end 3)))
4573 (if (and (string-match "\n[ \t]*" (match-string 3))
4574 (not (save-match-data
4576 (goto-char (1+ end3))
4577 (looking-at "[.)]*$")))))
4578 (remove-text-properties (+ beg3 (match-beginning 0))
4579 (+ beg3 (match-end 0))
4580 '(invisible t front-sticky nil rear-nonsticky t))))))
4581 (when (and Info-refill-paragraphs Info-hide-note-references)
4582 (push (set-marker (make-marker) start)
4583 paragraph-markers))))))
4585 ;; Refill paragraphs (experimental feature)
4586 (when (and not-fontified-p
4587 Info-refill-paragraphs
4589 (let ((fill-nobreak-invisible t)
4590 (fill-individual-varying-indent nil)
4591 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4592 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4593 (adaptive-fill-mode nil))
4594 (goto-char (point-max))
4595 (dolist (m paragraph-markers)
4599 (let ((beg (point)))
4600 (when (zerop (forward-paragraph))
4601 (fill-individual-paragraphs beg (point) nil nil)
4603 (set-marker m nil))))
4605 ;; Fontify menu items
4606 (goto-char (point-min))
4607 (when (and (or not-fontified-p fontify-visited-p)
4608 (search-forward "\n* Menu:" nil t)
4609 ;; Don't take time to annotate huge menus
4610 Info-fontify-maximum-menu-size
4611 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4614 (while (re-search-forward
4615 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4616 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4618 (when (match-beginning 1)
4619 (when not-fontified-p
4621 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4622 (put-text-property (match-beginning 0)
4623 (1+ (match-beginning 0))
4624 'font-lock-face 'info-menu-star)))
4625 (when not-fontified-p
4626 (add-text-properties
4627 (match-beginning 1) (match-end 1)
4629 'help-echo (if (and (match-end 3)
4630 (not (equal (match-string 3) "")))
4631 (concat "mouse-2: go to " (match-string 3))
4632 "mouse-2: go to this node")
4633 'mouse-face 'highlight)))
4634 (when (or not-fontified-p fontify-visited-p)
4636 (match-beginning 1) (match-end 1)
4638 ;; Display visited menu items in a different face
4639 (if (and Info-fontify-visited-nodes
4641 (let* ((node (if (equal (match-string 3) "")
4642 (match-string-no-properties 1)
4643 (match-string-no-properties 3)))
4645 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4646 (file (if external-link-p
4647 (file-name-nondirectory
4648 (match-string-no-properties 1 node))
4650 (hl Info-history-list)
4653 (setq node (if (equal (match-string 2 node) "")
4655 (match-string-no-properties 2 node))))
4657 (if (and (string-equal node (nth 1 (car hl)))
4659 (if (and external-link-p
4660 (stringp (caar hl)))
4661 (file-name-nondirectory
4664 (setq res (car hl) hl nil)
4665 (setq hl (cdr hl))))
4666 res))) 'info-xref-visited 'info-xref)))
4667 (when (and not-fontified-p
4668 (memq Info-hide-note-references '(t hide))
4669 (not (Info-index-node)))
4670 (put-text-property (match-beginning 2) (1- (match-end 6))
4672 ;; Unhide the file name in parens
4673 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4674 (remove-text-properties (match-beginning 4) (match-end 4)
4676 ;; We need a stretchable space like :align-to but with
4678 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4679 (if (>= 22 (- (match-end 1)
4680 (match-beginning 0)))
4681 '(space :align-to 24)
4683 (setq cont (looking-at "."))
4684 (while (and (= (forward-line 1) 0)
4685 (looking-at "\\([ \t]+\\)[^*\n]"))
4686 (put-text-property (match-beginning 1) (1- (match-end 1))
4688 (put-text-property (1- (match-end 1)) (match-end 1)
4691 '(space :align-to 26)
4692 '(space :align-to 24)))
4695 ;; Fontify menu headers
4696 ;; Add the face `info-menu-header' to any header before a menu entry
4697 (goto-char (point-min))
4698 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4699 (put-text-property (match-beginning 0) (match-end 0)
4700 'font-lock-face 'info-menu-header)
4701 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4702 (put-text-property (match-beginning 1) (match-end 1)
4703 'font-lock-face 'info-menu-header)))
4705 ;; Hide index line numbers
4706 (goto-char (point-min))
4707 (when (and not-fontified-p (Info-index-node))
4708 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4709 (put-text-property (match-beginning 0) (match-end 0)
4712 ;; Fontify http and ftp references
4713 (goto-char (point-min))
4714 (when not-fontified-p
4715 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4717 (add-text-properties (match-beginning 0) (match-end 0)
4718 '(font-lock-face info-xref
4719 mouse-face highlight
4720 help-echo "mouse-2: go to this URL"))))
4722 (set-buffer-modified-p nil))))
4724 ;;; Speedbar support:
4725 ;; These functions permit speedbar to display the "tags" in the
4726 ;; current Info node.
4727 (eval-when-compile (require 'speedbar))
4729 (defvar Info-speedbar-key-map nil
4730 "Keymap used when in the Info display mode.")
4732 (defun Info-install-speedbar-variables ()
4733 "Install those variables used by speedbar to enhance Info."
4734 (if Info-speedbar-key-map
4736 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4738 ;; Basic tree features
4739 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4740 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4741 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4742 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4745 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4746 Info-speedbar-key-map
4747 Info-speedbar-hierarchy-buttons)))
4749 (defvar Info-speedbar-menu-items
4750 '(["Browse Node" speedbar-edit-line t]
4751 ["Expand Node" speedbar-expand-line
4752 (save-excursion (beginning-of-line)
4753 (looking-at "[0-9]+: *.\\+. "))]
4754 ["Contract Node" speedbar-contract-line
4755 (save-excursion (beginning-of-line)
4756 (looking-at "[0-9]+: *.-. "))]
4758 "Additional menu-items to add to speedbar frame.")
4760 ;; Make sure our special speedbar major mode is loaded
4761 (if (featurep 'speedbar)
4762 (Info-install-speedbar-variables)
4763 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4765 ;;; Info hierarchy display method
4767 (defun Info-speedbar-browser ()
4768 "Initialize speedbar to display an Info node browser.
4769 This will add a speedbar major display mode."
4772 ;; Make sure that speedbar is active
4773 (speedbar-frame-mode 1)
4774 ;; Now, throw us into Info mode on speedbar.
4775 (speedbar-change-initial-expansion-list "Info")
4778 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
4779 "Display an Info directory hierarchy in speedbar.
4780 DIRECTORY is the current directory in the attached frame.
4781 DEPTH is the current indentation depth.
4782 NODE is an optional argument that is used to represent the
4783 specific node to expand."
4785 (save-excursion (goto-char (point-min))
4786 (let ((case-fold-search t))
4787 (looking-at "Info Nodes:"))))
4788 ;; Update our "current node" maybe?
4790 ;; We cannot use the generic list code, that depends on all leaves
4791 ;; being known at creation time.
4793 (speedbar-with-writable (insert "Info Nodes:\n")))
4794 (let ((completions nil))
4795 (speedbar-select-attached-frame)
4796 (save-window-excursion
4798 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4799 (select-frame (speedbar-current-frame))
4801 (speedbar-with-writable
4802 (dolist (completion completions)
4803 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4806 'Info-speedbar-goto-node
4812 (defun Info-speedbar-goto-node (_text node _indent)
4813 "When user clicks on TEXT, go to an info NODE.
4814 The INDENT level is ignored."
4815 (speedbar-select-attached-frame)
4816 (let* ((buff (or (get-buffer "*info*")
4817 (progn (info) (get-buffer "*info*"))))
4818 (bwin (get-buffer-window buff 0)))
4821 (select-window bwin)
4822 (raise-frame (window-frame bwin)))
4823 (if speedbar-power-click
4824 (switch-to-buffer-other-frame buff)
4825 (speedbar-select-attached-frame)
4826 (switch-to-buffer buff)))
4827 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4828 (error "Invalid node %s" node)
4829 (Info-find-node (match-string 1 node) (match-string 2 node))
4830 ;; If we do a find-node, and we were in info mode, restore
4831 ;; the old default method. Once we are in info mode, it makes
4832 ;; sense to return to whatever method the user was using before.
4833 (if (string= speedbar-initial-expansion-list-name "Info")
4834 (speedbar-change-initial-expansion-list
4835 speedbar-previously-used-expansion-list-name)))))
4837 (defun Info-speedbar-expand-node (text token indent)
4838 "Expand the node the user clicked on.
4839 TEXT is the text of the button we clicked on, a + or - item.
4840 TOKEN is data related to this node (NAME . FILE).
4841 INDENT is the current indentation depth."
4842 (cond ((string-match "+" text) ;we have to expand this file
4843 (speedbar-change-expand-button-char ?-)
4844 (if (speedbar-with-writable
4846 (end-of-line) (forward-char 1)
4847 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4848 (speedbar-change-expand-button-char ?-)
4849 (speedbar-change-expand-button-char ??)))
4850 ((string-match "-" text) ;we have to contract this node
4851 (speedbar-change-expand-button-char ?+)
4852 (speedbar-delete-subblock indent))
4853 (t (error "Ooops... not sure what to do")))
4854 (speedbar-center-buffer-smartly))
4856 (defun Info-speedbar-fetch-file-nodes (nodespec)
4857 "Fetch the subnodes from the info NODESPEC.
4858 NODESPEC is a string of the form: (file)node."
4859 ;; Set up a buffer we can use to fake-out Info.
4860 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4861 (if (not (equal major-mode 'Info-mode))
4863 ;; Get the node into this buffer
4864 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4865 (error "Invalid node specification %s" nodespec)
4866 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4867 ;; Scan the created buffer
4868 (goto-char (point-min))
4869 (let ((completions nil)
4870 (case-fold-search t)
4871 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4872 (match-string 1 nodespec))))
4873 ;; Always skip the first one...
4874 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4875 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4876 (let ((name (match-string 1)))
4878 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4880 (if (looking-at " *\\(([^)]+)\\)\\.")
4881 (concat (match-string 1) "Top")
4882 (concat "(" thisfile ")"
4883 (if (looking-at " \\([^.]+\\).")
4887 (nreverse completions))))
4889 ;;; Info mode node listing
4890 ;; This is called by `speedbar-add-localized-speedbar-support'
4891 (defun Info-speedbar-buttons (_buffer)
4892 "Create a speedbar display to help navigation in an Info file.
4893 BUFFER is the buffer speedbar is requesting buttons for."
4894 (if (save-excursion (goto-char (point-min))
4895 (let ((case-fold-search t))
4896 (not (looking-at "Info Nodes:"))))
4898 (Info-speedbar-hierarchy-buttons nil 0))
4900 (dolist (mess '("^First node in file$"
4901 "^No `.*' in index$"
4902 "^No cross-reference named"
4903 "^No cross.references in this node$"
4904 "^No current Info node$"
4905 "^No menu in this node$"
4906 "^No more items in menu$"
4908 "^No pointer \\(?:forward\\|backward\\) from this node$"
4909 "^No previous `i' command$"
4910 "^No previous items in menu$"
4911 "^No previous nodes$"
4912 "^No such item in menu$"
4913 "^No such node or anchor"
4915 "^Point neither on reference nor in menu item description$"
4916 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4918 (add-to-list 'debug-ignored-errors mess))
4920 ;;;; Desktop support
4922 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
4923 "Auxiliary information to be saved in desktop file."
4924 (list Info-current-file
4926 ;; Additional data as an association list.
4929 (cons 'history Info-history))
4930 (and (Info-virtual-fun
4931 'slow Info-current-file Info-current-node)
4934 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
4936 desktop-buffer-misc)
4937 "Restore an Info buffer specified in a desktop file."
4938 (let* ((file (nth 0 desktop-buffer-misc))
4939 (node (nth 1 desktop-buffer-misc))
4940 (data (nth 2 desktop-buffer-misc))
4941 (hist (assq 'history data))
4942 (slow (assq 'slow data)))
4943 ;; Don't restore nodes slow to regenerate.
4945 (when (and file node)
4946 (when desktop-buffer-name
4947 (set-buffer (get-buffer-create desktop-buffer-name))
4949 (Info-find-node file node)
4951 (setq Info-history (cdr hist)))
4952 (current-buffer)))))
4954 (add-to-list 'desktop-buffer-mode-handlers
4955 '(Info-mode . Info-restore-desktop-buffer))
4957 ;;;; Bookmark support
4958 (declare-function bookmark-make-record-default
4959 "bookmark" (&optional no-file no-context posn))
4960 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4961 (declare-function bookmark-default-handler "bookmark" (bmk))
4962 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4964 (defun Info-bookmark-make-record ()
4965 "This implements the `bookmark-make-record-function' type (which see)
4967 `(,Info-current-node
4968 ,@(bookmark-make-record-default 'no-file)
4969 (filename . ,Info-current-file)
4970 (info-node . ,Info-current-node)
4971 (handler . Info-bookmark-jump)))
4974 (defun Info-bookmark-jump (bmk)
4975 "This implements the `handler' function interface for the record
4976 type returned by `Info-bookmark-make-record', which see."
4977 (let* ((file (bookmark-prop-get bmk 'filename))
4978 (info-node (bookmark-prop-get bmk 'info-node))
4979 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4980 (Info-find-node file info-node) (current-buffer))))
4981 ;; Use bookmark-default-handler to move to the appropriate location
4983 (bookmark-default-handler
4984 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4988 (defun info-display-manual (manual)
4989 "Go to Info buffer that displays MANUAL, creating it if none already exists."
4990 (interactive "sManual name: ")
4991 (let ((blist (buffer-list))
4992 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
4993 (case-fold-search t)
4995 (dolist (buffer blist)
4996 (with-current-buffer buffer
4997 (when (and (eq major-mode 'Info-mode)
4998 (stringp Info-current-file)
4999 (string-match manual-re Info-current-file))
5003 (switch-to-buffer found)
5005 (info (Info-find-file manual)))))
5009 ;;; info.el ends here