1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 ;; 2010 Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Note that nowadays we expect Info files to be made using makeinfo.
28 ;; In particular we make these assumptions:
29 ;; - a menu item MAY contain colons but not colon-space ": "
30 ;; - a menu item ending with ": " (but not ":: ") is an index entry
31 ;; - a node name MAY NOT contain a colon
32 ;; This distinction is to support indexing of computer programming
33 ;; language terms that may contain ":" but not ": ".
37 (eval-when-compile (require 'jka-compr
) (require 'cl
))
45 (defvar Info-history nil
46 "Stack of Info nodes user has visited.
47 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
49 (defvar Info-history-forward nil
50 "Stack of Info nodes user has visited with `Info-history-back' command.
51 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
53 (defvar Info-history-list nil
54 "List of all Info nodes user has visited.
55 Each element of the list is a list (FILENAME NODENAME).")
57 (defcustom Info-enable-edit nil
58 "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
59 This is convenient if you want to write Info files by hand.
60 However, we recommend that you not do this.
61 It is better to write a Texinfo file and generate the Info file from that,
62 because that gives you a printed manual as well."
66 (defvar Info-enable-active-nodes nil
67 "Non-nil allows Info to execute Lisp code associated with nodes.
68 The Lisp code is executed when the node is selected.")
69 (put 'Info-enable-active-nodes
'risky-local-variable t
)
72 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
73 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
74 (t :weight bold
:slant italic
))
75 "Face for Info node names."
79 '((((type tty pc
) (class color
) (background light
))
80 :foreground
"green" :weight bold
)
81 (((type tty pc
) (class color
) (background dark
))
82 :foreground
"yellow" :weight bold
)
83 (t :height
1.2 :inherit info-title-2
))
84 "Face for info titles at level 1."
86 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
89 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
90 (t :height
1.2 :inherit info-title-3
))
91 "Face for info titles at level 2."
93 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
96 '((((type tty pc
) (class color
)) :weight bold
)
97 (t :height
1.2 :inherit info-title-4
))
98 "Face for info titles at level 3."
100 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
102 (defface info-title-4
103 '((((type tty pc
) (class color
)) :weight bold
)
104 (t :weight bold
:inherit variable-pitch
))
105 "Face for info titles at level 4."
107 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
109 (defface info-menu-header
114 :inherit variable-pitch
116 "Face for headers in Info menus."
119 (defface info-menu-star
120 '((((class color
)) :foreground
"red1")
122 "Face for every third `*' in an Info menu."
124 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
128 "Face for unvisited Info cross-references."
131 (defface info-xref-visited
132 '((t :inherit
(link-visited info-xref
)))
133 "Face for visited Info cross-references."
137 (defcustom Info-fontify-visited-nodes t
138 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
143 (defcustom Info-fontify-maximum-menu-size
100000
144 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
145 Set to nil to disable node fontification."
149 (defcustom Info-use-header-line t
150 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
151 A header-line does not scroll with the rest of the buffer."
155 (defface info-header-xref
156 '((t :inherit info-xref
))
157 "Face for Info cross-references in a node header."
160 (defface info-header-node
161 '((t :inherit info-node
))
162 "Face for Info nodes in a node header."
165 (defvar Info-directory-list nil
166 "List of directories to search for Info documentation files.
167 If nil, meaning not yet initialized, Info uses the environment
168 variable INFOPATH to initialize it, or `Info-default-directory-list'
169 if there is no INFOPATH variable in the environment, or the
170 concatenation of the two if INFOPATH ends with a colon.
172 When `Info-directory-list' is initialized from the value of
173 `Info-default-directory-list', and Emacs is installed in one of the
174 standard directories, the directory of Info files that come with Emacs
175 is put last (so that local Info files override standard ones).
177 When `Info-directory-list' is initialized from the value of
178 `Info-default-directory-list', and Emacs is not installed in one
179 of the standard directories, the first element of the resulting
180 list is the directory where Emacs installs the Info files that
181 come with it. This is so that Emacs's own manual, which suits the
182 version of Emacs you are using, will always be found first. This
183 is useful when you install an experimental version of Emacs without
184 removing the standard installation.
186 If you want to override the order of directories in
187 `Info-default-directory-list', set INFOPATH in the environment.
189 If you run the Emacs executable from the `src' directory in the Emacs
190 source tree, and INFOPATH is not defined, the `info' directory in the
191 source tree is used as the first element of `Info-directory-list', in
192 place of the installation Info directory. This is useful when you run
193 a version of Emacs without installing it.")
195 (defcustom Info-additional-directory-list nil
196 "List of additional directories to search for Info documentation files.
197 These directories are searched after those in `Info-directory-list'."
198 :type
'(repeat directory
)
201 (defcustom Info-scroll-prefer-subnodes nil
202 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
204 If this is non-nil, and you scroll far enough in a node that its menu
205 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
206 moves to a subnode indicated by the following menu item. This means
207 that you visit a subnode before getting to the end of the menu.
209 Setting this option to nil results in behavior similar to the stand-alone
210 Info reader program, which visits the first subnode from the menu only
211 when you hit the end of the current node."
216 (defcustom Info-hide-note-references t
217 "If non-nil, hide the tag and section reference in *note and * menu items.
218 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
219 If value is non-nil but not t or `hide', the reference section is still shown.
220 `nil' completely disables this feature. If this is non-nil, you might
221 want to set `Info-refill-paragraphs'."
223 :type
'(choice (const :tag
"No hiding" nil
)
224 (const :tag
"Replace tag and hide reference" t
)
225 (const :tag
"Hide tag and reference" hide
)
226 (other :tag
"Only replace tag" tag
))
229 (defcustom Info-refill-paragraphs nil
230 "If non-nil, attempt to refill paragraphs with hidden references.
231 This refilling may accidentally remove explicit line breaks in the Info
232 file, so be prepared for a few surprises if you enable this feature.
233 This only has an effect if `Info-hide-note-references' is non-nil."
238 (defcustom Info-breadcrumbs-depth
4
239 "Depth of breadcrumbs to display.
240 0 means do not display breadcrumbs."
245 (defcustom Info-search-whitespace-regexp
"\\s-+"
246 "If non-nil, regular expression to match a sequence of whitespace chars.
247 This applies to Info search for regular expressions.
248 You might want to use something like \"[ \\t\\r\\n]+\" instead.
249 In the Customization buffer, that is `[' followed by a space,
250 a tab, a carriage return (control-M), a newline, and `]+'."
254 (defcustom Info-isearch-search t
255 "If non-nil, isearch in Info searches through multiple nodes.
256 Before leaving the initial Info node, where isearch was started,
257 it fails once with the error message [initial node], and with
258 subsequent C-s/C-r continues through other nodes without failing
259 with this error message in other nodes. When isearch fails for
260 the rest of the manual, it wraps aroung the whole manual and
261 restarts the search from the top/final node depending on
264 Setting this option to nil restores the default isearch behavior
265 with wrapping around the current Info node."
270 (defvar Info-isearch-initial-node nil
)
271 (defvar Info-isearch-initial-history nil
)
272 (defvar Info-isearch-initial-history-list nil
)
274 (defcustom Info-mode-hook
275 ;; Try to obey obsolete Info-fontify settings.
276 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
277 '(turn-on-font-lock))
278 "Hooks run when `Info-mode' is called."
282 (defcustom Info-selection-hook nil
283 "Hooks run when `Info-select-node' is called."
287 (defvar Info-edit-mode-hook nil
288 "Hooks run when `Info-edit-mode' is called.")
290 (defvar Info-current-file nil
291 "Info file that Info is now looking at, or nil.
292 This is the name that was specified in Info, not the actual file name.
293 It doesn't contain directory names or file name extensions added by Info.")
295 (defvar Info-current-subfile nil
296 "Info subfile that is actually in the *info* buffer now.
297 It is nil if current Info file is not split into subfiles.")
299 (defvar Info-current-node nil
300 "Name of node that Info is now looking at, or nil.")
302 (defvar Info-tag-table-marker nil
303 "Marker pointing at beginning of current Info file's tag table.
304 Marker points nowhere if file has no tag table.")
306 (defvar Info-tag-table-buffer nil
307 "Buffer used for indirect tag tables.")
309 (defvar Info-current-file-completions nil
310 "Cached completion list for current Info file.")
312 (defvar Info-file-supports-index-cookies nil
313 "Non-nil if current Info file supports index cookies.")
315 (defvar Info-file-supports-index-cookies-list nil
316 "List of Info files with information about index cookies support.
317 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
318 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
320 (defvar Info-index-alternatives nil
321 "List of possible matches for last `Info-index' command.")
323 (defvar Info-point-loc nil
324 "Point location within a selected node.
325 If string, the point is moved to the proper occurrence of the
326 name of the followed cross reference within a selected node.
327 If number, the point is moved to the corresponding line.")
329 (defvar Info-standalone nil
330 "Non-nil if Emacs was started solely as an Info browser.")
332 (defvar Info-virtual-files nil
333 "List of definitions of virtual Info files.
334 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
335 where FILENAME is a regexp that matches a class of virtual Info file names.
336 It should be carefully chosen to not cause file name clashes with
337 existing file names. OPERATION is one of the following operation
338 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
339 function to call instead of calling the default corresponding function
342 (defvar Info-virtual-nodes nil
343 "List of definitions of virtual Info nodes.
344 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
345 where NODENAME is a regexp that matches a class of virtual Info node names.
346 It should be carefully chosen to not cause node name clashes with
347 existing node names. OPERATION is one of the following operation
348 symbols `find-node' that define what HANDLER
349 function to call instead of calling the default corresponding function
352 (defvar Info-current-node-virtual nil
353 "Non-nil if the current Info node is virtual.")
355 (defun Info-virtual-file-p (filename)
356 "Check if Info file FILENAME is virtual."
357 (Info-virtual-fun 'find-file filename nil
))
359 (defun Info-virtual-fun (op filename nodename
)
360 "Find a function that handles operations on virtual manuals.
361 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
362 FILENAME is a virtual Info file name, NODENAME is a virtual Info
363 node name. Return a function found either in `Info-virtual-files'
364 or `Info-virtual-nodes'."
365 (or (and (stringp filename
) ; some legacy code can still use a symbol
366 (cdr-safe (assoc op
(assoc-default filename
369 (and (stringp nodename
) ; some legacy code can still use a symbol
370 (cdr-safe (assoc op
(assoc-default nodename
374 (defun Info-virtual-call (virtual-fun &rest args
)
375 "Call a function that handles operations on virtual manuals."
376 (when (functionp virtual-fun
)
377 (or (apply virtual-fun args
) t
)))
380 (defvar Info-suffix-list
381 ;; The MS-DOS list should work both when long file names are
382 ;; supported (Windows 9X), and when only 8+3 file names are available.
383 (if (eq system-type
'ms-dos
)
384 '( (".gz" .
"gunzip")
386 (".bz2" .
("bzip2" "-dc"))
389 (".info.Z" .
"gunzip")
390 (".info.gz" .
"gunzip")
391 ("-info.Z" .
"gunzip")
392 ("-info.gz" .
"gunzip")
393 ("/index.gz".
"gunzip")
394 ("/index.z" .
"gunzip")
400 '( (".info.Z".
"uncompress")
401 (".info.Y".
"unyabba")
402 (".info.gz".
"gunzip")
403 (".info.z".
"gunzip")
404 (".info.bz2" .
("bzip2" "-dc"))
407 ("-info.Z".
"uncompress")
408 ("-info.Y".
"unyabba")
409 ("-info.gz".
"gunzip")
410 ("-info.bz2" .
("bzip2" "-dc"))
411 ("-info.z".
"gunzip")
414 ("/index.Z".
"uncompress")
415 ("/index.Y".
"unyabba")
416 ("/index.gz".
"gunzip")
417 ("/index.z".
"gunzip")
418 ("/index.bz2".
("bzip2" "-dc"))
419 ("/index.xz".
"unxz")
425 (".bz2" .
("bzip2" "-dc"))
428 "List of file name suffixes and associated decoding commands.
429 Each entry should be (SUFFIX . STRING); the file is given to
430 the command as standard input.
432 STRING may be a list of strings. In that case, the first element is
433 the command name, and the rest are arguments to that command.
435 If STRING is nil, no decoding is done.
436 Because the SUFFIXes are tried in order, the empty string should
437 be last in the list.")
439 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
440 ;; First, on MS-DOS with no long file names support, delete some of
441 ;; the extension in FILENAME to make room.
442 (defun info-insert-file-contents-1 (filename suffix lfn
)
443 (if lfn
; long file names are supported
444 (concat filename suffix
)
445 (let* ((sans-exts (file-name-sans-extension filename
))
446 ;; How long is the extension in FILENAME (not counting the dot).
447 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
449 ;; SUFFIX starts with a dot. If FILENAME already has one,
450 ;; get rid of the one in SUFFIX (unless suffix is empty).
451 (or (and (<= ext-len
0)
452 (not (eq (aref filename
(1- (length filename
))) ?.
)))
453 (= (length suffix
) 0)
454 (setq suffix
(substring suffix
1)))
455 ;; How many chars of that extension should we keep?
456 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
457 ;; Get rid of the rest of the extension, and add SUFFIX.
458 (concat (substring filename
0 (- (length filename
)
459 (- ext-len ext-left
)))
462 (defun info-file-exists-p (filename)
463 (and (file-exists-p filename
)
464 (not (file-directory-p filename
))))
466 (defun info-insert-file-contents (filename &optional visit
)
467 "Insert the contents of an Info file in the current buffer.
468 Do the right thing if the file has been compressed or zipped."
469 (let* ((tail Info-suffix-list
)
470 (lfn (if (fboundp 'msdos-long-file-names
)
471 (msdos-long-file-names)
473 (check-short (and (fboundp 'msdos-long-file-names
)
475 fullname decoder done
)
476 (if (info-file-exists-p filename
)
477 ;; FILENAME exists--see if that name contains a suffix.
478 ;; If so, set DECODE accordingly.
482 (concat (regexp-quote (car (car tail
))) "$")
484 (setq tail
(cdr tail
)))
485 (setq fullname filename
486 decoder
(cdr (car tail
))))
487 ;; Try adding suffixes to FILENAME and see if we can find something.
488 (while (and tail
(not done
))
489 (setq fullname
(info-insert-file-contents-1 filename
490 (car (car tail
)) lfn
))
491 (if (info-file-exists-p fullname
)
493 ;; If we found a file with a suffix, set DECODER
494 ;; according to the suffix.
495 decoder
(cdr (car tail
)))
496 ;; When the MS-DOS port runs on Windows, we need to check
497 ;; the short variant of a long file name as well.
499 (setq fullname
(info-insert-file-contents-1 filename
500 (car (car tail
)) nil
))
501 (if (info-file-exists-p fullname
)
503 decoder
(cdr (car tail
))))))
504 (setq tail
(cdr tail
)))
506 (error "Can't find %s or any compressed version of it" filename
)))
507 ;; check for conflict with jka-compr
508 (if (and (jka-compr-installed-p)
509 (jka-compr-get-compression-info fullname
))
513 (insert-file-contents-literally fullname visit
)
514 (let ((inhibit-read-only t
)
515 (coding-system-for-write 'no-conversion
)
516 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
517 (default-directory (or (file-name-directory fullname
)
520 (setq decoder
(list decoder
)))
521 (apply 'call-process-region
(point-min) (point-max)
522 (car decoder
) t t nil
(cdr decoder
))))
523 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
524 (insert-file-contents fullname visit
)))))
526 (defun Info-file-supports-index-cookies (&optional file
)
527 "Return non-nil value if FILE supports Info index cookies.
528 Info index cookies were first introduced in 4.7, and all later
529 makeinfo versions output them in index nodes, so we can rely
530 solely on the makeinfo version. This function caches the information
531 in `Info-file-supports-index-cookies-list'."
532 (or file
(setq file Info-current-file
))
533 (or (assoc file Info-file-supports-index-cookies-list
)
534 ;; Skip virtual Info files
535 (and (or (not (stringp file
))
536 (Info-virtual-file-p file
))
537 (setq Info-file-supports-index-cookies-list
538 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
541 (goto-char (point-min))
543 (if (and (re-search-forward
544 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
545 (line-beginning-position 3) t
)
546 (not (version< (match-string 1) "4.7")))
549 (setq Info-file-supports-index-cookies-list
550 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
551 (cdr (assoc file Info-file-supports-index-cookies-list
)))
554 (defun Info-default-dirs ()
555 (let ((source (expand-file-name "info/" source-directory
))
556 (sibling (if installation-directory
557 (expand-file-name "info/" installation-directory
)
558 (if invocation-directory
559 (let ((infodir (expand-file-name
561 invocation-directory
)))
562 (if (file-exists-p infodir
)
564 (setq infodir
(expand-file-name
565 "../../../share/info/"
566 invocation-directory
))
567 (and (file-exists-p infodir
)
571 (if (and sibling
(file-exists-p sibling
))
572 ;; Uninstalled, Emacs builddir != srcdir.
574 ;; Uninstalled, builddir == srcdir
576 (if (or (member alternative Info-default-directory-list
)
577 ;; On DOS/NT, we use movable executables always,
578 ;; and we must always find the Info dir at run time.
579 (if (memq system-type
'(ms-dos windows-nt
))
581 ;; Use invocation-directory for Info
582 ;; only if we used it for exec-directory also.
583 (not (string= exec-directory
584 (expand-file-name "lib-src/"
585 installation-directory
))))
586 (not (file-exists-p alternative
)))
587 Info-default-directory-list
588 ;; `alternative' contains the Info files that came with this
589 ;; version, so we should look there first. `Info-insert-dir'
590 ;; currently expects to find `alternative' first on the list.
592 ;; Don't drop the last part, it might contain non-Emacs stuff.
593 ;; (reverse (cdr (reverse
594 Info-default-directory-list
)))) ;; )))
596 (defun info-initialize ()
597 "Initialize `Info-directory-list', if that hasn't been done yet."
598 (unless Info-directory-list
599 (let ((path (getenv "INFOPATH")))
600 (setq Info-directory-list
601 (prune-directory-list
603 (if (string-match ":\\'" path
)
604 (append (split-string (substring path
0 -
1)
605 (regexp-quote path-separator
))
607 (split-string path
(regexp-quote path-separator
)))
608 (Info-default-dirs)))))))
611 (defun info-other-window (&optional file-or-node
)
612 "Like `info' but show the Info buffer in another window."
613 (interactive (if current-prefix-arg
614 (list (read-file-name "Info file name: " nil nil t
))))
615 (info file-or-node nil
'same-frame
))
617 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
619 (defun info (&optional file-or-node buffer window-specifiers
)
620 "Enter Info, the documentation browser.
621 Optional argument FILE-OR-NODE specifies the file to examine;
622 the default is the top-level directory of Info.
623 Called from a program, FILE-OR-NODE may specify an Info node of the form
624 `(FILENAME)NODENAME'.
625 Optional argument BUFFER specifies the Info buffer name;
626 the default buffer name is *info*. If BUFFER exists,
627 just switch to BUFFER. Otherwise, create a new buffer
628 with the top-level Info directory.
630 In interactive use, a non-numeric prefix argument directs
631 this command to read a file name from the minibuffer.
632 A numeric prefix argument selects an Info buffer with the prefix number
633 appended to the Info buffer name.
635 The search path for Info files is in the variable `Info-directory-list'.
636 The top-level Info directory is made by combining all the files named `dir'
637 in all the directories in that path.
639 See a list of available Info commands in `Info-mode'."
641 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
642 (read-file-name "Info file name: " nil nil t
))
643 (if (numberp current-prefix-arg
)
644 (format "*info*<%s>" current-prefix-arg
))))
646 (or buffer
"*info*") (or window-specifiers
'same-window
))
647 (if (and buffer
(not (eq major-mode
'Info-mode
)))
650 ;; If argument already contains parentheses, don't add another set
651 ;; since the argument will then be parsed improperly. This also
652 ;; has the added benefit of allowing node names to be included
653 ;; following the parenthesized filename.
655 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
657 (concat "(" file-or-node
")")))
658 (if (and (zerop (buffer-size))
660 ;; If we just created the Info buffer, go to the directory.
664 (defun info-emacs-manual ()
665 "Display the Emacs manual in Info mode."
670 (defun info-standalone ()
671 "Run Emacs as a standalone Info reader.
672 Usage: emacs -f info-standalone [filename]
673 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
674 (setq Info-standalone t
)
675 (if (and command-line-args-left
676 (not (string-match "^-" (car command-line-args-left
))))
679 (info (car command-line-args-left
))
680 (setq command-line-args-left
(cdr command-line-args-left
)))
681 (error (send-string-to-terminal
682 (format "%s\n" (if (eq (car-safe err
) 'error
)
684 (save-buffers-kill-emacs)))
687 ;; See if the accessible portion of the buffer begins with a node
688 ;; delimiter, and the node header line which follows matches REGEXP.
689 ;; Typically, this test will be followed by a loop that examines the
690 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
691 ;; to have the overhead of this special test inside the loop.
693 ;; This function changes match-data, but supposedly the caller might
694 ;; want to use the results of re-search-backward.
696 ;; The return value is the value of point at the beginning of matching
697 ;; REGEXP, if the function succeeds, nil otherwise.
698 (defun Info-node-at-bob-matching (regexp)
699 (and (bobp) ; are we at beginning of buffer?
700 (looking-at "\^_") ; does it begin with node delimiter?
704 (forward-line 1) ; does the line after delimiter match REGEXP?
705 (re-search-backward regexp beg t
))))
707 (defun Info-find-file (filename &optional noerror
)
708 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
709 Optional second argument NOERROR, if t, means if file is not found
710 just return nil (no error)."
711 ;; Convert filename to lower case if not found as specified.
715 (Info-virtual-fun 'find-file filename nil
)
718 (let (temp temp-downcase found
)
719 (setq filename
(substitute-in-file-name filename
))
720 (let ((dirs (if (string-match "^\\./" filename
)
721 ;; If specified name starts with `./'
722 ;; then just try current directory.
724 (if (file-name-absolute-p filename
)
725 ;; No point in searching for an
726 ;; absolute file name
728 (if Info-additional-directory-list
729 (append Info-directory-list
730 Info-additional-directory-list
)
731 Info-directory-list
)))))
732 ;; Search the directory list for file FILENAME.
733 (while (and dirs
(not found
))
734 (setq temp
(expand-file-name filename
(car dirs
)))
736 (expand-file-name (downcase filename
) (car dirs
)))
737 ;; Try several variants of specified name.
738 (let ((suffix-list Info-suffix-list
)
739 (lfn (if (fboundp 'msdos-long-file-names
)
740 (msdos-long-file-names)
742 (while (and suffix-list
(not found
))
743 (cond ((info-file-exists-p
744 (info-insert-file-contents-1
745 temp
(car (car suffix-list
)) lfn
))
748 (info-insert-file-contents-1
749 temp-downcase
(car (car suffix-list
)) lfn
))
750 (setq found temp-downcase
))
751 ((and (fboundp 'msdos-long-file-names
)
754 (info-insert-file-contents-1
755 temp
(car (car suffix-list
)) nil
)))
757 (setq suffix-list
(cdr suffix-list
))))
758 (setq dirs
(cdr dirs
))))
760 (setq filename found
)
763 (error "Info file %s does not exist" filename
)))
766 (defun Info-find-node (filename nodename
&optional no-going-back
)
767 "Go to an Info node specified as separate FILENAME and NODENAME.
768 NO-GOING-BACK is non-nil if recovering from an error in this function;
769 it says do not attempt further (recursive) error recovery."
771 (setq filename
(Info-find-file filename
))
772 ;; Go into Info buffer.
773 (or (eq major-mode
'Info-mode
)
774 (pop-to-buffer "*info*" 'same-window
))
775 ;; Record the node we are leaving, if we were in one.
776 (and (not no-going-back
)
778 (push (list Info-current-file Info-current-node
(point))
780 (Info-find-node-2 filename nodename no-going-back
))
783 (defun Info-on-current-buffer (&optional nodename
)
784 "Use Info mode to browse the current Info buffer.
785 With a prefix arg, this queries for the node name to visit first;
786 otherwise, that defaults to `Top'."
788 (list (if current-prefix-arg
789 (completing-read "Node name: " (Info-build-node-completions)
791 (unless nodename
(setq nodename
"Top"))
794 (set (make-local-variable 'Info-current-file
)
796 ;; If called on a non-file buffer, make a fake file name.
797 (concat default-directory
(buffer-name))))
798 (Info-find-node-2 nil nodename
))
800 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
801 ;; but at least it keeps this routine (which is for makeinfo-buffer and
802 ;; Info-revert-buffer-function) out of the way of normal operations.
804 (defun Info-revert-find-node (filename nodename
)
805 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
806 When *info* is already displaying FILENAME and NODENAME, the window position
807 is preserved, if possible."
808 (or (eq major-mode
'Info-mode
)
809 (pop-to-buffer "*info*" 'same-window
))
810 (let ((old-filename Info-current-file
)
811 (old-nodename Info-current-node
)
812 (old-buffer-name (buffer-name))
813 (pcolumn (current-column))
814 (pline (count-lines (point-min) (line-beginning-position)))
815 (wline (count-lines (point-min) (window-start)))
816 (old-history-forward Info-history-forward
)
817 (old-history Info-history
)
818 (new-history (and Info-current-file
819 (list Info-current-file Info-current-node
(point)))))
820 (kill-buffer (current-buffer))
822 (or old-buffer-name
"*info*") 'same-window
)
824 (Info-find-node filename nodename
)
825 (setq Info-history-forward old-history-forward
)
826 (setq Info-history old-history
)
827 (if (and (equal old-filename Info-current-file
)
828 (equal old-nodename Info-current-node
))
830 ;; note goto-line is no good, we want to measure from point-min
831 (goto-char (point-min))
833 (set-window-start (selected-window) (point))
834 (goto-char (point-min))
836 (move-to-column pcolumn
))
837 ;; only add to the history when coming from a different file+node
839 (setq Info-history
(cons new-history Info-history
))))))
841 (defun Info-revert-buffer-function (ignore-auto noconfirm
)
842 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
843 (Info-revert-find-node Info-current-file Info-current-node
)
844 (message "Reverted %s" Info-current-file
)))
846 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
847 "Find a node in a tag table.
848 MARKER specifies the buffer and position to start searching at.
849 REGEXP is a regular expression matching nodes or references. Its first
850 group should match `Node:' or `Ref:'.
851 CASE-FOLD t means search for a case-insensitive match.
852 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
853 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
854 where the match was found, and MODE is `major-mode' of the buffer in
855 which the match was found."
856 (let ((case-fold-search case-fold
))
857 (with-current-buffer (marker-buffer marker
)
862 (when (re-search-forward regexp nil t
)
863 (list (string-equal "Ref:" (match-string 1))
864 (+ (point-min) (read (current-buffer)))
867 (defun Info-find-in-tag-table (marker regexp
)
868 "Find a node in a tag table.
869 MARKER specifies the buffer and position to start searching at.
870 REGEXP is a regular expression matching nodes or references. Its first
871 group should match `Node:' or `Ref:'.
872 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
873 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
874 where the match was found, and MODE is `major-mode' of the buffer in
875 which the match was found.
876 This function tries to find a case-sensitive match first, then a
877 case-insensitive match is tried."
878 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
879 (when (null (car result
))
880 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
883 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
884 "Find a node or anchor in the current buffer.
885 REGEXP is a regular expression matching nodes or references. Its first
886 group should match `Node:' or `Ref:'.
887 CASE-FOLD t means search for a case-insensitive match.
888 Value is the position at which a match was found, or nil if not found."
889 (let ((case-fold-search case-fold
)
892 (if (Info-node-at-bob-matching regexp
)
894 (while (and (not found
)
895 (search-forward "\n\^_" nil t
))
899 (if (re-search-backward regexp beg t
)
900 (setq found
(line-beginning-position)))))))
903 (defun Info-find-node-in-buffer (regexp)
904 "Find a node or anchor in the current buffer.
905 REGEXP is a regular expression matching nodes or references. Its first
906 group should match `Node:' or `Ref:'.
907 Value is the position at which a match was found, or nil if not found.
908 This function looks for a case-sensitive match first. If none is found,
909 a case-insensitive match is tried."
910 (or (Info-find-node-in-buffer-1 regexp nil
)
911 (Info-find-node-in-buffer-1 regexp t
)))
913 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
914 (buffer-disable-undo (current-buffer))
915 (or (eq major-mode
'Info-mode
)
918 (setq Info-current-node nil
)
920 (let ((case-fold-search t
)
921 (virtual-fun (Info-virtual-fun 'find-node
922 (or filename Info-current-file
)
926 ((functionp virtual-fun
)
927 (let ((filename (or filename Info-current-file
)))
928 (setq buffer-read-only nil
)
929 (setq Info-current-file filename
930 Info-current-subfile nil
931 Info-current-file-completions nil
932 buffer-file-name nil
)
934 (Info-virtual-call virtual-fun filename nodename no-going-back
)
935 (set-marker Info-tag-table-marker nil
)
936 (setq buffer-read-only t
)
937 (set-buffer-modified-p nil
)
938 (set (make-local-variable 'Info-current-node-virtual
) t
)))
940 ;; Reread a file when moving from a virtual node.
941 (not Info-current-node-virtual
)
943 (equal Info-current-file filename
))))
944 ;; Switch files if necessary
945 (let ((inhibit-read-only t
))
946 (when Info-current-node-virtual
947 ;; When moving from a virtual node.
948 (set (make-local-variable 'Info-current-node-virtual
) nil
)
950 (setq filename Info-current-file
)))
951 (setq Info-current-file nil
952 Info-current-subfile nil
953 Info-current-file-completions nil
954 buffer-file-name nil
)
956 (info-insert-file-contents filename nil
)
957 (setq default-directory
(file-name-directory filename
))
958 (set-buffer-modified-p nil
)
959 (set (make-local-variable 'Info-file-supports-index-cookies
)
960 (Info-file-supports-index-cookies filename
))
962 ;; See whether file has a tag table. Record the location if yes.
963 (goto-char (point-max))
965 ;; Use string-equal, not equal, to ignore text props.
966 (if (not (or (string-equal nodename
"*")
968 (search-forward "\^_\nEnd tag table\n" nil t
))))
970 ;; We have a tag table. Find its beginning.
971 ;; Is this an indirect file?
972 (search-backward "\nTag table:\n")
976 (looking-at "(Indirect)\n"))
977 ;; It is indirect. Copy it to another buffer
978 ;; and record that the tag table is in that buffer.
979 (let ((buf (current-buffer))
981 (or Info-tag-table-buffer
982 (generate-new-buffer " *info tag table*"))))
983 (setq Info-tag-table-buffer tagbuf
)
984 (with-current-buffer tagbuf
985 (buffer-disable-undo (current-buffer))
986 (setq case-fold-search t
)
988 (insert-buffer-substring buf
))
989 (set-marker Info-tag-table-marker
990 (match-end 0) tagbuf
))
991 (set-marker Info-tag-table-marker pos
)))
992 (set-marker Info-tag-table-marker nil
))
993 (setq Info-current-file filename
)
996 ;; Use string-equal, not equal, to ignore text props.
997 (if (string-equal nodename
"*")
998 (progn (setq Info-current-node nodename
)
999 (Info-set-mode-line))
1002 ;; 1. Anchor found in tag table
1003 ;; 2. Anchor *not* in tag table
1005 ;; 3. Node found in tag table
1006 ;; 4. Node *not* found in tag table, but found in file
1007 ;; 5. Node *not* in tag table, and *not* in file
1009 ;; *Or* the same, but in an indirect subfile.
1011 ;; Search file for a suitable node.
1012 (let ((guesspos (point-min))
1013 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1014 (if (stringp nodename
)
1015 (regexp-quote nodename
)
1017 "\\) *[,\t\n\177]")))
1021 ;; First, search a tag table, if any
1022 (when (marker-position Info-tag-table-marker
)
1023 (let* ((m Info-tag-table-marker
)
1024 (found (Info-find-in-tag-table m regexp
)))
1027 ;; FOUND is (ANCHOR POS MODE).
1028 (setq guesspos
(nth 1 found
))
1030 ;; If this is an indirect file, determine which
1031 ;; file really holds this node and read it in.
1032 (unless (eq (nth 2 found
) 'Info-mode
)
1033 ;; Note that the current buffer must be the
1034 ;; *info* buffer on entry to
1035 ;; Info-read-subfile. Thus the hackery above.
1036 (setq guesspos
(Info-read-subfile guesspos
)))
1040 (goto-char (setq anchorpos guesspos
))
1043 ;; Else we may have a node, which we search for:
1044 (goto-char (max (point-min)
1045 (- (byte-to-position guesspos
) 1000)))
1047 ;; Now search from our advised position (or from beg of
1048 ;; buffer) to find the actual node. First, check
1049 ;; whether the node is right where we are, in case the
1050 ;; buffer begins with a node.
1051 (let ((pos (Info-find-node-in-buffer regexp
)))
1056 (when (string-match "\\([^.]+\\)\\." nodename
)
1057 (let (Info-point-loc)
1059 filename
(match-string 1 nodename
) no-going-back
))
1063 ;; No such anchor in tag table or node in tag table or file
1064 (error "No such node or anchor: %s" nodename
))
1067 (goto-char (point-min))
1068 (forward-line 1) ; skip header line
1069 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1070 ;; (forward-line 1))
1073 (let ((new-history (list Info-current-file
1074 (substring-no-properties nodename
))))
1075 ;; Add anchors to the history too
1076 (setq Info-history-list
1078 (delete new-history Info-history-list
))))
1079 (goto-char anchorpos
))
1080 ((numberp Info-point-loc
)
1081 (forward-line (- Info-point-loc
2))
1082 (setq Info-point-loc nil
))
1083 ((stringp Info-point-loc
)
1084 (Info-find-index-name Info-point-loc
)
1085 (setq Info-point-loc nil
))))))
1086 ;; If we did not finish finding the specified node,
1087 ;; go back to the previous one.
1088 (or Info-current-node no-going-back
(null Info-history
)
1089 (let ((hist (car Info-history
)))
1090 (setq Info-history
(cdr Info-history
))
1091 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1092 (goto-char (nth 2 hist
))))))
1094 ;; Cache the contents of the (virtual) dir file, once we have merged
1095 ;; it for the first time, so we can save time subsequently.
1096 (defvar Info-dir-contents nil
)
1098 ;; Cache for the directory we decided to use for the default-directory
1099 ;; of the merged dir text.
1100 (defvar Info-dir-contents-directory nil
)
1102 ;; Record the file attributes of all the files from which we
1103 ;; constructed Info-dir-contents.
1104 (defvar Info-dir-file-attributes nil
)
1106 (defvar Info-dir-file-name nil
)
1108 ;; Construct the Info directory node by merging the files named `dir'
1109 ;; from various directories. Set the *info* buffer's
1110 ;; default-directory to the first directory we actually get any text
1112 (defun Info-insert-dir ()
1113 (if (and Info-dir-contents Info-dir-file-attributes
1114 ;; Verify that none of the files we used has changed
1115 ;; since we used it.
1117 (mapcar (lambda (elt)
1118 (let ((curr (file-attributes
1120 (file-truename (car elt
)))))
1122 ;; Don't compare the access time.
1123 (if curr
(setcar (nthcdr 4 curr
) 0))
1124 (setcar (nthcdr 4 (cdr elt
)) 0)
1125 (equal (cdr elt
) curr
)))
1126 Info-dir-file-attributes
))))
1128 (insert Info-dir-contents
)
1129 (goto-char (point-min)))
1130 (let ((dirs (if Info-additional-directory-list
1131 (append Info-directory-list
1132 Info-additional-directory-list
)
1133 Info-directory-list
))
1134 (dir-file-attrs nil
)
1135 ;; Bind this in case the user sets it to nil.
1136 (case-fold-search t
)
1137 ;; This is set non-nil if we find a problem in some input files.
1139 buffers buffer others nodes dirs-done
)
1141 ;; Search the directory list for the directory file.
1143 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1144 (or (member truename dirs-done
)
1145 (member (directory-file-name truename
) dirs-done
)
1146 ;; Try several variants of specified name.
1147 ;; Try upcasing, appending `.info', or both.
1151 (progn (setq file
(expand-file-name "dir" truename
))
1152 (file-attributes file
))
1153 (progn (setq file
(expand-file-name "DIR" truename
))
1154 (file-attributes file
))
1155 (progn (setq file
(expand-file-name "dir.info" truename
))
1156 (file-attributes file
))
1157 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1158 (file-attributes file
)))))
1161 (cons (directory-file-name truename
)
1164 (with-current-buffer (generate-new-buffer " info dir")
1166 (message "Composing main Info directory..."))
1168 ;; Index nodes include null bytes. DIR
1169 ;; files should not have indices, but who
1171 (let ((inhibit-null-byte-detection t
))
1172 (insert-file-contents file
)
1173 (set (make-local-variable 'Info-dir-file-name
)
1175 (push (current-buffer) buffers
)
1176 (push (cons file attrs
) dir-file-attrs
))
1177 (error (kill-buffer (current-buffer))))))))
1179 (set (make-local-variable 'Info-dir-contents-directory
)
1180 (file-name-as-directory (car dirs
))))
1181 (setq dirs
(cdr dirs
))))
1184 (error "Can't find the Info directory node"))
1186 ;; Distinguish the dir file that comes with Emacs from all the
1187 ;; others. Yes, that is really what this is supposed to do.
1188 ;; The definition of `Info-directory-list' puts it first on that
1189 ;; list and so last in `buffers' at this point.
1190 (setq buffer
(car (last buffers
))
1191 others
(delq buffer buffers
))
1193 ;; Insert the entire original dir file as a start; note that we've
1194 ;; already saved its default directory to use as the default
1195 ;; directory for the whole concatenation.
1196 (save-excursion (insert-buffer-substring buffer
))
1198 ;; Look at each of the other buffers one by one.
1199 (dolist (other others
)
1200 (let (this-buffer-nodes)
1201 ;; In each, find all the menus.
1202 (with-current-buffer other
1203 (goto-char (point-min))
1204 ;; Find each menu, and add an elt to NODES for it.
1205 (while (re-search-forward "^\\* Menu:" nil t
)
1206 (while (and (zerop (forward-line 1)) (eolp)))
1209 (re-search-backward "^\^_")
1210 (search-forward "Node: ")
1211 (setq nodename
(Info-following-node-name))
1212 (search-forward "\n\^_" nil
'move
)
1215 (push (list nodename other beg end
) this-buffer-nodes
)))
1216 (if (assoc-string "top" this-buffer-nodes t
)
1217 (setq nodes
(nconc this-buffer-nodes nodes
))
1219 (message "No `top' node in %s" Info-dir-file-name
)))))
1220 ;; Add to the main menu a menu item for each other node.
1221 (re-search-forward "^\\* Menu:")
1223 (let ((menu-items '("top"))
1224 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1225 (dolist (node nodes
)
1226 (let ((nodename (car node
)))
1228 (or (member (downcase nodename
) menu-items
)
1229 (re-search-forward (concat "^\\* +"
1230 (regexp-quote nodename
)
1234 (insert "* " nodename
"::" "\n")
1235 (push nodename menu-items
)))))))
1236 ;; Now take each node of each of the other buffers
1237 ;; and merge it into the main buffer.
1238 (dolist (node nodes
)
1239 (let ((case-fold-search t
)
1240 (nodename (car node
)))
1241 (goto-char (point-min))
1242 ;; Find the like-named node in the main buffer.
1243 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1244 (regexp-quote nodename
)
1248 (search-forward "\n\^_" nil
'move
)
1251 ;; If none exists, add one.
1252 (goto-char (point-max))
1253 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1254 ;; Merge the text from the other buffer's menu
1255 ;; into the menu in the like-named node in the main buffer.
1256 (apply 'insert-buffer-substring
(cdr node
))))
1257 (Info-dir-remove-duplicates)
1258 ;; Kill all the buffers we just made, including the special one excised.
1259 (mapc 'kill-buffer
(cons buffer buffers
))
1260 (goto-char (point-min))
1262 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1263 (message "Composing main Info directory...done"))
1264 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1265 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1266 (setq default-directory Info-dir-contents-directory
))
1268 (defvar Info-streamline-headings
1269 '(("Emacs" .
"Emacs")
1270 ("Programming" .
"Programming")
1271 ("Libraries" .
"Libraries")
1272 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1273 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1275 (defun Info-dir-remove-duplicates ()
1277 (goto-char (point-min))
1278 ;; Remove duplicate headings in the same menu.
1279 (while (search-forward "\n* Menu:" nil t
)
1280 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1281 ;; Look for the next heading to unify.
1282 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1283 (let ((name (match-string 1))
1284 (start (match-beginning 0))
1286 ;; Check whether this heading should be streamlined.
1288 (dolist (x Info-streamline-headings
)
1289 (when (string-match (car x
) name
)
1291 (setq re
(car x
)))))
1292 (if re
(replace-match name t t nil
1))
1293 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1295 (or limit
(point-max))))
1296 ;; Look for other headings of the same category and merge them.
1298 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1299 (when (if re
(save-match-data (string-match re
(match-string 1)))
1300 (equal name
(match-string 1)))
1302 ;; Delete redundant heading.
1303 (delete-region (match-beginning 0) (point))
1304 ;; Push the entries onto `text'.
1306 (delete-and-extract-region
1308 (if (re-search-forward "^[^* \n\t]" nil t
)
1310 (or limit
(point-max))))
1313 ;; Insert the entries just found.
1314 (while (= (line-beginning-position 0) (1- (point)))
1316 (dolist (entry (nreverse entries
))
1318 (while (= (line-beginning-position 0) (1- (point)))
1319 (delete-region (1- (point)) (point))))
1321 ;; Now remove duplicate entries under the same heading.
1324 (narrow-to-region start
(point))
1325 (goto-char (point-min))
1326 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1327 ;; Fold case straight away; `member-ignore-case' here wasteful.
1328 (let ((x (downcase (match-string 1))))
1332 (if (re-search-forward "^[^ \t]" nil
'move
)
1333 (goto-char (match-beginning 0))
1335 (push x seen
)))))))))))
1337 ;; Note that on entry to this function the current-buffer must be the
1338 ;; *info* buffer; not the info tags buffer.
1339 (defun Info-read-subfile (nodepos)
1340 ;; NODEPOS is either a position (in the Info file as a whole,
1341 ;; not relative to a subfile) or the name of a subfile.
1344 (if (numberp nodepos
)
1345 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1346 (goto-char (point-min))
1347 (or (looking-at "\^_")
1348 (search-forward "\n\^_"))
1351 (while (not (looking-at "\^_"))
1354 thisfilepos thisfilename
)
1355 (search-forward ": ")
1356 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1357 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1358 ;; read in version 19 stops at the end of number.
1359 ;; Advance to the next line.
1361 (if (> thisfilepos nodepos
)
1363 (setq lastfilename thisfilename
)
1364 (setq lastfilepos thisfilepos
))
1365 (forward-line 1)))))
1366 (setq lastfilename nodepos
)
1367 (setq lastfilepos
0))
1368 ;; Assume previous buffer is in Info-mode.
1369 ;; (set-buffer (get-buffer "*info*"))
1370 (or (equal Info-current-subfile lastfilename
)
1371 (let ((inhibit-read-only t
))
1372 (setq buffer-file-name nil
)
1375 (info-insert-file-contents lastfilename
)
1376 (set-buffer-modified-p nil
)
1377 (setq Info-current-subfile lastfilename
)))
1378 ;; Widen in case we are in the same subfile as before.
1380 (goto-char (point-min))
1381 (if (looking-at "\^_")
1383 (search-forward "\n\^_"))
1384 (if (numberp nodepos
)
1385 (+ (- nodepos lastfilepos
) (point)))))
1387 (defun Info-unescape-quotes (value)
1388 "Unescape double quotes and backslashes in VALUE."
1391 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1392 (setq unquote
(replace-match "" t t unquote
1))
1393 (setq start
(- (match-end 0) 1)))
1396 ;; As of Texinfo 4.6, makeinfo writes constructs like
1397 ;; \0\h[image param=value ...\h\0]
1398 ;; into the Info file for handling images.
1399 (defun Info-split-parameter-string (parameter-string)
1400 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1401 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1402 whitespace or double quotes, it must be quoted in double quotes and
1403 any double quotes or backslashes must be escaped (\\\",\\\\)."
1406 (while (string-match
1407 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1408 parameter-string start
)
1409 (setq start
(match-end 0))
1410 (push (cons (match-string 1 parameter-string
)
1411 (or (match-string 2 parameter-string
)
1412 (Info-unescape-quotes
1413 (match-string 3 parameter-string
))))
1417 (defun Info-display-images-node ()
1418 "Display images in current node."
1420 (let ((inhibit-read-only t
)
1421 (case-fold-search t
))
1422 (goto-char (point-min))
1423 (while (re-search-forward
1424 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1426 (let* ((start (match-beginning 1))
1427 (parameter-alist (Info-split-parameter-string (match-string 2)))
1428 (src (cdr (assoc-string "src" parameter-alist
))))
1429 (if (display-images-p)
1430 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1431 (concat default-directory src
))
1433 (image (if (file-exists-p image-file
)
1434 (create-image image-file
)
1436 (if (not (get-text-property start
'display
))
1437 (add-text-properties
1438 start
(point) `(display ,image rear-nonsticky
(display)))))
1439 ;; text-only display, show alternative text if provided, or
1440 ;; otherwise a clue that there's meant to be a picture
1441 (delete-region start
(point))
1442 (insert (or (cdr (assoc-string "text" parameter-alist
))
1443 (cdr (assoc-string "alt" parameter-alist
))
1445 (concat "[image:" src
"]"))
1447 (set-buffer-modified-p nil
)))
1449 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1450 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1451 ;; including one optional trailing newline.
1452 (defun Info-hide-cookies-node ()
1453 "Hide unrecognized cookies in current node."
1455 (let ((inhibit-read-only t
)
1456 (case-fold-search t
))
1457 (goto-char (point-min))
1458 (while (re-search-forward
1459 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1461 (let* ((start (match-beginning 1)))
1462 (if (and (not (get-text-property start
'invisible
))
1463 (not (get-text-property start
'display
)))
1464 (put-text-property start
(point) 'invisible t
)))))
1465 (set-buffer-modified-p nil
)))
1467 (defun Info-select-node ()
1468 "Select the Info node that point is in."
1469 ;; Bind this in case the user sets it to nil.
1470 (let ((case-fold-search t
))
1472 ;; Find beginning of node.
1473 (if (search-backward "\n\^_" nil
'move
)
1475 (if (looking-at "\^_")
1477 (signal 'search-failed
(list "\n\^_"))))
1478 ;; Get nodename spelled as it is in the node.
1479 (re-search-forward "Node:[ \t]*")
1480 (setq Info-current-node
1481 (buffer-substring-no-properties (point)
1483 (skip-chars-forward "^,\t\n")
1485 (Info-set-mode-line)
1486 ;; Find the end of it, and narrow.
1488 (let (active-expression)
1489 ;; Narrow to the node contents
1490 (narrow-to-region (point)
1491 (if (re-search-forward "\n[\^_\f]" nil t
)
1494 (if (looking-at "[\n\^_\f]*execute: ")
1496 (goto-char (match-end 0))
1497 (setq active-expression
1498 (read (current-buffer))))))
1500 (if Info-enable-active-nodes
(eval active-expression
))
1501 ;; Add a new unique history item to full history list
1502 (let ((new-history (list Info-current-file Info-current-node
)))
1503 (setq Info-history-list
1504 (cons new-history
(delete new-history Info-history-list
)))
1505 (setq Info-history-forward nil
))
1506 (if (not (eq Info-fontify-maximum-menu-size nil
))
1507 (Info-fontify-node))
1508 (Info-display-images-node)
1509 (Info-hide-cookies-node)
1510 (run-hooks 'Info-selection-hook
)))))
1512 (defvar Info-mode-line-node-keymap
1513 (let ((map (make-sparse-keymap)))
1514 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1515 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1517 "Keymap to put on the Info node name in the mode line.")
1519 (defun Info-set-mode-line ()
1520 (setq mode-line-buffer-identification
1521 (nconc (propertized-buffer-identification "%b")
1525 (if (stringp Info-current-file
)
1526 (replace-regexp-in-string
1527 "%" "%%" (file-name-nondirectory Info-current-file
))
1528 (format "*%S*" Info-current-file
))
1530 (if Info-current-node
1531 (propertize (replace-regexp-in-string
1532 "%" "%%" Info-current-node
)
1533 'face
'mode-line-buffer-id
1535 "mouse-1: scroll forward, mouse-3: scroll back"
1536 'mouse-face
'mode-line-highlight
1537 'local-map Info-mode-line-node-keymap
)
1540 ;; Go to an Info node specified with a filename-and-nodename string
1541 ;; of the sort that is found in pointers in nodes.
1543 ;; Don't autoload this function: the correct entry point for other packages
1544 ;; to use is `info'. --Stef
1546 (defun Info-goto-node (nodename &optional fork
)
1547 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1548 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1549 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1551 Completion is available, but only for node names in the current Info file.
1552 If FORK is non-nil (interactively with a prefix arg), show the node in
1554 If FORK is a string, it is the name to use for the new buffer."
1555 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1559 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1561 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1563 (setq filename
(if (= (match-beginning 1) (match-end 1))
1565 (match-string 2 nodename
))
1566 nodename
(match-string 3 nodename
))
1567 (let ((trim (string-match "\\s +\\'" filename
)))
1568 (if trim
(setq filename
(substring filename
0 trim
))))
1569 (let ((trim (string-match "\\s +\\'" nodename
)))
1570 (if trim
(setq nodename
(substring nodename
0 trim
))))
1571 (if transient-mark-mode
(deactivate-mark))
1572 (Info-find-node (if (equal filename
"") nil filename
)
1573 (if (equal nodename
"") "Top" nodename
))))
1575 (defvar Info-read-node-completion-table
)
1577 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1578 "Virtual completion table for file names input in Info node names.
1579 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1580 (setq suffixes
(remove "" suffixes
))
1581 (when (file-name-absolute-p string
)
1582 (setq dirs
(list (file-name-directory string
))))
1584 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1585 (string-dir (file-name-directory string
)))
1588 (setq dir default-directory
))
1589 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1590 (when (file-directory-p dir
)
1591 (dolist (file (file-name-all-completions
1592 (file-name-nondirectory string
) dir
))
1593 ;; If the file name has no suffix or a standard suffix,
1595 (and (or (null (file-name-extension file
))
1596 (string-match suffix file
))
1597 ;; But exclude subfiles of split Info files.
1598 (not (string-match "-[0-9]+\\'" file
))
1599 ;; And exclude backup files.
1600 (not (string-match "~\\'" file
))
1601 (push (if string-dir
(concat string-dir file
) file
) names
))
1602 ;; If the file name ends in a standard suffix,
1603 ;; add the unsuffixed name as a completion option.
1604 (when (string-match suffix file
)
1605 (setq file
(substring file
0 (match-beginning 0)))
1606 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1607 (complete-with-action action names string pred
)))
1609 ;; This function is used as the "completion table" while reading a node name.
1610 ;; It does completion using the alist in Info-read-node-completion-table
1611 ;; unless STRING starts with an open-paren.
1612 (defun Info-read-node-name-1 (string predicate code
)
1614 ;; First complete embedded file names.
1615 ((string-match "\\`([^)]*\\'" string
)
1616 (completion-table-with-context
1618 (apply-partially 'completion-table-with-terminator
")"
1619 (apply-partially 'Info-read-node-name-2
1621 (mapcar 'car Info-suffix-list
)))
1622 (substring string
1)
1626 ;; If a file name was given, then any node is fair game.
1627 ((string-match "\\`(" string
)
1629 ((eq code nil
) string
)
1632 ;; Otherwise use Info-read-node-completion-table.
1633 (t (complete-with-action
1634 code Info-read-node-completion-table string predicate
))))
1636 ;; Arrange to highlight the proper letters in the completion list buffer.
1639 (defun Info-read-node-name (prompt)
1640 (let* ((completion-ignore-case t
)
1641 (Info-read-node-completion-table (Info-build-node-completions))
1642 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1643 (if (equal nodename
"")
1644 (Info-read-node-name prompt
)
1647 (defun Info-build-node-completions ()
1648 (or Info-current-file-completions
1650 ;; Bind this in case the user sets it to nil.
1651 (case-fold-search t
)
1652 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1655 (or Info-tag-table-marker
1656 (error "No Info tags found"))
1657 (if (marker-buffer Info-tag-table-marker
)
1658 (let ((marker Info-tag-table-marker
))
1659 (set-buffer (marker-buffer marker
))
1662 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1664 (cons (list (match-string-no-properties 2))
1667 (goto-char (point-min))
1668 ;; If the buffer begins with a node header, process that first.
1669 (if (Info-node-at-bob-matching node-regexp
)
1670 (setq compl
(list (match-string-no-properties 1))))
1671 ;; Now for the rest of the nodes.
1672 (while (search-forward "\n\^_" nil t
)
1674 (let ((beg (point)))
1676 (if (re-search-backward node-regexp beg t
)
1678 (cons (list (match-string-no-properties 1))
1680 (setq compl
(cons '("*") compl
))
1681 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1683 (defun Info-restore-point (hl)
1684 "If this node has been visited, restore the point value when we left."
1686 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1687 ;; Use string-equal, not equal, to ignore text props.
1688 (string-equal (nth 1 (car hl
)) Info-current-node
))
1690 (goto-char (nth 2 (car hl
)))
1691 (setq hl nil
)) ;terminate the while at next iter
1692 (setq hl
(cdr hl
)))))
1694 (defvar Info-search-history nil
1695 "The history list for `Info-search'.")
1697 (defvar Info-search-case-fold nil
1698 "The value of `case-fold-search' from previous `Info-search' command.")
1700 (defun Info-search (regexp &optional bound noerror count direction
)
1701 "Search for REGEXP, starting from point, and select node it's found in.
1702 If DIRECTION is `backward', search in the reverse direction."
1703 (interactive (list (read-string
1704 (if Info-search-history
1705 (format "Regexp search%s (default %s): "
1706 (if case-fold-search
"" " case-sensitively")
1707 (car Info-search-history
))
1708 (format "Regexp search%s: "
1709 (if case-fold-search
"" " case-sensitively")))
1710 nil
'Info-search-history
)))
1712 (when (equal regexp
"")
1713 (setq regexp
(car Info-search-history
)))
1715 (let (found beg-found give-up
1716 (backward (eq direction
'backward
))
1717 (onode Info-current-node
)
1718 (ofile Info-current-file
)
1720 (opoint-min (point-min))
1721 (opoint-max (point-max))
1722 (ostart (window-start))
1723 (osubfile Info-current-subfile
))
1724 (setq Info-search-case-fold case-fold-search
)
1729 ;; Hide Info file header for backward search
1730 (narrow-to-region (save-excursion
1731 (goto-char (point-min))
1732 (search-forward "\n\^_")
1735 (while (and (not give-up
)
1737 (not (funcall isearch-filter-predicate beg-found found
))))
1738 (let ((search-spaces-regexp
1739 (if (or (not isearch-mode
) isearch-regexp
)
1740 Info-search-whitespace-regexp
)))
1742 (re-search-backward regexp bound t
)
1743 (re-search-forward regexp bound t
))
1744 (setq found
(point) beg-found
(if backward
(match-end 0)
1745 (match-beginning 0)))
1746 (setq give-up t
))))))
1748 (when (and isearch-mode Info-isearch-search
1749 (not Info-isearch-initial-node
)
1751 (or give-up
(and found
(not (and (> found opoint-min
)
1752 (< found opoint-max
))))))
1753 (signal 'search-failed
(list regexp
"initial node")))
1755 ;; If no subfiles, give error now.
1757 (if (null Info-current-subfile
)
1758 (let ((search-spaces-regexp
1759 (if (or (not isearch-mode
) isearch-regexp
)
1760 Info-search-whitespace-regexp
)))
1762 (re-search-backward regexp
)
1763 (re-search-forward regexp
)))
1766 (if (and bound
(not found
))
1767 (signal 'search-failed
(list regexp
)))
1769 (unless (or found bound
)
1771 ;; Try other subfiles.
1773 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1774 (goto-char (point-min))
1775 (search-forward "\n\^_\nIndirect:")
1777 (narrow-to-region (point)
1778 (progn (search-forward "\n\^_")
1780 (goto-char (point-min))
1781 ;; Find the subfile we just searched.
1782 (search-forward (concat "\n" osubfile
": "))
1784 (forward-line (if backward
0 1))
1785 (if backward
(forward-char -
1))
1786 ;; Make a list of all following subfiles.
1787 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1788 (while (not (if backward
(bobp) (eobp)))
1790 (re-search-backward "\\(^.*\\): [0-9]+$")
1791 (re-search-forward "\\(^.*\\): [0-9]+$"))
1792 (goto-char (+ (match-end 1) 2))
1793 (setq list
(cons (cons (+ (point-min)
1794 (read (current-buffer)))
1795 (match-string-no-properties 1))
1797 (goto-char (if backward
1798 (1- (match-beginning 0))
1799 (1+ (match-end 0)))))
1800 ;; Put in forward order
1801 (setq list
(nreverse list
))))
1803 (message "Searching subfile %s..." (cdr (car list
)))
1804 (Info-read-subfile (car (car list
)))
1806 ;; Hide Info file header for backward search
1807 (narrow-to-region (save-excursion
1808 (goto-char (point-min))
1809 (search-forward "\n\^_")
1812 (goto-char (point-max)))
1813 (setq list
(cdr list
))
1814 (setq give-up nil found nil
)
1815 (while (and (not give-up
)
1817 (not (funcall isearch-filter-predicate beg-found found
))))
1818 (let ((search-spaces-regexp
1819 (if (or (not isearch-mode
) isearch-regexp
)
1820 Info-search-whitespace-regexp
)))
1822 (re-search-backward regexp nil t
)
1823 (re-search-forward regexp nil t
))
1824 (setq found
(point) beg-found
(if backward
(match-end 0)
1825 (match-beginning 0)))
1833 (signal 'search-failed
(list regexp
))))
1835 (progn (Info-read-subfile osubfile
)
1838 (set-window-start (selected-window) ostart
)))))
1840 (if (and (string= osubfile Info-current-subfile
)
1841 (> found opoint-min
)
1842 (< found opoint-max
))
1843 ;; Search landed in the same node
1847 (save-match-data (Info-select-node)))
1849 ;; Use string-equal, not equal, to ignore text props.
1850 (or (and (string-equal onode Info-current-node
)
1851 (equal ofile Info-current-file
))
1852 (and isearch-mode isearch-wrapped
1853 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1854 (setq Info-history
(cons (list ofile onode opoint
)
1857 (defun Info-search-case-sensitively ()
1858 "Search for a regexp case-sensitively."
1860 (let ((case-fold-search nil
))
1861 (call-interactively 'Info-search
)))
1863 (defun Info-search-next ()
1864 "Search for next regexp from a previous `Info-search' command."
1866 (let ((case-fold-search Info-search-case-fold
))
1867 (if Info-search-history
1868 (Info-search (car Info-search-history
))
1869 (call-interactively 'Info-search
))))
1871 (defun Info-search-backward (regexp &optional bound noerror count
)
1872 "Search for REGEXP in the reverse direction."
1873 (interactive (list (read-string
1874 (if Info-search-history
1875 (format "Regexp search%s backward (default %s): "
1876 (if case-fold-search
"" " case-sensitively")
1877 (car Info-search-history
))
1878 (format "Regexp search%s backward: "
1879 (if case-fold-search
"" " case-sensitively")))
1880 nil
'Info-search-history
)))
1881 (Info-search regexp bound noerror count
'backward
))
1883 (defun Info-isearch-search ()
1884 (if Info-isearch-search
1885 (lambda (string &optional bound noerror count
)
1887 (Info-search (concat "\\b" (replace-regexp-in-string
1889 (replace-regexp-in-string
1890 "^\\W+\\|\\W+$" "" string
)
1892 ;; Lax version of word search
1893 (if (or isearch-nonincremental
1895 (length (isearch-string-state
1896 (car isearch-cmds
)))))
1899 (unless isearch-forward
'backward
))
1900 (Info-search (if isearch-regexp string
(regexp-quote string
))
1902 (unless isearch-forward
'backward
)))
1904 (let ((isearch-search-fun-function nil
))
1905 (isearch-search-fun))))
1907 (defun Info-isearch-wrap ()
1908 (if Info-isearch-search
1909 (if Info-isearch-initial-node
1911 (if isearch-forward
(Info-top-node) (Info-final-node))
1912 (goto-char (if isearch-forward
(point-min) (point-max))))
1913 (setq Info-isearch-initial-node Info-current-node
)
1914 (setq isearch-wrapped nil
))
1915 (goto-char (if isearch-forward
(point-min) (point-max)))))
1917 (defun Info-isearch-push-state ()
1919 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
1921 (defun Info-isearch-pop-state (cmd file node
)
1922 (or (and (equal Info-current-file file
)
1923 (equal Info-current-node node
))
1924 (progn (Info-find-node file node
) (sit-for 0))))
1926 (defun Info-isearch-start ()
1927 (setq Info-isearch-initial-node
1928 ;; Don't stop at initial node for nonincremental search.
1929 ;; Otherwise this variable is set after first search failure.
1930 (and isearch-nonincremental Info-current-node
))
1931 (setq Info-isearch-initial-history Info-history
1932 Info-isearch-initial-history-list Info-history-list
)
1933 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
1935 (defun Info-isearch-end ()
1936 ;; Remove intermediate nodes (visited while searching)
1937 ;; from the history. Add only the last node (where Isearch ended).
1938 (if (> (length Info-history
)
1939 (length Info-isearch-initial-history
))
1941 (nthcdr (- (length Info-history
)
1942 (length Info-isearch-initial-history
)
1945 (if (> (length Info-history-list
)
1946 (length Info-isearch-initial-history-list
))
1947 (setq Info-history-list
1948 (cons (car Info-history-list
)
1949 Info-isearch-initial-history-list
)))
1950 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
1952 (defun Info-isearch-filter (beg-found found
)
1953 "Test whether the current search hit is a visible useful text.
1954 Return non-nil if the text from BEG-FOUND to FOUND is visible
1955 and is not in the header line or a tag table."
1957 (let ((backward (< found beg-found
)))
1960 (and (not (eq search-invisible t
))
1962 (or (text-property-not-all found beg-found
'invisible nil
)
1963 (text-property-not-all found beg-found
'display nil
))
1964 (or (text-property-not-all beg-found found
'invisible nil
)
1965 (text-property-not-all beg-found found
'display nil
))))
1966 ;; Skip node header line
1967 (and (save-excursion (forward-line -
1)
1969 (forward-line (if backward -
1 1)))
1970 ;; Skip Tag Table node
1972 (and (search-backward "\^_" nil t
)
1974 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1977 (defun Info-extract-pointer (name &optional errorname
)
1978 "Extract the value of the node-pointer named NAME.
1979 If there is none, use ERRORNAME in the error message;
1980 if ERRORNAME is nil, just return nil."
1981 ;; Bind this in case the user sets it to nil.
1982 (let ((case-fold-search t
))
1984 (goto-char (point-min))
1985 (let ((bound (point)))
1987 (cond ((re-search-backward
1988 (concat name
":" (Info-following-node-name-re)) bound t
)
1989 (match-string-no-properties 1))
1990 ((not (eq errorname t
))
1991 (error "Node has no %s"
1992 (capitalize (or errorname name
)))))))))
1994 (defun Info-following-node-name-re (&optional allowedchars
)
1995 "Return a regexp matching a node name.
1996 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1997 saying which chars may appear in the node name.
1998 Submatch 1 is the complete node name.
1999 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2000 Submatch 3 is the local part of the node name.
2001 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2002 (concat "[ \t]*" ;Skip leading space.
2003 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2004 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2005 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2006 "\\|\\)\\)")) ;Allow empty node names.
2008 ;;; For compatibility; other files have used this name.
2009 (defun Info-following-node-name ()
2010 (and (looking-at (Info-following-node-name-re))
2011 (match-string-no-properties 1)))
2014 "Go to the next node of this node."
2016 ;; In case another window is currently selected
2017 (save-window-excursion
2018 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*" 'same-window
))
2019 (Info-goto-node (Info-extract-pointer "next"))))
2022 "Go to the previous node of this node."
2024 ;; In case another window is currently selected
2025 (save-window-excursion
2026 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*" 'same-window
))
2027 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2029 (defun Info-up (&optional same-file
)
2030 "Go to the superior node of this node.
2031 If SAME-FILE is non-nil, do not move to a different Info file."
2033 ;; In case another window is currently selected
2034 (save-window-excursion
2035 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*" 'same-window
))
2036 (let ((old-node Info-current-node
)
2037 (old-file Info-current-file
)
2038 (node (Info-extract-pointer "up")) p
)
2040 (string-match "^(" node
)
2041 (error "Up node is in another Info file"))
2042 (Info-goto-node node
)
2044 (goto-char (point-min))
2045 (if (and (stringp old-file
)
2046 (search-forward "\n* Menu:" nil t
)
2048 (if (string-equal old-node
"Top")
2049 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2050 (concat "\n\\* +\\(" (regexp-quote old-node
)
2051 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2053 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2055 (Info-restore-point Info-history
)))))
2057 (defun Info-history-back ()
2058 "Go back in the history to the last node visited."
2061 (error "This is the first Info node you looked at"))
2062 (let ((history-forward
2063 (cons (list Info-current-file Info-current-node
(point))
2064 Info-history-forward
))
2065 filename nodename opoint
)
2066 (setq filename
(car (car Info-history
)))
2067 (setq nodename
(car (cdr (car Info-history
))))
2068 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2069 (setq Info-history
(cdr Info-history
))
2070 (Info-find-node filename nodename
)
2071 (setq Info-history
(cdr Info-history
))
2072 (setq Info-history-forward history-forward
)
2073 (goto-char opoint
)))
2075 (defalias 'Info-last
'Info-history-back
)
2077 (defun Info-history-forward ()
2078 "Go forward in the history of visited nodes."
2080 (or Info-history-forward
2081 (error "This is the last Info node you looked at"))
2082 (let ((history-forward (cdr Info-history-forward
))
2083 filename nodename opoint
)
2084 (setq filename
(car (car Info-history-forward
)))
2085 (setq nodename
(car (cdr (car Info-history-forward
))))
2086 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2087 (Info-find-node filename nodename
)
2088 (setq Info-history-forward history-forward
)
2089 (goto-char opoint
)))
2091 (add-to-list 'Info-virtual-files
2093 (toc-nodes . Info-directory-toc-nodes
)
2094 (find-file . Info-directory-find-file
)
2095 (find-node . Info-directory-find-node
)
2098 (defun Info-directory-toc-nodes (filename)
2099 "Directory-specific implementation of Info-directory-toc-nodes."
2101 ("Top" nil nil nil
)))
2103 (defun Info-directory-find-file (filename &optional noerror
)
2104 "Directory-specific implementation of Info-find-file."
2107 (defun Info-directory-find-node (filename nodename
&optional no-going-back
)
2108 "Directory-specific implementation of Info-find-node-2."
2112 (defun Info-directory ()
2113 "Go to the Info directory node."
2115 (Info-find-node "dir" "top"))
2117 (add-to-list 'Info-virtual-files
2118 '("\\`\\*History\\*\\'"
2119 (toc-nodes . Info-history-toc-nodes
)
2120 (find-file . Info-history-find-file
)
2121 (find-node . Info-history-find-node
)
2124 (defun Info-history-toc-nodes (filename)
2125 "History-specific implementation of Info-history-toc-nodes."
2127 ("Top" nil nil nil
)))
2129 (defun Info-history-find-file (filename &optional noerror
)
2130 "History-specific implementation of Info-find-file."
2133 (defun Info-history-find-node (filename nodename
&optional no-going-back
)
2134 "History-specific implementation of Info-find-node-2."
2135 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2136 (or filename Info-current-file
) nodename
))
2137 (insert "Recently Visited Nodes\n")
2138 (insert "**********************\n\n")
2139 (insert "* Menu:\n\n")
2140 (let ((hl (delete '("*History*" "Top") Info-history-list
)))
2142 (let ((file (nth 0 (car hl
)))
2143 (node (nth 1 (car hl
))))
2145 (insert "* " node
": ("
2146 (propertize (or (file-name-directory file
) "") 'invisible t
)
2147 (file-name-nondirectory file
)
2149 (setq hl
(cdr hl
)))))
2151 (defun Info-history ()
2152 "Go to a node with a menu of visited nodes."
2154 (Info-find-node "*History*" "Top")
2155 (Info-next-reference)
2156 (Info-next-reference))
2158 (add-to-list 'Info-virtual-nodes
2160 (find-node . Info-toc-find-node
)
2163 (defun Info-toc-find-node (filename nodename
&optional no-going-back
)
2164 "Toc-specific implementation of Info-find-node-2."
2165 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2166 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2167 (node-list (Info-toc-nodes curr-file
)))
2168 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2169 curr-file curr-node
))
2170 (insert "Table of Contents\n")
2171 (insert "*****************\n\n")
2172 (insert "*Note Top::\n")
2174 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2175 node-list
0 curr-file
)
2177 (let ((Info-hide-note-references 'hide
)
2178 (Info-fontify-visited-nodes nil
))
2179 (setq Info-current-file filename Info-current-node
"*TOC*")
2180 (goto-char (point-min))
2181 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2188 "Go to a node with table of contents of the current Info file.
2189 Table of contents is created from the tree structure of menus."
2191 (Info-find-node Info-current-file
"*TOC*")
2192 (let ((prev-node (nth 1 (car Info-history
))) p
)
2193 (goto-char (point-min))
2194 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2195 (setq p
(- p
(length prev-node
) 2)))
2196 (goto-char (or p
(point-min)))))
2198 (defun Info-toc-insert (nodes node-list level curr-file
)
2199 "Insert table of contents with references to nodes."
2200 (let ((section "Top"))
2202 (let ((node (assoc (car nodes
) node-list
)))
2203 (unless (member (nth 2 node
) (list nil section
))
2204 (insert (setq section
(nth 2 node
)) "\n"))
2205 (insert (make-string level ?
\t))
2206 (insert "*Note " (car nodes
) ":: \n")
2207 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2208 (setq nodes
(cdr nodes
))))))
2210 (defun Info-toc-build (file)
2211 "Build table of contents from menus of Info FILE and its subfiles."
2213 (let* ((file (and (stringp file
) (Info-find-file file
)))
2214 (default-directory (or (and (stringp file
)
2215 (file-name-directory file
))
2217 (main-file (and (stringp file
) file
))
2218 (sections '(("Top" "Top")))
2220 (while (or main-file subfiles
)
2221 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2223 (info-insert-file-contents (or main-file
(car subfiles
)))
2224 (goto-char (point-min))
2225 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2226 (search-forward "Node: " nil
'move
))
2227 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2228 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2230 (upnode (and (re-search-forward
2231 (concat "Up:" (Info-following-node-name-re))
2233 (match-string-no-properties 1)))
2236 (when (string-match "(" upnode
) (setq upnode nil
))
2237 (when (and (not (Info-index-node nodename file
))
2238 (re-search-forward "^\\* Menu:" bound t
))
2241 (setq bound
(or (and (equal nodename
"Top")
2244 "^[ \t-]*The Detailed Node Listing" nil t
)))
2246 (while (< (point) bound
)
2249 ((looking-at "^\\* +[^:]+:")
2252 (let ((menu-node-name (substring-no-properties
2253 (Info-extract-menu-node-name))))
2254 (setq menu-items
(cons menu-node-name menu-items
))
2255 (if (equal nodename
"Top")
2257 (cons (list menu-node-name section
) sections
)))))
2258 ;; Other non-empty strings in the Top node are section names
2259 ((and (equal nodename
"Top")
2260 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2261 (setq section
(match-string-no-properties 1))))
2263 (beginning-of-line)))
2264 (setq nodes
(cons (list nodename upnode
2265 (cadr (assoc nodename sections
))
2266 (nreverse menu-items
))
2271 (goto-char (point-min))
2272 (if (search-forward "\n\^_\nIndirect:" nil t
)
2273 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2274 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2275 (setq subfiles
(cons (match-string-no-properties 1)
2277 (setq subfiles
(nreverse subfiles
)
2279 (setq subfiles
(cdr subfiles
))))
2283 (defvar Info-toc-nodes nil
2284 "Alist of cached parent-children node information in visited Info files.
2285 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2286 where PARENT is the parent node extracted from the Up pointer,
2287 SECTION is the section name in the Top node where this node is placed,
2288 CHILDREN is a list of child nodes extracted from the node menu.")
2290 (defun Info-toc-nodes (filename)
2291 "Return a node list of Info FILENAME with parent-children information.
2292 This information is cached in the variable `Info-toc-nodes' with the help
2293 of the function `Info-toc-build'."
2296 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2299 (or filename
(setq filename Info-current-file
))
2300 (or (assoc filename Info-toc-nodes
)
2301 ;; Skip virtual Info files
2302 (and (or (not (stringp filename
))
2303 (Info-virtual-file-p filename
))
2304 (push (cons filename nil
) Info-toc-nodes
))
2305 ;; Scan the entire manual and cache the result in Info-toc-nodes
2306 (let ((nodes (Info-toc-build filename
)))
2307 (push (cons filename nodes
) Info-toc-nodes
)
2309 ;; If there is an error, still add nil to the cache
2310 (push (cons filename nil
) Info-toc-nodes
))
2311 (cdr (assoc filename Info-toc-nodes
)))))
2314 (defun Info-follow-reference (footnotename &optional fork
)
2315 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2316 FOOTNOTENAME may be an abbreviation of the reference name.
2317 If FORK is non-nil (interactively with a prefix arg), show the node in
2318 a new Info buffer. If FORK is a string, it is the name to use for the
2321 (let ((completion-ignore-case t
)
2322 (case-fold-search t
)
2323 completions default alt-default
(start-point (point)) str i bol eol
)
2325 ;; Store end and beginning of line.
2326 (setq eol
(line-end-position)
2327 bol
(line-beginning-position))
2328 (goto-char (point-min))
2329 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2330 (setq str
(match-string-no-properties 1))
2331 ;; See if this one should be the default.
2333 (<= (match-beginning 0) start-point
)
2334 (<= start-point
(point))
2336 ;; See if this one should be the alternate default.
2337 (and (null alt-default
)
2338 (and (<= bol
(match-beginning 0))
2340 (setq alt-default t
))
2342 (while (setq i
(string-match "[ \n\t]+" str i
))
2343 (setq str
(concat (substring str
0 i
) " "
2344 (substring str
(match-end 0))))
2346 ;; Record as a completion and perhaps as default.
2347 (if (eq default t
) (setq default str
))
2348 (if (eq alt-default t
) (setq alt-default str
))
2349 ;; Don't add this string if it's a duplicate.
2350 (or (assoc-string str completions t
)
2351 (push str completions
))))
2352 ;; If no good default was found, try an alternate.
2354 (setq default alt-default
))
2355 ;; If only one cross-reference found, then make it default.
2356 (if (eq (length completions
) 1)
2357 (setq default
(car completions
)))
2359 (let ((input (completing-read (if default
2361 "Follow reference named (default "
2363 "Follow reference named: ")
2364 completions nil t
)))
2365 (list (if (equal input
"")
2366 default input
) current-prefix-arg
))
2367 (error "No cross-references in this node"))))
2369 (unless footnotename
2370 (error "No reference was specified"))
2372 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2373 (case-fold-search t
))
2374 (while (setq i
(string-match " " str i
))
2375 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2378 ;; Move point to the beginning of reference if point is on reference
2379 (or (looking-at "\\*note[ \n\t]+")
2380 (and (looking-back "\\*note[ \n\t]+")
2381 (goto-char (match-beginning 0)))
2382 (if (and (save-excursion
2383 (goto-char (+ (point) 5)) ; skip a possible *note
2384 (re-search-backward "\\*note[ \n\t]+" nil t
)
2386 (<= (point) (match-end 0)))
2387 (goto-char (match-beginning 0))))
2388 ;; Go to the reference closest to point
2389 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2390 (+ (match-beginning 0) 5))))
2391 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2392 (+ (match-beginning 0) 5)))))
2393 (goto-char (cond ((and next-ref prev-ref
)
2394 (if (< (abs (- next-ref
(point)))
2395 (abs (- prev-ref
(point))))
2397 ((or next-ref prev-ref
))
2398 ((error "No cross-reference named %s" footnotename
))))
2399 (setq target
(Info-extract-menu-node-name t
))))
2400 (while (setq i
(string-match "[ \t\n]+" target i
))
2401 (setq target
(concat (substring target
0 i
) " "
2402 (substring target
(match-end 0))))
2404 (Info-goto-node target fork
)))
2406 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2407 ;; We allow newline because this is also used in Info-follow-reference,
2408 ;; where the xref name might be wrapped over two lines.
2409 "Regexp that matches a menu entry name upto but not including the colon.
2410 Because of ambiguities, this should be concatenated with something like
2411 `:' and `Info-following-node-name-re'.")
2413 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2414 (skip-chars-forward " \t\n")
2415 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2416 (Info-following-node-name-re
2418 (index-node "^,\t\n")
2419 (multi-line "^.,\t")
2423 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2426 (setq Info-point-loc
2427 (if (match-beginning 5)
2428 (string-to-number (match-string 5))
2429 (buffer-substring-no-properties
2430 (match-beginning 0) (1- (match-beginning 1)))))
2431 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2432 ;;; (setq Info-point-loc
2433 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2435 (replace-regexp-in-string
2437 (or (match-string-no-properties 2)
2438 ;; If the node name is the menu entry name (using `entry::').
2439 (buffer-substring-no-properties
2440 (match-beginning 0) (1- (match-beginning 1)))))))
2442 ;; No one calls this.
2443 ;;(defun Info-menu-item-sequence (list)
2445 ;; (Info-menu (car list))
2446 ;; (setq list (cdr list))))
2448 (defvar Info-complete-menu-buffer
)
2449 (defvar Info-complete-next-re nil
)
2450 (defvar Info-complete-nodes nil
)
2451 (defvar Info-complete-cache nil
)
2453 (defconst Info-node-spec-re
2454 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2455 "Regexp to match the text after a : until the terminating `.'.")
2457 (defun Info-complete-menu-item (string predicate action
)
2458 ;; This uses two dynamically bound variables:
2459 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2460 ;; is the menu of items we're trying to complete.
2461 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2462 ;; also look for menu items in subsequent nodes as long as those
2463 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2465 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2466 ;; also look for menu items in these nodes. This feature is currently
2467 ;; only used for completion in Info-index.
2469 ;; Note that `Info-complete-menu-buffer' could be current already,
2470 ;; so we want to save point.
2471 (with-current-buffer Info-complete-menu-buffer
2473 (let ((completion-ignore-case t
)
2474 (case-fold-search t
)
2475 (orignode Info-current-node
)
2477 (goto-char (point-min))
2478 (search-forward "\n* Menu:")
2480 ((eq (car-safe action
) 'boundaries
) nil
)
2481 ((eq action
'lambda
)
2483 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2485 (let ((pattern (concat "\n\\* +\\("
2486 (regexp-quote string
)
2487 Info-menu-entry-name-re
"\\):"
2490 (complete-nodes Info-complete-nodes
))
2492 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2493 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2494 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2495 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2496 (let ((prev (nth 3 Info-complete-cache
)))
2497 (eq t
(compare-strings string
0 (length prev
)
2499 ;; We can reuse the previous list.
2500 (setq completions
(nth 4 Info-complete-cache
))
2501 ;; The cache can't be used.
2504 (while (re-search-forward pattern nil t
)
2505 (push (match-string-no-properties 1)
2507 ;; Check subsequent nodes if applicable.
2508 (or (and Info-complete-next-re
2509 (setq nextnode
(Info-extract-pointer "next" t
))
2510 (string-match Info-complete-next-re nextnode
))
2512 (setq complete-nodes
(cdr complete-nodes
)
2513 nextnode
(car complete-nodes
)))))
2514 (Info-goto-node nextnode
))
2515 ;; Go back to the start node (for the next completion).
2516 (unless (equal Info-current-node orignode
)
2517 (Info-goto-node orignode
))
2518 ;; Update the cache.
2519 (set (make-local-variable 'Info-complete-cache
)
2520 (list Info-current-file Info-current-node
2521 Info-complete-next-re string completions
2522 Info-complete-nodes
)))
2523 (complete-with-action action completions string predicate
))))))))
2526 (defun Info-menu (menu-item &optional fork
)
2527 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2528 The menu item should one of those listed in the current node's menu.
2529 Completion is allowed, and the default menu item is the one point is on.
2530 If FORK is non-nil (interactively with a prefix arg), show the node in
2531 a new Info buffer. If FORK is a string, it is the name to use for the
2534 (let (;; If point is within a menu item, use that item as the default
2538 (case-fold-search t
))
2540 (goto-char (point-min))
2541 (if (not (search-forward "\n* menu:" nil t
))
2542 (error "No menu in this node"))
2548 (if (re-search-backward (concat "\n\\* +\\("
2549 Info-menu-entry-name-re
2551 (setq default
(match-string-no-properties 1))))))
2554 (setq item
(let ((completion-ignore-case t
)
2555 (Info-complete-menu-buffer (current-buffer)))
2556 (completing-read (if default
2557 (format "Menu item (default %s): "
2560 'Info-complete-menu-item nil t
)))
2561 ;; we rely on the fact that completing-read accepts an input
2562 ;; of "" even when the require-match argument is true and ""
2563 ;; is not a valid possibility
2564 (if (string= item
"")
2569 (list item current-prefix-arg
))))
2570 ;; there is a problem here in that if several menu items have the same
2571 ;; name you can only go to the node of the first with this command.
2572 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2574 (defun Info-extract-menu-item (menu-item)
2575 (setq menu-item
(regexp-quote menu-item
))
2576 (let ((case-fold-search t
))
2578 (let ((case-fold-search t
))
2579 (goto-char (point-min))
2580 (or (search-forward "\n* menu:" nil t
)
2581 (error "No menu in this node"))
2582 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2583 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2584 (error "No such item in menu"))
2587 (Info-extract-menu-node-name nil
(Info-index-node))))))
2589 ;; If COUNT is nil, use the last item in the menu.
2590 (defun Info-extract-menu-counting (count &optional no-detail
)
2591 (let ((case-fold-search t
))
2593 (let ((case-fold-search t
)
2594 (bound (when (and no-detail
2596 "^[ \t-]*The Detailed Node Listing" nil t
))
2597 (match-beginning 0))))
2598 (goto-char (point-min))
2599 (or (search-forward "\n* menu:" bound t
)
2600 (error "No menu in this node"))
2602 (or (search-forward "\n* " bound t count
)
2603 (error "Too few items in menu"))
2604 (while (search-forward "\n* " bound t
)
2606 (Info-extract-menu-node-name nil
(Info-index-node))))))
2608 (defun Info-nth-menu-item ()
2609 "Go to the node of the Nth menu item.
2610 N is the digit argument used to invoke this command."
2613 (Info-extract-menu-counting
2614 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2616 (defun Info-top-node ()
2617 "Go to the Top node of this file."
2619 (Info-goto-node "Top"))
2621 (defun Info-final-node ()
2622 "Go to the final node in this file."
2624 (Info-goto-node "Top")
2625 (let ((Info-history nil
)
2626 (case-fold-search t
))
2627 ;; Go to the last node in the menu of Top. But don't delve into
2628 ;; detailed node listings.
2629 (Info-goto-node (Info-extract-menu-counting nil t
))
2630 ;; If the last node in the menu is not last in pointer structure,
2631 ;; move forward (but not down- or upward - see bug#1116) until we
2632 ;; can't go any farther.
2633 (while (Info-forward-node t t t
) nil
)
2634 ;; Then keep moving down to last subnode, unless we reach an index.
2635 (while (and (not (Info-index-node))
2636 (save-excursion (search-forward "\n* Menu:" nil t
)))
2637 (Info-goto-node (Info-extract-menu-counting nil
)))))
2639 (defun Info-forward-node (&optional not-down not-up no-error
)
2640 "Go forward one node, considering all nodes as forming one sequence."
2642 (goto-char (point-min))
2644 (let ((case-fold-search t
))
2645 ;; three possibilities, in order of priority:
2646 ;; 1. next node is in a menu in this node (but not in an index)
2647 ;; 2. next node is next at same level
2648 ;; 3. next node is up and next
2649 (cond ((and (not not-down
)
2650 (save-excursion (search-forward "\n* menu:" nil t
))
2651 (not (Info-index-node)))
2652 (Info-goto-node (Info-extract-menu-counting 1))
2654 ((save-excursion (search-backward "next:" nil t
))
2658 (save-excursion (search-backward "up:" nil t
))
2659 ;; Use string-equal, not equal, to ignore text props.
2660 (not (string-equal (downcase (Info-extract-pointer "up"))
2662 (let ((old-node Info-current-node
))
2664 (let (Info-history success
)
2666 (setq success
(Info-forward-node t nil no-error
))
2667 (or success
(Info-goto-node old-node
))))))
2669 (t (error "No pointer forward from this node")))))
2671 (defun Info-backward-node ()
2672 "Go backward one node, considering all nodes as forming one sequence."
2674 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2675 (upnode (Info-extract-pointer "up" t
))
2676 (case-fold-search t
))
2677 (cond ((and upnode
(string-match "(" upnode
))
2678 (error "First node in file"))
2679 ((and upnode
(or (null prevnode
)
2680 ;; Use string-equal, not equal,
2681 ;; to ignore text properties.
2682 (string-equal (downcase prevnode
)
2683 (downcase upnode
))))
2686 ;; If we move back at the same level,
2687 ;; go down to find the last subnode*.
2690 (while (and (not (Info-index-node))
2691 (save-excursion (search-forward "\n* Menu:" nil t
)))
2692 (Info-goto-node (Info-extract-menu-counting nil
)))))
2694 (error "No pointer backward from this node")))))
2697 "Exit Info by selecting some other buffer."
2700 (save-buffers-kill-emacs)
2703 (defun Info-next-menu-item ()
2704 "Go to the node of the next menu item."
2706 ;; Bind this in case the user sets it to nil.
2707 (let* ((case-fold-search t
)
2711 (search-forward "\n* menu:" nil t
)
2712 (and (search-forward "\n* " nil t
)
2713 (Info-extract-menu-node-name)))))
2714 (if node
(Info-goto-node node
)
2715 (error "No more items in menu"))))
2717 (defun Info-last-menu-item ()
2718 "Go to the node of the previous menu item."
2722 ;; Bind this in case the user sets it to nil.
2723 (let* ((case-fold-search t
)
2724 (beg (save-excursion
2725 (and (search-backward "\n* menu:" nil t
)
2727 (or (and beg
(search-backward "\n* " beg t
))
2728 (error "No previous items in menu")))
2729 (Info-goto-node (save-excursion
2730 (goto-char (match-end 0))
2731 (Info-extract-menu-node-name)))))
2733 (defmacro Info-no-error
(&rest body
)
2734 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2736 (defun Info-next-preorder ()
2737 "Go to the next subnode or the next node, or go up a level."
2739 (cond ((Info-no-error (Info-next-menu-item)))
2740 ((Info-no-error (Info-next)))
2741 ((Info-no-error (Info-up t
))
2742 ;; Since we have already gone thru all the items in this menu,
2743 ;; go up to the end of this node.
2744 (goto-char (point-max))
2745 ;; Since logically we are done with the node with that menu,
2746 ;; move on from it. But don't add intermediate nodes
2747 ;; to the history on recursive calls.
2749 (Info-next-preorder)))
2751 (error "No more nodes"))))
2753 (defun Info-last-preorder ()
2754 "Go to the last node, popping up a level if there is none."
2756 (cond ((Info-no-error
2757 (Info-last-menu-item)
2758 ;; If we go down a menu item, go to the end of the node
2759 ;; so we can scroll back through it.
2760 (goto-char (point-max)))
2761 ;; Keep going down, as long as there are nested menu nodes.
2762 (while (Info-no-error
2763 (Info-last-menu-item)
2764 ;; If we go down a menu item, go to the end of the node
2765 ;; so we can scroll back through it.
2766 (goto-char (point-max))))
2768 ((and (Info-no-error (Info-extract-pointer "prev"))
2769 (not (equal (Info-extract-pointer "up")
2770 (Info-extract-pointer "prev"))))
2771 (Info-no-error (Info-prev))
2772 (goto-char (point-max))
2773 (while (Info-no-error
2774 (Info-last-menu-item)
2775 ;; If we go down a menu item, go to the end of the node
2776 ;; so we can scroll back through it.
2777 (goto-char (point-max))))
2779 ((Info-no-error (Info-up t
))
2780 (goto-char (point-min))
2781 (let ((case-fold-search t
))
2782 (or (search-forward "\n* Menu:" nil t
)
2783 (goto-char (point-max)))))
2784 (t (error "No previous nodes"))))
2786 (defun Info-scroll-up ()
2787 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2788 Once you scroll far enough in a node that its menu appears on the screen
2789 but after point, the next scroll moves into its first subnode, unless
2790 `Info-scroll-prefer-subnodes' is nil.
2792 When you scroll past the end of a node, that goes to the next node if
2793 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2794 if this node has no successor, it moves to the parent node's successor,
2795 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2796 the menu of a node, it moves to subnode indicated by the following menu
2797 item. (That case won't normally result from this command, but can happen
2801 (if (or (< (window-start) (point-min))
2802 (> (window-start) (point-max)))
2803 (set-window-start (selected-window) (point)))
2804 (let* ((case-fold-search t
)
2805 (virtual-end (save-excursion
2806 (goto-char (point-min))
2807 (if (and Info-scroll-prefer-subnodes
2808 (search-forward "\n* Menu:" nil t
))
2811 (if (or (< virtual-end
(window-start))
2812 (pos-visible-in-window-p virtual-end
))
2814 (Info-scroll-prefer-subnodes (Info-next-preorder))
2815 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2816 (t (Info-next-preorder)))
2819 (defun Info-mouse-scroll-up (e)
2820 "Scroll one screenful forward in Info, using the mouse.
2821 See `Info-scroll-up'."
2823 (save-selected-window
2825 (select-window (posn-window (event-start e
))))
2828 (defun Info-scroll-down ()
2829 "Scroll one screenful back in Info, considering all nodes as one sequence.
2830 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2831 is non-nil, this goes to its last subnode. When you scroll past the
2832 beginning of a node, that goes to the previous node or back up to the
2835 (if (or (< (window-start) (point-min))
2836 (> (window-start) (point-max)))
2837 (set-window-start (selected-window) (point)))
2838 (let* ((case-fold-search t
)
2839 (current-point (point))
2841 (and Info-scroll-prefer-subnodes
2843 (setq current-point
(line-beginning-position))
2844 (goto-char (point-min))
2845 (search-forward "\n* Menu:" current-point t
)))))
2847 (pos-visible-in-window-p (point-min) nil t
))
2848 (Info-last-preorder)
2851 (defun Info-mouse-scroll-down (e)
2852 "Scroll one screenful backward in Info, using the mouse.
2853 See `Info-scroll-down'."
2855 (save-selected-window
2857 (select-window (posn-window (event-start e
))))
2858 (Info-scroll-down)))
2860 (defun Info-next-reference (&optional recur
)
2861 "Move cursor to the next cross-reference or menu item in the node."
2863 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2865 (case-fold-search t
))
2866 (or (eobp) (forward-char 1))
2867 (or (re-search-forward pat nil t
)
2869 (goto-char (point-min))
2870 (or (re-search-forward pat nil t
)
2873 (error "No cross references in this node")))))
2874 (goto-char (or (match-beginning 1) (match-beginning 0)))
2875 (if (looking-at "\\* Menu:")
2877 (error "No cross references in this node")
2878 (Info-next-reference t
))
2879 (if (looking-at "^\\* ")
2880 (forward-char 2)))))
2882 (defun Info-prev-reference (&optional recur
)
2883 "Move cursor to the previous cross-reference or menu item in the node."
2885 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2887 (case-fold-search t
))
2888 (or (re-search-backward pat nil t
)
2890 (goto-char (point-max))
2891 (or (re-search-backward pat nil t
)
2894 (error "No cross references in this node")))))
2895 (goto-char (or (match-beginning 1) (match-beginning 0)))
2896 (if (looking-at "\\* Menu:")
2898 (error "No cross references in this node")
2899 (Info-prev-reference t
))
2900 (if (looking-at "^\\* ")
2901 (forward-char 2)))))
2903 (defvar Info-index-nodes nil
2904 "Alist of cached index node names of visited Info files.
2905 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2907 (defun Info-index-nodes (&optional file
)
2908 "Return a list of names of all index nodes in Info FILE.
2909 If FILE is omitted, it defaults to the current Info file.
2910 First look in a list of cached index node names. Then scan Info
2911 file and its subfiles for nodes with the index cookie. Then try
2912 to find index nodes starting from the first node in the top level
2913 menu whose name contains the word \"Index\", plus any immediately
2914 following nodes whose names also contain the word \"Index\"."
2915 (or file
(setq file Info-current-file
))
2916 (or (assoc file Info-index-nodes
)
2917 ;; Skip virtual Info files
2918 (and (or (not (stringp file
))
2919 (Info-virtual-file-p file
))
2920 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2921 (if (Info-file-supports-index-cookies file
)
2922 ;; Find nodes with index cookie
2923 (let* ((default-directory (or (and (stringp file
)
2924 (file-name-directory
2925 (setq file
(Info-find-file file
))))
2927 Info-history Info-history-list Info-fontify-maximum-menu-size
2928 (main-file file
) subfiles nodes
)
2931 (while (or main-file subfiles
)
2933 (info-insert-file-contents (or main-file
(car subfiles
)))
2934 (goto-char (point-min))
2935 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2937 (re-search-backward "^\^_")
2938 (search-forward "Node: ")
2939 (setq nodes
(cons (Info-following-node-name) nodes
))))
2942 (goto-char (point-min))
2943 (if (search-forward "\n\^_\nIndirect:" nil t
)
2944 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2945 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2946 (setq subfiles
(cons (match-string-no-properties 1)
2948 (setq subfiles
(nreverse subfiles
)
2950 (setq subfiles
(cdr subfiles
)))))
2953 (setq nodes
(nreverse nodes
)
2954 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2956 ;; Else find nodes with the word "Index" in the node name
2957 (let ((case-fold-search t
)
2958 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2963 (Info-find-node file
"Top")
2964 (when (and (search-forward "\n* menu:" nil t
)
2965 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2966 (goto-char (match-beginning 1))
2967 (setq nodes
(list (Info-extract-menu-node-name)))
2968 (Info-goto-node (car nodes
))
2969 (while (and (setq node
(Info-extract-pointer "next" t
))
2970 (string-match "\\<Index\\>" node
))
2972 (Info-goto-node node
))))
2975 (setq nodes
(nreverse nodes
)
2976 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2978 ;; If file has no index nodes, still add it to the cache
2979 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2980 (cdr (assoc file Info-index-nodes
)))
2982 (defun Info-index-node (&optional node file
)
2983 "Return non-nil value if NODE is an index node.
2984 If NODE is nil, check the current Info node.
2985 If FILE is nil, check the current Info file."
2986 (or file
(setq file Info-current-file
))
2987 (if (and (or (and node
(not (equal node Info-current-node
)))
2988 (assoc file Info-index-nodes
))
2989 (not Info-current-node-virtual
))
2990 (member (or node Info-current-node
) (Info-index-nodes file
))
2991 ;; Don't search all index nodes if request is only for the current node
2992 ;; and file is not in the cache of index nodes
2994 (if (Info-file-supports-index-cookies file
)
2996 (goto-char (+ (or (save-excursion
2997 (search-backward "\n\^_" nil t
))
2999 (search-forward "\0\b[index\0\b]"
3001 (search-forward "\n\^_" nil t
))
3003 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3005 (defun Info-goto-index ()
3006 "Go to the first index node."
3007 (let ((node (car (Info-index-nodes))))
3008 (or node
(error "No index"))
3009 (Info-goto-node node
)))
3012 (defun Info-index (topic)
3013 "Look up a string TOPIC in the index for this manual and go to that entry.
3014 If there are no exact matches to the specified topic, this chooses
3015 the first match which is a case-insensitive substring of a topic.
3016 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3017 Give an empty topic name to go to the Index node itself."
3020 (let ((completion-ignore-case t
)
3021 (Info-complete-menu-buffer (clone-buffer))
3022 (Info-complete-nodes (Info-index-nodes))
3023 (Info-history-list nil
))
3024 (if (equal Info-current-file
"dir")
3025 (error "The Info directory node has no index; use m to select a manual"))
3027 (with-current-buffer Info-complete-menu-buffer
3029 (completing-read "Index topic: " 'Info-complete-menu-item
))
3030 (kill-buffer Info-complete-menu-buffer
)))))
3031 (if (equal Info-current-file
"dir")
3032 (error "The Info directory node has no index; use m to select a manual"))
3033 ;; Strip leading colon in topic; index format does not allow them.
3034 (if (and (stringp topic
)
3035 (> (length topic
) 0)
3036 (= (aref topic
0) ?
:))
3037 (setq topic
(substring topic
1)))
3038 (let ((orignode Info-current-node
)
3039 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3040 (regexp-quote topic
)))
3041 node
(nodes (Info-index-nodes))
3042 (ohist-list Info-history-list
)
3043 (case-fold-search t
))
3045 (or (equal topic
"")
3048 ;; We bind Info-history to nil for internal node-switches so
3049 ;; that we don't put junk in the history. In the first
3050 ;; Info-goto-index call, above, we do update the history
3051 ;; because that is what the user's previous node choice into it.
3056 (goto-char (point-min))
3057 (while (re-search-forward pattern nil t
)
3058 (push (list (match-string-no-properties 1)
3059 (match-string-no-properties 2)
3061 (string-to-number (concat "0"
3064 (setq nodes
(cdr nodes
) node
(car nodes
)))
3065 (Info-goto-node node
))
3068 (Info-goto-node orignode
)
3069 (error "No `%s' in index" topic
)))
3070 ;; Here it is a feature that assoc is case-sensitive.
3071 (while (setq found
(assoc topic matches
))
3072 (setq exact
(cons found exact
)
3073 matches
(delq found matches
)))
3074 (setq Info-history-list ohist-list
)
3075 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3076 (Info-index-next 0)))))
3078 (defun Info-index-next (num)
3079 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3081 (or Info-index-alternatives
3082 (error "No previous `i' command"))
3084 (setq num
(+ num
(length Info-index-alternatives
))))
3086 (setq Info-index-alternatives
3087 (nconc (cdr Info-index-alternatives
)
3088 (list (car Info-index-alternatives
)))
3090 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3091 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3092 ;; Forward 2 lines less because `Info-find-node-2' initially
3093 ;; puts point to the 2nd line.
3094 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3095 (forward-line 3) ; don't search in headers
3096 (let ((name (car (car Info-index-alternatives
))))
3097 (Info-find-index-name name
)))
3098 (message "Found `%s' in %s. %s"
3099 (car (car Info-index-alternatives
))
3100 (nth 2 (car Info-index-alternatives
))
3101 (if (cdr Info-index-alternatives
)
3102 (format "(%s total; use `%s' for next)"
3103 (length Info-index-alternatives
)
3104 (key-description (where-is-internal
3105 'Info-index-next overriding-local-map
3109 (defun Info-find-index-name (name)
3110 "Move point to the place within the current node where NAME is defined."
3111 (let ((case-fold-search t
))
3112 (if (or (re-search-forward (format
3113 "[a-zA-Z]+: %s\\( \\|$\\)"
3114 (regexp-quote name
)) nil t
)
3115 ;; Find a function definition with a return type.
3116 (re-search-forward (format
3117 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3118 (regexp-quote name
)) nil t
)
3119 (search-forward (format "`%s'" name
) nil t
)
3120 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3122 (format "`%s'" (substring name
0 (match-beginning 1)))
3124 (search-forward name nil t
)
3125 ;; Try again without the " <1>" makeinfo can append
3126 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3127 (Info-find-index-name (match-string 1 name
))))
3128 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3129 (goto-char (point-min)))))
3131 (add-to-list 'Info-virtual-nodes
3132 '("\\`\\*Index.*\\*\\'"
3133 (find-node . Info-virtual-index-find-node
)
3137 (defvar Info-virtual-index-nodes nil
3138 "Alist of cached matched index search nodes.
3139 Each element is ((FILENAME . TOPIC) MATCHES) where
3140 FILENAME is the file name of the manual,
3141 TOPIC is the search string given as an argument to `Info-virtual-index',
3142 MATCHES is a list of index matches found by `Info-index'.")
3144 (defun Info-virtual-index-find-node (filename nodename
&optional no-going-back
)
3145 "Index-specific implementation of Info-find-node-2."
3146 ;; Generate Index-like menu of matches
3147 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3148 ;; Generate Index-like menu of matches
3149 (let* ((topic (match-string 1 nodename
))
3150 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3151 Info-virtual-index-nodes
))))
3152 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3153 (or filename Info-current-file
) nodename
))
3154 (insert "Info Virtual Index\n")
3155 (insert "******************\n\n")
3156 (insert "Index entries that match `" topic
"':\n\n")
3157 (insert "\0\b[index\0\b]\n")
3159 (insert "No matches found.\n")
3160 (insert "* Menu:\n\n")
3161 (dolist (entry matches
)
3162 (insert (format "* %-38s %s.%s\n"
3163 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3166 (format " (line %s)" (nth 3 entry
))
3168 ;; Else, Generate a list of previous search results
3169 (let ((nodes (reverse Info-virtual-index-nodes
)))
3170 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3171 (or filename Info-current-file
) nodename
))
3172 (insert "Info Virtual Index\n")
3173 (insert "******************\n\n")
3174 (insert "This is a list of search results produced by\n"
3175 "`Info-virtual-index' for the current manual.\n\n")
3176 (insert "* Menu:\n\n")
3177 (dolist (nodeinfo nodes
)
3178 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3180 (format "* %-20s %s.\n"
3181 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3182 (cdr (nth 0 nodeinfo
)))))))))
3184 (defun Info-virtual-index (topic)
3185 "Show a node with all lines in the index containing a string TOPIC.
3186 Like `Info-index' but displays a node with index search results.
3187 Give an empty topic name to go to the node with links to previous
3189 ;; `interactive' is a copy from `Info-index'
3192 (let ((completion-ignore-case t
)
3193 (Info-complete-menu-buffer (clone-buffer))
3194 (Info-complete-nodes (Info-index-nodes))
3195 (Info-history-list nil
))
3196 (if (equal Info-current-file
"dir")
3197 (error "The Info directory node has no index; use m to select a manual"))
3199 (with-current-buffer Info-complete-menu-buffer
3201 (completing-read "Index topic: " 'Info-complete-menu-item
))
3202 (kill-buffer Info-complete-menu-buffer
)))))
3203 (if (equal topic
"")
3204 (Info-find-node Info-current-file
"*Index*")
3205 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3206 (let ((orignode Info-current-node
)
3207 (ohist-list Info-history-list
)
3209 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3211 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3212 Info-virtual-index-nodes
)
3213 ;; Clean up unneccessary side-effects of `Info-index'.
3214 (setq Info-history-list ohist-list
)
3215 (Info-goto-node orignode
)
3217 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3219 (add-to-list 'Info-virtual-files
3220 '("\\`\\*Apropos\\*\\'"
3221 (toc-nodes . Info-apropos-toc-nodes
)
3222 (find-file . Info-apropos-find-file
)
3223 (find-node . Info-apropos-find-node
)
3227 (defvar Info-apropos-file
"*Apropos*"
3228 "Info file name of the virtual manual for matches of `info-apropos'.")
3230 (defvar Info-apropos-nodes nil
3231 "Alist of cached apropos matched nodes.
3232 Each element is (NODENAME STRING MATCHES) where
3233 NODENAME is the name of the node that holds the search result,
3234 STRING is the search string given as an argument to `info-apropos',
3235 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3237 (defun Info-apropos-toc-nodes (filename)
3238 "Apropos-specific implementation of Info-apropos-toc-nodes."
3239 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3241 ("Top" nil nil
,nodes
)
3242 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3244 (defun Info-apropos-find-file (filename &optional noerror
)
3245 "Apropos-specific implementation of Info-find-file."
3248 (defun Info-apropos-find-node (filename nodename
&optional no-going-back
)
3249 "Apropos-specific implementation of Info-find-node-2."
3250 (if (equal nodename
"Top")
3251 ;; Generate Top menu
3252 (let ((nodes (reverse Info-apropos-nodes
)))
3253 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3254 Info-apropos-file nodename
))
3255 (insert "Apropos Index\n")
3256 (insert "*************\n\n")
3257 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3258 (insert "* Menu:\n\n")
3259 (dolist (nodeinfo nodes
)
3260 (insert (format "* %-20s %s.\n"
3261 (format "%s::" (nth 0 nodeinfo
))
3262 (nth 1 nodeinfo
)))))
3263 ;; Else, Generate Index-like menu of matches
3264 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3265 (matches (nth 2 nodeinfo
)))
3267 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3268 Info-apropos-file nodename
))
3269 (insert "Apropos Index\n")
3270 (insert "*************\n\n")
3271 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3272 (insert "\0\b[index\0\b]\n")
3274 (insert "No matches found.\n")
3275 (insert "* Menu:\n\n")
3276 (dolist (entry matches
)
3277 (insert (format "* %-38s (%s)%s.%s\n"
3278 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3282 (format " (line %s)" (nth 3 entry
))
3285 (defun Info-apropos-matches (string)
3286 "Collect STRING matches from all known Info files on your system.
3287 Return a list of matches where each element is in the format
3288 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3289 (interactive "sIndex apropos: ")
3290 (unless (string= string
"")
3291 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3292 (regexp-quote string
)))
3293 (ohist Info-history
)
3294 (ohist-list Info-history-list
)
3295 (current-node Info-current-node
)
3296 (current-file Info-current-file
)
3297 manuals matches node nodes
)
3298 (let ((Info-fontify-maximum-menu-size nil
))
3300 ;; current-node and current-file are nil when they invoke info-apropos
3301 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3302 ;; case, we use (DIR)Top instead, to avoid signalling an error after
3303 ;; the search is complete.
3304 (when (null current-node
)
3305 (setq current-file Info-current-file
)
3306 (setq current-node Info-current-node
))
3307 (message "Searching indices...")
3308 (goto-char (point-min))
3309 (re-search-forward "\\* Menu: *\n" nil t
)
3310 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3311 ;; add-to-list makes sure we don't have duplicates in `manuals',
3312 ;; so that the following dolist loop runs faster.
3313 (add-to-list 'manuals
(match-string 1)))
3314 (dolist (manual (nreverse manuals
))
3315 (message "Searching %s" manual
)
3317 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3319 (Info-find-node manual
(car nodes
))
3322 (goto-char (point-min))
3323 (while (re-search-forward pattern nil t
)
3326 (match-string-no-properties 1)
3327 (match-string-no-properties 2)
3328 (match-string-no-properties 3))
3330 (setq nodes
(cdr nodes
) node
(car nodes
)))
3331 (Info-goto-node node
))))
3333 (message "%s" (if (eq (car-safe err
) 'error
)
3336 (Info-find-node current-file current-node
)
3337 (setq Info-history ohist
3338 Info-history-list ohist-list
)
3339 (message "Searching indices...done")
3340 (or (nreverse matches
) t
))))
3343 (defun info-apropos (string)
3344 "Grovel indices of all known Info files on your system for STRING.
3345 Build a menu of the possible matches."
3346 (interactive "sIndex apropos: ")
3347 (if (equal string
"")
3348 (Info-find-node Info-apropos-file
"Top")
3349 (let* ((nodes Info-apropos-nodes
) nodename
)
3350 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3351 (setq nodes
(cdr nodes
)))
3353 (Info-find-node Info-apropos-file
(car (car nodes
)))
3354 (setq nodename
(format "Index for `%s'" string
))
3355 (push (list nodename string
(Info-apropos-matches string
))
3357 (Info-find-node Info-apropos-file nodename
)))))
3359 (add-to-list 'Info-virtual-files
3360 '("\\`\\*Finder.*\\*\\'"
3361 (find-file . Info-finder-find-file
)
3362 (find-node . Info-finder-find-node
)
3365 (defvar Info-finder-file
"*Finder*"
3366 "Info file name of the virtual Info keyword finder manual.")
3368 (defun Info-finder-find-file (filename &optional noerror
)
3369 "Finder-specific implementation of Info-find-file."
3372 (defvar finder-known-keywords
)
3373 (declare-function find-library-name
"find-func" (library))
3374 (declare-function finder-unknown-keywords
"finder" ())
3375 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3376 (defvar finder-keywords-hash
)
3377 (defvar package-alist
) ; finder requires package
3379 (defun Info-finder-find-node (filename nodename
&optional no-going-back
)
3380 "Finder-specific implementation of Info-find-node-2."
3383 ((equal nodename
"Top")
3384 ;; Display Top menu with descriptions of the keywords
3385 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3386 Info-finder-file nodename
))
3387 (insert "Finder Keywords\n")
3388 (insert "***************\n\n")
3389 (insert "* Menu:\n\n")
3390 (dolist (assoc (append '((all .
"All package info")
3391 (unknown .
"unknown keywords"))
3392 finder-known-keywords
))
3393 (let ((keyword (car assoc
)))
3394 (insert (format "* %s %s.\n"
3395 (concat (symbol-name keyword
) ": "
3396 "kw:" (symbol-name keyword
) ".")
3398 ((equal nodename
"unknown")
3399 ;; Display unknown keywords
3400 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3401 Info-finder-file nodename
))
3402 (insert "Finder Unknown Keywords\n")
3403 (insert "***********************\n\n")
3404 (insert "* Menu:\n\n")
3407 (insert (format "* %-14s %s.\n"
3408 (concat (symbol-name (car assoc
)) "::")
3410 (finder-unknown-keywords)))
3411 ((equal nodename
"all")
3412 ;; Display all package info.
3413 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3414 Info-finder-file nodename
))
3415 (insert "Finder Package Info\n")
3416 (insert "*******************\n\n")
3417 (dolist (package package-alist
)
3418 (insert (format "%s - %s\n"
3419 (format "*Note %s::" (nth 0 package
))
3421 ((string-match "\\`kw:" nodename
)
3422 (setq nodename
(substring nodename
(match-end 0)))
3423 ;; Display packages that match the keyword
3424 ;; or the list of keywords separated by comma.
3425 (insert (format "\n\^_\nFile: %s, Node: kw:%s, Up: Top\n\n"
3426 Info-finder-file nodename
))
3427 (insert "Finder Packages\n")
3428 (insert "***************\n\n")
3430 "The following packages match the keyword `" nodename
"':\n\n")
3431 (insert "* Menu:\n\n")
3433 (mapcar 'intern
(if (string-match-p "," nodename
)
3434 (split-string nodename
",[ \t\n]*" t
)
3437 (dolist (kw keywords
)
3438 (push (copy-tree (gethash kw finder-keywords-hash
)) hits
))
3439 (setq hits
(delete-dups (apply 'append hits
)))
3440 (dolist (package hits
)
3441 (setq desc
(cdr-safe (assq package package-alist
)))
3442 (when (vectorp desc
)
3443 (insert (format "* %-16s %s.\n"
3444 (concat (symbol-name package
) "::")
3447 ;; Display commentary section
3448 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3449 Info-finder-file nodename
))
3450 (insert "Finder Commentary\n")
3451 (insert "*****************\n\n")
3453 "Commentary section of the package `" nodename
"':\n\n")
3454 (let ((str (lm-commentary (find-library-name nodename
))))
3456 (insert "Can't find any Commentary section\n\n")
3460 (goto-char (point-min))
3461 (delete-blank-lines)
3462 (goto-char (point-max))
3463 (delete-blank-lines)
3464 (goto-char (point-min))
3465 (while (re-search-forward "^;+ ?" nil t
)
3466 (replace-match "" nil nil
))
3467 (buffer-string))))))))
3470 (defun info-finder (&optional keywords
)
3471 "Display descriptions of the keywords in the Finder virtual manual.
3472 In interactive use, a prefix argument directs this command to read
3473 a list of keywords separated by comma. After that, it displays a node
3474 with a list packages that contain all specified keywords."
3476 (when current-prefix-arg
3479 (completing-read-multiple
3480 "Keywords (separated by comma): "
3481 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3482 (finder-unknown-keywords))))
3486 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3487 (Info-find-node Info-finder-file
"Top")))
3490 (defun Info-undefined ()
3491 "Make command be undefined in Info."
3496 "Enter the Info tutorial."
3498 (delete-other-windows)
3499 (Info-find-node "info"
3500 (if (< (window-height) 23)
3504 (defun Info-summary ()
3505 "Display a brief summary of all Info commands."
3507 (save-window-excursion
3508 (switch-to-buffer "*Help*")
3509 (setq buffer-read-only nil
)
3511 (insert (documentation 'Info-mode
))
3513 (goto-char (point-min))
3515 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3516 (message (if flag
"Type Space to see more"
3517 "Type Space to return to Info"))
3518 (if (not (eq ?\s
(setq ch
(read-event))))
3519 (progn (setq unread-command-events
(list ch
)) nil
)
3522 (bury-buffer "*Help*")))
3524 (defun Info-get-token (pos start all
&optional errorstring
)
3525 "Return the token around POS.
3526 POS must be somewhere inside the token
3527 START is a regular expression which will match the
3528 beginning of the tokens delimited string
3529 ALL is a regular expression with a single
3530 parenthesized subpattern which is the token to be
3531 returned. E.g. '{\(.*\)}' would return any string
3532 enclosed in braces around POS.
3533 ERRORSTRING optional fourth argument, controls action on no match
3536 a string: signal an error, using that string."
3537 (let ((case-fold-search t
))
3540 ;; First look for a match for START that goes across POS.
3541 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3542 (not (looking-at start
)))
3544 ;; If we did not find one, search back for START
3545 ;; (this finds only matches that end at or before POS).
3546 (or (looking-at start
)
3549 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3551 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3552 (not (setq found
(and (<= (match-beginning 0) pos
)
3553 (> (match-end 0) pos
))))))
3554 (if (and found
(<= (match-beginning 0) pos
)
3555 (> (match-end 0) pos
))
3556 (match-string-no-properties 1)
3557 (cond ((null errorstring
)
3563 (error "No %s around position %d" errorstring pos
))))))))
3565 (defun Info-mouse-follow-nearest-node (click)
3566 "\\<Info-mode-map>Follow a node reference near point.
3567 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3568 At end of the node's text, moves to the next node, or up if none."
3570 (mouse-set-point click
)
3571 (and (not (Info-follow-nearest-node))
3572 (save-excursion (forward-line 1) (eobp))
3573 (Info-next-preorder)))
3575 (defun Info-follow-nearest-node (&optional fork
)
3576 "Follow a node reference near point.
3577 If point is on a reference, follow that reference. Otherwise,
3578 if point is in a menu item description, follow that menu item.
3580 If FORK is non-nil (interactively with a prefix arg), show the node in
3582 If FORK is a string, it is the name to use for the new buffer."
3584 (or (Info-try-follow-nearest-node fork
)
3585 (when (save-excursion
3586 (search-backward "\n* menu:" nil t
))
3589 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3590 (beginning-of-line 0))
3591 (when (looking-at "\\* +\\([^\t\n]*\\):")
3593 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3595 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3596 ;; Don't raise an error when mouse-1 is bound to this - it's
3597 ;; often used to simply select the window or frame.
3598 (eq 'mouse-1
(event-basic-type last-input-event
)))
3599 (error "Point neither on reference nor in menu item description")))
3601 ;; Common subroutine.
3602 (defun Info-try-follow-nearest-node (&optional fork
)
3603 "Follow a node reference near point. Return non-nil if successful.
3604 If FORK is non-nil, it is passed to `Info-goto-node'."
3607 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3608 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3611 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3612 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3613 (Info-follow-reference node fork
))
3614 ;; menu item: node name
3615 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3616 (Info-goto-node node fork
))
3617 ;; menu item: node name or index entry
3618 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3621 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3622 (Info-goto-node node fork
))
3623 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3624 (Info-goto-node node fork
))
3625 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3626 (Info-goto-node node fork
))
3627 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3628 (Info-goto-node "Top" fork
))
3629 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3630 (Info-goto-node node fork
)))
3633 (defun Info-mouse-follow-link (click)
3634 "Follow a link where you click."
3636 (let* ((position (event-start click
))
3637 (posn-string (and position
(posn-string position
)))
3638 (string (car-safe posn-string
))
3639 (string-pos (cdr-safe posn-string
))
3640 (link-args (and string string-pos
3641 (get-text-property string-pos
'link-args string
))))
3643 (Info-goto-node link-args
))))
3646 (defvar Info-mode-map
3647 (let ((map (make-keymap)))
3648 (suppress-keymap map
)
3649 (define-key map
"." 'beginning-of-buffer
)
3650 (define-key map
" " 'Info-scroll-up
)
3651 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3652 (define-key map
"\t" 'Info-next-reference
)
3653 (define-key map
"\e\t" 'Info-prev-reference
)
3654 (define-key map
[(shift tab
)] 'Info-prev-reference
)
3655 (define-key map
[backtab] 'Info-prev-reference)
3656 (define-key map "1" 'Info-nth-menu-item)
3657 (define-key map "2" 'Info-nth-menu-item)
3658 (define-key map "3" 'Info-nth-menu-item)
3659 (define-key map "4" 'Info-nth-menu-item)
3660 (define-key map "5" 'Info-nth-menu-item)
3661 (define-key map "6" 'Info-nth-menu-item)
3662 (define-key map "7" 'Info-nth-menu-item)
3663 (define-key map "8" 'Info-nth-menu-item)
3664 (define-key map "9" 'Info-nth-menu-item)
3665 (define-key map "0" 'undefined)
3666 (define-key map "?" 'Info-summary)
3667 (define-key map "]" 'Info-forward-node)
3668 (define-key map "[" 'Info-backward-node)
3669 (define-key map "<" 'Info-top-node)
3670 (define-key map ">" 'Info-final-node)
3671 (define-key map "b" 'beginning-of-buffer)
3672 (define-key map "d" 'Info-directory)
3673 (define-key map "e" 'Info-edit)
3674 (define-key map "f" 'Info-follow-reference)
3675 (define-key map "g" 'Info-goto-node)
3676 (define-key map "h" 'Info-help)
3677 (define-key map "i" 'Info-index)
3678 (define-key map "I" 'Info-virtual-index)
3679 (define-key map "l" 'Info-history-back)
3680 (define-key map "L" 'Info-history)
3681 (define-key map "m" 'Info-menu)
3682 (define-key map "n" 'Info-next)
3683 (define-key map "p" 'Info-prev)
3684 (define-key map "q" 'Info-exit)
3685 (define-key map "r" 'Info-history-forward)
3686 (define-key map "s" 'Info-search)
3687 (define-key map "S" 'Info-search-case-sensitively)
3688 (define-key map "\M-n" 'clone-buffer)
3689 (define-key map "t" 'Info-top-node)
3690 (define-key map "T" 'Info-toc)
3691 (define-key map "u" 'Info-up)
3692 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3693 (define-key map "w" 'Info-copy-current-node-name)
3694 (define-key map "c" 'Info-copy-current-node-name)
3695 ;; `^' for consistency with `dired-up-directory'.
3696 (define-key map "^" 'Info-up)
3697 (define-key map "," 'Info-index-next)
3698 (define-key map "\177" 'Info-scroll-down)
3699 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3700 (define-key map [follow-link] 'mouse-face)
3702 "Keymap containing Info commands.")
3705 (defun Info-check-pointer (item)
3706 "Non-nil if ITEM is present in this node."
3708 (Info-extract-pointer item)
3712 Info-mode-menu Info-mode-map
3713 "Menu for Info files."
3715 ["Up" Info-up :active (Info-check-pointer "up")
3716 :help "Go up in the Info tree"]
3717 ["Next" Info-next :active (Info-check-pointer "next")
3718 :help "Go to the next node"]
3719 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3720 :help "Go to the previous node"]
3721 ["Backward" Info-backward-node
3722 :help "Go backward one node, considering all as a sequence"]
3723 ["Forward" Info-forward-node
3724 :help "Go forward one node, considering all as a sequence"]
3725 ["Beginning" beginning-of-buffer
3726 :help "Go to beginning of this node"]
3727 ["Top" Info-top-node
3728 :help "Go to top node of file"]
3729 ["Final Node" Info-final-node
3730 :help "Go to final node in this file"]
3731 ("Menu Item" ["You should never see this" report-emacs-bug t])
3732 ("Reference" ["You should never see this" report-emacs-bug t])
3733 ["Search..." Info-search
3734 :help "Search for regular expression in this Info file"]
3735 ["Search Next" Info-search-next
3736 :help "Search for another occurrence of regular expression"]
3737 ["Go to Node..." Info-goto-node
3738 :help "Go to a named node"]
3739 ["Back in history" Info-history-back :active Info-history
3740 :help "Go back in history to the last node you were at"]
3741 ["Forward in history" Info-history-forward :active Info-history-forward
3742 :help "Go forward in history"]
3743 ["History" Info-history :active Info-history-list
3744 :help "Go to menu of visited nodes"]
3745 ["Table of Contents" Info-toc
3746 :help "Go to table of contents"]
3748 ["Lookup a String..." Info-index
3749 :help "Look for a string in the index items"]
3750 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3751 :help "Look for another occurrence of previous item"]
3752 ["Lookup a string and display index of results..." Info-virtual-index
3753 :help "Look for a string in the index items and display node with results"]
3754 ["Lookup a string in all indices..." info-apropos
3755 :help "Look for a string in the indices of all manuals"])
3756 ["Copy Node Name" Info-copy-current-node-name
3757 :help "Copy the name of the current node into the kill ring"]
3758 ["Clone Info buffer" clone-buffer
3759 :help "Create a twin copy of the current Info buffer."]
3760 ["Exit" Info-exit :help "Stop reading Info"]))
3763 (defvar info-tool-bar-map
3764 (let ((map (make-sparse-keymap)))
3765 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3769 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3773 (define-key-after map [separator-1] menu-bar-separator)
3774 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3776 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3778 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
3780 (define-key-after map [separator-2] menu-bar-separator)
3781 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3782 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3783 (define-key-after map [separator-3] menu-bar-separator)
3784 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3785 :label "Index Search")
3786 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3787 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map)
3790 (defvar Info-menu-last-node nil)
3791 ;; Last node the menu was created for.
3792 ;; Value is a list, (FILE-NAME NODE-NAME).
3794 (defun Info-menu-update ()
3795 "Update the Info menu for the current node."
3797 (if (or (not (eq major-mode 'Info-mode))
3798 (equal (list Info-current-file Info-current-node)
3799 Info-menu-last-node))
3801 ;; Update menu menu.
3802 (let* ((Info-complete-menu-buffer (current-buffer))
3803 (items (nreverse (condition-case nil
3804 (Info-complete-menu-item "" nil t)
3808 (while (and items (< number 9))
3809 (setq current (car items)
3812 (setq entries (cons `[,current
3813 (Info-menu ,current)
3814 :keys ,(format "%d" number)]
3817 (setq entries (cons ["Other..." Info-menu t] entries)))
3819 (setq entries (list ["No menu" nil nil] nil :active)))
3820 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3821 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3823 str i entries current
3825 (case-fold-search t))
3827 (goto-char (point-min))
3828 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3829 (setq str (match-string 1))
3831 (while (setq i (string-match "[ \n\t]+" str i))
3832 (setq str (concat (substring str 0 i) " "
3833 (substring str (match-end 0))))
3837 (while (and items (< number 9))
3838 (setq current (car items)
3841 (setq entries (cons `[,current
3842 (Info-follow-reference ,current)
3846 (setq entries (cons ["Other..." Info-follow-reference t]
3849 (setq entries (list ["No references" nil nil] nil :active)))
3850 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3851 ;; Update last seen node.
3852 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3853 ;; Try to avoid entering infinite beep mode in case of errors.
3857 (defun Info-copy-current-node-name (&optional arg)
3858 "Put the name of the current Info node into the kill ring.
3859 The name of the Info file is prepended to the node name in parentheses.
3860 With a zero prefix arg, put the name inside a function call to `info'."
3862 (unless Info-current-node
3863 (error "No current Info node"))
3864 (let ((node (if (stringp Info-current-file)
3865 (concat "(" (file-name-nondirectory Info-current-file) ") "
3866 Info-current-node))))
3867 (if (zerop (prefix-numeric-value arg))
3868 (setq node (concat "(info \"" node "\")")))
3869 (unless (stringp Info-current-file)
3870 (setq node (format "(Info-find-node '%S '%S)"
3871 Info-current-file Info-current-node)))
3873 (message "%s" node)))
3876 ;; Info mode is suitable only for specially formatted data.
3877 (put 'Info-mode 'mode-class 'special)
3878 (put 'Info-mode 'no-clone-indirect t)
3880 (defvar tool-bar-map)
3881 (defvar bookmark-make-record-function)
3883 ;; Autoload cookie needed by desktop.el
3885 (define-derived-mode Info-mode nil "Info"
3886 "Info mode provides commands for browsing through the Info documentation tree.
3887 Documentation in Info is divided into \"nodes\", each of which discusses
3888 one topic and contains references to other nodes which discuss related
3889 topics. Info has commands to follow the references and show you other nodes.
3892 \\[Info-help] Invoke the Info tutorial.
3893 \\[Info-exit] Quit Info: reselect previously selected buffer.
3895 Selecting other nodes:
3896 \\[Info-mouse-follow-nearest-node]
3897 Follow a node reference you click on.
3898 This works with menu items, cross references, and
3899 the \"next\", \"previous\" and \"up\", depending on where you click.
3900 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3901 \\[Info-next] Move to the \"next\" node of this node.
3902 \\[Info-prev] Move to the \"previous\" node of this node.
3903 \\[Info-up] Move \"up\" from this node.
3904 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3905 Picking a menu item causes another node to be selected.
3906 \\[Info-directory] Go to the Info directory node.
3907 \\[Info-top-node] Go to the Top node of this file.
3908 \\[Info-final-node] Go to the final node in this file.
3909 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3910 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3911 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3912 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3913 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3914 \\[Info-history-back] Move back in history to the last node you were at.
3915 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3916 \\[Info-history] Go to menu of visited nodes.
3917 \\[Info-toc] Go to table of contents of the current Info file.
3919 Moving within a node:
3920 \\[Info-scroll-up] Normally, scroll forward a full screen.
3921 Once you scroll far enough in a node that its menu appears on the
3922 screen but after point, the next scroll moves into its first
3923 subnode. When after all menu items (or if there is no menu),
3924 move up to the parent node.
3925 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3926 already visible, try to go to the previous menu entry, or up
3928 \\[beginning-of-buffer] Go to beginning of node.
3931 \\[Info-search] Search through this Info file for specified regexp,
3932 and select the node in which the next occurrence is found.
3933 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3934 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3935 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3936 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3937 \\[Info-virtual-index] Look for a string and display the index node with results.
3938 \\[info-apropos] Look for a string in the indices of all manuals.
3939 \\[Info-goto-node] Move to node specified by name.
3940 You may include a filename as well, as (FILENAME)NODENAME.
3941 1 .. 9 Pick first ... ninth item in node's menu.
3942 Every third `*' is highlighted to help pick the right number.
3943 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3944 \\[clone-buffer] Select a new cloned Info buffer in another window.
3945 \\[universal-argument] \\[info] Move to new Info file with completion.
3946 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3947 :syntax-table text-mode-syntax-table
3948 :abbrev-table text-mode-abbrev-table
3950 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3951 (setq case-fold-search t)
3952 (setq buffer-read-only t)
3953 (make-local-variable 'Info-current-file)
3954 (make-local-variable 'Info-current-subfile)
3955 (make-local-variable 'Info-current-node)
3956 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
3957 (set (make-local-variable 'Info-tag-table-buffer) nil)
3958 (make-local-variable 'Info-history)
3959 (make-local-variable 'Info-history-forward)
3960 (make-local-variable 'Info-index-alternatives)
3961 (if Info-use-header-line ; do not override global header lines
3962 (setq header-line-format
3963 '(:eval (get-text-property (point-min) 'header-line))))
3964 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3965 ;; This is for the sake of the invisible text we use handling titles.
3966 (set (make-local-variable 'line-move-ignore-invisible) t)
3967 (set (make-local-variable 'desktop-save-buffer)
3968 'Info-desktop-buffer-misc-data)
3969 (set (make-local-variable 'widen-automatically) nil)
3970 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3971 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
3972 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3973 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3974 (set (make-local-variable 'isearch-search-fun-function)
3975 'Info-isearch-search)
3976 (set (make-local-variable 'isearch-wrap-function)
3978 (set (make-local-variable 'isearch-push-state-function)
3979 'Info-isearch-push-state)
3980 (set (make-local-variable 'isearch-filter-predicate)
3981 'Info-isearch-filter)
3982 (set (make-local-variable 'search-whitespace-regexp)
3983 Info-search-whitespace-regexp)
3984 (set (make-local-variable 'revert-buffer-function)
3985 'Info-revert-buffer-function)
3986 (Info-set-mode-line)
3987 (set (make-local-variable 'bookmark-make-record-function)
3988 'Info-bookmark-make-record))
3990 ;; When an Info buffer is killed, make sure the associated tags buffer
3992 (defun Info-kill-buffer ()
3993 (and (eq major-mode 'Info-mode)
3994 Info-tag-table-buffer
3995 (kill-buffer Info-tag-table-buffer)))
3997 ;; Placed on `clone-buffer-hook'.
3998 (defun Info-clone-buffer ()
3999 (when (bufferp Info-tag-table-buffer)
4000 (setq Info-tag-table-buffer
4001 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4002 (let ((m Info-tag-table-marker))
4004 (setq Info-tag-table-marker
4005 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4006 (with-current-buffer Info-tag-table-buffer
4007 (copy-marker (marker-position m)))
4010 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4011 (set-keymap-parent map text-mode-map)
4012 (define-key map "\C-c\C-c" 'Info-cease-edit)
4014 "Local keymap used within `e' command of Info.")
4016 ;; Info-edit mode is suitable only for specially formatted data.
4017 (put 'Info-edit-mode 'mode-class 'special)
4019 (defun Info-edit-mode ()
4020 "Major mode for editing the contents of an Info node.
4021 Like text mode with the addition of `Info-cease-edit'
4022 which returns to Info mode for browsing.
4024 (use-local-map Info-edit-map)
4025 (setq major-mode 'Info-edit-mode)
4026 (setq mode-name "Info Edit")
4027 (kill-local-variable 'mode-line-buffer-identification)
4028 (setq buffer-read-only nil)
4029 (force-mode-line-update)
4030 (buffer-enable-undo (current-buffer))
4031 (run-mode-hooks 'Info-edit-mode-hook))
4034 "Edit the contents of this Info node.
4035 Allowed only if variable `Info-enable-edit' is non-nil."
4037 (or Info-enable-edit
4038 (error "Editing Info nodes is not enabled"))
4040 (message "%s" (substitute-command-keys
4041 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4043 (defun Info-cease-edit ()
4044 "Finish editing Info node; switch back to Info proper."
4046 ;; Do this first, so nothing has changed if user C-g's at query.
4047 (and (buffer-modified-p)
4048 (y-or-n-p "Save the file? ")
4050 (use-local-map Info-mode-map)
4051 (setq major-mode 'Info-mode)
4052 (setq mode-name "Info")
4053 (Info-set-mode-line)
4054 (setq buffer-read-only t)
4055 (force-mode-line-update)
4056 (and (marker-position Info-tag-table-marker)
4058 (message "Tags may have changed. Use Info-tagify if necessary")))
4060 (defvar Info-file-list-for-emacs
4061 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4062 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4063 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4064 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4065 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4066 ("copyright" . "autotype") ("executable" . "autotype")
4067 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4068 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4069 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4070 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4071 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4072 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4073 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4074 ("rfc2045" . "emacs-mime")
4075 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4076 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4077 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4078 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4079 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4080 ("mml" . "emacs-mime"))
4081 "List of Info files that describe Emacs commands.
4082 An element can be a file name, or a list of the form (PREFIX . FILE)
4083 where PREFIX is a name prefix and FILE is the file to look in.
4084 If the element is just a file name, the file name also serves as the prefix.")
4086 (defun Info-find-emacs-command-nodes (command)
4087 "Return a list of locations documenting COMMAND.
4088 The `info-file' property of COMMAND says which Info manual to search.
4089 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4090 defines heuristics for which Info manual to try.
4091 The locations are of the format used in `Info-history', i.e.
4092 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
4093 in the first element of the returned list (which is treated specially in
4094 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4095 (let ((where '()) line-number
4096 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4097 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4098 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4099 (info-file "emacs")) ;default
4100 ;; Determine which Info file this command is documented in.
4101 (if (get command 'info-file)
4102 (setq info-file (get command 'info-file))
4103 ;; If it doesn't say explicitly, test its name against
4104 ;; various prefixes that we know.
4105 (let ((file-list Info-file-list-for-emacs))
4107 (let* ((elt (car file-list))
4108 (name (if (consp elt)
4111 (file (if (consp elt) (cdr elt) elt))
4112 (case-fold-search nil)
4113 (regexp (concat "\\`" (regexp-quote name)
4115 (if (string-match regexp (symbol-name command))
4116 (setq info-file file file-list nil))
4117 (setq file-list (cdr file-list))))))
4118 (Info-find-node info-file "Top")
4119 ;; Bind Info-history to nil, to prevent the index nodes from
4120 ;; getting into the node history.
4121 (let ((Info-history nil)
4122 (Info-history-list nil)
4123 node (nodes (Info-index-nodes)))
4124 (Info-goto-node (car nodes))
4127 (goto-char (point-min))
4128 (while (re-search-forward cmd-desc nil t)
4130 (cons (list Info-current-file
4131 (match-string-no-properties 2)
4134 (setq line-number (and (match-beginning 3)
4135 (string-to-number (match-string 3)))))
4136 (and (setq nodes (cdr nodes) node (car nodes))))
4137 (Info-goto-node node)))
4138 (if (and line-number where)
4139 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4143 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4145 (defun Info-goto-emacs-command-node (command)
4146 "Go to the Info node in the Emacs manual for command COMMAND.
4147 The command is found by looking up in Emacs manual's indices
4148 or in another manual found via COMMAND's `info-file' property or
4149 the variable `Info-file-list-for-emacs'.
4150 COMMAND must be a symbol or string."
4151 (interactive "CFind documentation for command: ")
4152 ;; If command is given as a string, convert it to a symbol.
4153 (if (stringp command)
4154 (setq command (intern command)))
4155 (or (commandp command)
4156 (signal 'wrong-type-argument (list 'commandp command)))
4157 (let ((where (Info-find-emacs-command-nodes command)))
4159 (let ((num-matches (length where)))
4160 ;; Get Info running, and pop to it in another window.
4161 (save-window-excursion
4163 (or (eq major-mode 'Info-mode)
4164 (pop-to-buffer "*info*" 'same-window))
4165 ;; Bind Info-history to nil, to prevent the last Index node
4166 ;; visited by Info-find-emacs-command-nodes from being
4167 ;; pushed onto the history.
4168 (let ((Info-history nil) (Info-history-list nil)
4169 (line-number (nth 2 (car where))))
4170 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4171 (if (and (integerp line-number) (> line-number 0))
4172 (forward-line (1- line-number))))
4173 (if (> num-matches 1)
4175 ;; (car where) will be pushed onto Info-history
4176 ;; when/if they go to another node. Put the other
4177 ;; nodes that were found on the history.
4178 (setq Info-history (nconc (cdr where) Info-history))
4179 (message "Found %d other entr%s. Use %s to see %s."
4181 (if (> num-matches 2) "ies" "y")
4182 (substitute-command-keys "\\[Info-history-back]")
4183 (if (> num-matches 2) "them" "it")))))
4184 (error "Couldn't find documentation for %s" command))))
4186 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4188 (defun Info-goto-emacs-key-command-node (key)
4189 "Go to the node in the Emacs manual which describes the command bound to KEY.
4191 Interactively, if the binding is `execute-extended-command', a command is read.
4192 The command is found by looking up in Emacs manual's indices
4193 or in another manual found via COMMAND's `info-file' property or
4194 the variable `Info-file-list-for-emacs'."
4195 (interactive "kFind documentation for key: ")
4196 (let ((command (key-binding key)))
4197 (cond ((null command)
4198 (message "%s is undefined" (key-description key)))
4199 ((and (called-interactively-p 'interactive)
4200 (eq command 'execute-extended-command))
4201 (Info-goto-emacs-command-node
4202 (read-command "Find documentation for command: ")))
4204 (Info-goto-emacs-command-node command)))))
4206 (defvar Info-next-link-keymap
4207 (let ((keymap (make-sparse-keymap)))
4208 (define-key keymap [header-line mouse-1] 'Info-next)
4209 (define-key keymap [header-line mouse-2] 'Info-next)
4210 (define-key keymap [header-line down-mouse-1] 'ignore)
4211 (define-key keymap [mouse-2] 'Info-next)
4212 (define-key keymap [follow-link] 'mouse-face)
4214 "Keymap to put on the Next link in the text or the header line.")
4216 (defvar Info-prev-link-keymap
4217 (let ((keymap (make-sparse-keymap)))
4218 (define-key keymap [header-line mouse-1] 'Info-prev)
4219 (define-key keymap [header-line mouse-2] 'Info-prev)
4220 (define-key keymap [header-line down-mouse-1] 'ignore)
4221 (define-key keymap [mouse-2] 'Info-prev)
4222 (define-key keymap [follow-link] 'mouse-face)
4224 "Keymap to put on the Prev link in the text or the header line.")
4226 (defvar Info-up-link-keymap
4227 (let ((keymap (make-sparse-keymap)))
4228 (define-key keymap [header-line mouse-1] 'Info-up)
4229 (define-key keymap [header-line mouse-2] 'Info-up)
4230 (define-key keymap [header-line down-mouse-1] 'ignore)
4231 (define-key keymap [mouse-2] 'Info-up)
4232 (define-key keymap [follow-link] 'mouse-face)
4234 "Keymap to put on the Up link in the text or the header line.")
4236 (defvar Info-link-keymap
4237 (let ((keymap (make-sparse-keymap)))
4238 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4239 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4240 (define-key keymap [header-line down-mouse-1] 'ignore)
4241 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4242 (define-key keymap [follow-link] 'mouse-face)
4244 "Keymap to put on the link in the text or the header line.")
4246 (defun Info-breadcrumbs ()
4247 (let ((nodes (Info-toc-nodes Info-current-file))
4248 (node Info-current-node)
4250 (depth Info-breadcrumbs-depth)
4253 ;; Get ancestors from the cached parent-children node info
4254 (while (and (not (equal "Top" node)) (> depth 0))
4255 (setq node (nth 1 (assoc node nodes)))
4256 (if node (push node crumbs))
4257 (setq depth (1- depth)))
4260 (when Info-use-header-line
4261 ;; Let it disappear if crumbs is nil.
4262 (nconc crumbs (list Info-current-node)))
4263 (when (or Info-use-header-line crumbs)
4264 ;; Add top node (and continuation if needed).
4266 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4267 crumbs (cons nil crumbs))))
4268 ;; Eliminate duplicate.
4270 (dolist (node crumbs)
4272 (if (not (equal node "Top")) node
4274 (if (stringp Info-current-file)
4275 (file-name-nondirectory Info-current-file)
4276 ;; Some legacy code can still use a symbol.
4277 Info-current-file)))))
4280 (if (null line) "" " > ")
4283 ((equal node Info-current-node)
4284 ;; No point linking to ourselves.
4285 (propertize text 'font-lock-face 'info-header-node))
4288 'mouse-face 'highlight
4289 'font-lock-face 'info-header-xref
4290 'help-echo "mouse-2: Go to node"
4291 'keymap Info-link-keymap
4292 'link-args text)))))))
4293 (setq line (concat line "\n")))
4294 ;; (font-lock-append-text-property 0 (length line)
4295 ;; 'font-lock-face 'header-line line)
4298 (defun Info-fontify-node ()
4301 (let* ((inhibit-read-only t)
4302 (case-fold-search t)
4304 (not-fontified-p ; the node hasn't already been fontified
4305 (not (let ((where (next-single-property-change (point-min)
4307 (and where (not (= where (point-max)))))))
4308 (fontify-visited-p ; visited nodes need to be re-fontified
4309 (and Info-fontify-visited-nodes
4310 ;; Don't take time to refontify visited nodes in huge nodes
4311 Info-fontify-maximum-menu-size
4312 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4315 ;; Fontify header line
4316 (goto-char (point-min))
4317 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4318 (goto-char (match-end 0))
4319 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4320 (goto-char (match-end 0))
4321 (let* ((nbeg (match-beginning 2))
4322 (nend (match-end 2))
4323 (tbeg (match-beginning 1))
4324 (tag (match-string 1)))
4325 (if (string-equal (downcase tag) "node")
4326 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4327 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4328 (put-text-property tbeg nend 'mouse-face 'highlight)
4329 (put-text-property tbeg nend
4331 (concat "mouse-2: Go to node "
4332 (buffer-substring nbeg nend)))
4333 ;; Always set up the text property keymap.
4334 ;; It will either be used in the buffer
4335 ;; or copied in the header line.
4339 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4340 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4341 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4343 ;; (when (> Info-breadcrumbs-depth 0)
4344 ;; (insert (Info-breadcrumbs)))
4346 ;; Treat header line.
4347 (when Info-use-header-line
4348 (goto-char (point-min))
4349 (let* ((header-end (line-end-position))
4351 ;; If we find neither Next: nor Prev: link, show the entire
4352 ;; node header. Otherwise, don't show the File: and Node:
4353 ;; parts, to avoid wasting precious space on information that
4354 ;; is available in the mode line.
4355 (if (re-search-forward
4356 "\\(next\\|up\\|prev[ious]*\\): "
4359 (goto-char (match-beginning 1))
4360 (buffer-substring (point) header-end))
4361 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4363 (concat "No next, prev or up links -- "
4364 (buffer-substring (point) header-end))
4365 (buffer-substring (point) header-end)))))
4366 (put-text-property (point-min) (1+ (point-min))
4368 (replace-regexp-in-string
4370 ;; Preserve text properties on duplicated `%'.
4371 (lambda (s) (concat s s)) header))
4372 ;; Hide the part of the first line
4373 ;; that is in the header, if it is just part.
4375 ((> Info-breadcrumbs-depth 0)
4376 (let ((ov (make-overlay (point-min) (1+ header-end))))
4377 (overlay-put ov 'display (Info-breadcrumbs))
4378 (overlay-put ov 'evaporate t)))
4380 ;; Hide the punctuation at the end, too.
4381 (skip-chars-backward " \t,")
4382 (put-text-property (point) header-end 'invisible t))))))
4385 (goto-char (point-min))
4386 (when (and font-lock-mode not-fontified-p)
4387 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4389 ;; Only consider it as an underlined title if the ASCII
4390 ;; underline has the same size as the text. A typical
4391 ;; counter example is when a continuation "..." is alone
4393 (= (string-width (match-string 1))
4394 (string-width (match-string 2))))
4395 (let* ((c (preceding-char))
4397 (cond ((= c ?*) 'info-title-1)
4398 ((= c ?=) 'info-title-2)
4399 ((= c ?-) 'info-title-3)
4400 (t 'info-title-4))))
4401 (put-text-property (match-beginning 1) (match-end 1)
4402 'font-lock-face face))
4403 ;; This is a serious problem for trying to handle multiple
4404 ;; frame types at once. We want this text to be invisible
4405 ;; on frames that can display the font above.
4406 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4407 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4408 '(invisible t front-sticky nil rear-nonsticky t)))))
4410 ;; Fontify cross references
4411 (goto-char (point-min))
4412 (when (or not-fontified-p fontify-visited-p)
4413 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4414 (let ((start (match-beginning 0))
4417 (when not-fontified-p
4418 (when Info-hide-note-references
4419 (when (and (not (eq Info-hide-note-references 'hide))
4420 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4421 ;; *Note is often used where *note should have been
4423 (skip-syntax-backward " ")
4424 (when (memq (char-before) '(?\( ?\[ ?\{))
4425 ;; Check whether the paren is preceded by
4426 ;; an end of sentence
4427 (skip-syntax-backward " ("))
4429 (cond ((save-match-data (looking-back "\\<see"))
4431 ((save-match-data (looking-back "\\<in"))
4433 ((memq (char-before) '(nil ?\. ?! ??))
4437 (search-forward "\n\n" start t)))
4441 (add-text-properties
4443 (or (save-match-data
4444 ;; Don't hide \n after *Note
4445 (let ((start1 (match-beginning 1)))
4446 (if (string-match "\n" (match-string 1))
4447 (+ start1 (match-beginning 0)))))
4450 `(display ,other-tag front-sticky nil rear-nonsticky t)
4451 '(invisible t front-sticky nil rear-nonsticky t))))
4452 (add-text-properties
4453 (match-beginning 2) (match-end 2)
4455 'help-echo (if (or (match-end 5)
4456 (not (equal (match-string 4) "")))
4457 (concat "mouse-2: go to " (or (match-string 5)
4459 "mouse-2: go to this node")
4460 'mouse-face 'highlight)))
4461 (when (or not-fontified-p fontify-visited-p)
4462 (setq rbeg (match-beginning 2)
4467 ;; Display visited nodes in a different face
4468 (if (and Info-fontify-visited-nodes
4470 (let* ((node (replace-regexp-in-string
4472 (replace-regexp-in-string
4474 (or (match-string-no-properties 5)
4475 (and (not (equal (match-string 4) ""))
4476 (match-string-no-properties 4))
4477 (match-string-no-properties 2)))))
4479 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4480 (file (if external-link-p
4481 (file-name-nondirectory
4482 (match-string-no-properties 1 node))
4484 (hl Info-history-list)
4487 (setq node (if (equal (match-string 2 node) "")
4489 (match-string-no-properties 2 node))))
4491 (if (and (string-equal node (nth 1 (car hl)))
4493 (if (and external-link-p
4494 (stringp (caar hl)))
4495 (file-name-nondirectory
4498 (setq res (car hl) hl nil)
4499 (setq hl (cdr hl))))
4500 res))) 'info-xref-visited 'info-xref))
4501 ;; For multiline ref, unfontify newline and surrounding whitespace
4505 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4506 (remove-text-properties (match-beginning 0)
4508 '(font-lock-face t))))))
4509 (when not-fontified-p
4510 (when (memq Info-hide-note-references '(t hide))
4511 (add-text-properties (match-beginning 3) (match-end 3)
4512 '(invisible t front-sticky nil rear-nonsticky t))
4513 ;; Unhide the file name of the external reference in parens
4514 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4515 (remove-text-properties (match-beginning 6) (match-end 6)
4516 '(invisible t front-sticky nil rear-nonsticky t)))
4517 ;; Unhide newline because hidden newlines cause too long lines
4519 (let ((beg3 (match-beginning 3))
4520 (end3 (match-end 3)))
4521 (if (and (string-match "\n[ \t]*" (match-string 3))
4522 (not (save-match-data
4524 (goto-char (1+ end3))
4525 (looking-at "[.)]*$")))))
4526 (remove-text-properties (+ beg3 (match-beginning 0))
4527 (+ beg3 (match-end 0))
4528 '(invisible t front-sticky nil rear-nonsticky t))))))
4529 (when (and Info-refill-paragraphs Info-hide-note-references)
4530 (push (set-marker (make-marker) start)
4531 paragraph-markers))))))
4533 ;; Refill paragraphs (experimental feature)
4534 (when (and not-fontified-p
4535 Info-refill-paragraphs
4537 (let ((fill-nobreak-invisible t)
4538 (fill-individual-varying-indent nil)
4539 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4540 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4541 (adaptive-fill-mode nil))
4542 (goto-char (point-max))
4543 (dolist (m paragraph-markers)
4547 (let ((beg (point)))
4548 (when (zerop (forward-paragraph))
4549 (fill-individual-paragraphs beg (point) nil nil)
4551 (set-marker m nil))))
4553 ;; Fontify menu items
4554 (goto-char (point-min))
4555 (when (and (or not-fontified-p fontify-visited-p)
4556 (search-forward "\n* Menu:" nil t)
4557 ;; Don't take time to annotate huge menus
4558 Info-fontify-maximum-menu-size
4559 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4562 (while (re-search-forward
4563 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4564 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4566 (when (match-beginning 1)
4567 (when not-fontified-p
4569 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4570 (put-text-property (match-beginning 0)
4571 (1+ (match-beginning 0))
4572 'font-lock-face 'info-menu-star)))
4573 (when not-fontified-p
4574 (add-text-properties
4575 (match-beginning 1) (match-end 1)
4577 'help-echo (if (and (match-end 3)
4578 (not (equal (match-string 3) "")))
4579 (concat "mouse-2: go to " (match-string 3))
4580 "mouse-2: go to this node")
4581 'mouse-face 'highlight)))
4582 (when (or not-fontified-p fontify-visited-p)
4584 (match-beginning 1) (match-end 1)
4586 ;; Display visited menu items in a different face
4587 (if (and Info-fontify-visited-nodes
4589 (let* ((node (if (equal (match-string 3) "")
4590 (match-string-no-properties 1)
4591 (match-string-no-properties 3)))
4593 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4594 (file (if external-link-p
4595 (file-name-nondirectory
4596 (match-string-no-properties 1 node))
4598 (hl Info-history-list)
4601 (setq node (if (equal (match-string 2 node) "")
4603 (match-string-no-properties 2 node))))
4605 (if (and (string-equal node (nth 1 (car hl)))
4607 (if (and external-link-p
4608 (stringp (caar hl)))
4609 (file-name-nondirectory
4612 (setq res (car hl) hl nil)
4613 (setq hl (cdr hl))))
4614 res))) 'info-xref-visited 'info-xref)))
4615 (when (and not-fontified-p
4616 (memq Info-hide-note-references '(t hide))
4617 (not (Info-index-node)))
4618 (put-text-property (match-beginning 2) (1- (match-end 6))
4620 ;; Unhide the file name in parens
4621 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4622 (remove-text-properties (match-beginning 4) (match-end 4)
4624 ;; We need a stretchable space like :align-to but with
4626 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4627 (if (>= 22 (- (match-end 1)
4628 (match-beginning 0)))
4629 '(space :align-to 24)
4631 (setq cont (looking-at "."))
4632 (while (and (= (forward-line 1) 0)
4633 (looking-at "\\([ \t]+\\)[^*\n]"))
4634 (put-text-property (match-beginning 1) (1- (match-end 1))
4636 (put-text-property (1- (match-end 1)) (match-end 1)
4639 '(space :align-to 26)
4640 '(space :align-to 24)))
4643 ;; Fontify menu headers
4644 ;; Add the face `info-menu-header' to any header before a menu entry
4645 (goto-char (point-min))
4646 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4647 (put-text-property (match-beginning 0) (match-end 0)
4648 'font-lock-face 'info-menu-header)
4649 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4650 (put-text-property (match-beginning 1) (match-end 1)
4651 'font-lock-face 'info-menu-header)))
4653 ;; Hide index line numbers
4654 (goto-char (point-min))
4655 (when (and not-fontified-p (Info-index-node))
4656 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4657 (put-text-property (match-beginning 0) (match-end 0)
4660 ;; Fontify http and ftp references
4661 (goto-char (point-min))
4662 (when not-fontified-p
4663 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4665 (add-text-properties (match-beginning 0) (match-end 0)
4666 '(font-lock-face info-xref
4667 mouse-face highlight
4668 help-echo "mouse-2: go to this URL"))))
4670 (set-buffer-modified-p nil))))
4672 ;;; Speedbar support:
4673 ;; These functions permit speedbar to display the "tags" in the
4674 ;; current Info node.
4675 (eval-when-compile (require 'speedbar))
4677 (defvar Info-speedbar-key-map nil
4678 "Keymap used when in the info display mode.")
4680 (defun Info-install-speedbar-variables ()
4681 "Install those variables used by speedbar to enhance Info."
4682 (if Info-speedbar-key-map
4684 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4686 ;; Basic tree features
4687 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4688 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4689 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4690 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4693 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4694 Info-speedbar-key-map
4695 Info-speedbar-hierarchy-buttons)))
4697 (defvar Info-speedbar-menu-items
4698 '(["Browse Node" speedbar-edit-line t]
4699 ["Expand Node" speedbar-expand-line
4700 (save-excursion (beginning-of-line)
4701 (looking-at "[0-9]+: *.\\+. "))]
4702 ["Contract Node" speedbar-contract-line
4703 (save-excursion (beginning-of-line)
4704 (looking-at "[0-9]+: *.-. "))]
4706 "Additional menu-items to add to speedbar frame.")
4708 ;; Make sure our special speedbar major mode is loaded
4709 (if (featurep 'speedbar)
4710 (Info-install-speedbar-variables)
4711 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4713 ;;; Info hierarchy display method
4715 (defun Info-speedbar-browser ()
4716 "Initialize speedbar to display an Info node browser.
4717 This will add a speedbar major display mode."
4720 ;; Make sure that speedbar is active
4721 (speedbar-frame-mode 1)
4722 ;; Now, throw us into Info mode on speedbar.
4723 (speedbar-change-initial-expansion-list "Info")
4726 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4727 "Display an Info directory hierarchy in speedbar.
4728 DIRECTORY is the current directory in the attached frame.
4729 DEPTH is the current indentation depth.
4730 NODE is an optional argument that is used to represent the
4731 specific node to expand."
4733 (save-excursion (goto-char (point-min))
4734 (let ((case-fold-search t))
4735 (looking-at "Info Nodes:"))))
4736 ;; Update our "current node" maybe?
4738 ;; We cannot use the generic list code, that depends on all leaves
4739 ;; being known at creation time.
4741 (speedbar-with-writable (insert "Info Nodes:\n")))
4742 (let ((completions nil))
4743 (speedbar-select-attached-frame)
4744 (save-window-excursion
4746 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4747 (select-frame (speedbar-current-frame))
4749 (speedbar-with-writable
4750 (dolist (completion completions)
4751 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4754 'Info-speedbar-goto-node
4760 (defun Info-speedbar-goto-node (text node indent)
4761 "When user clicks on TEXT, go to an info NODE.
4762 The INDENT level is ignored."
4763 (speedbar-select-attached-frame)
4764 (let* ((buff (or (get-buffer "*info*")
4765 (progn (info) (get-buffer "*info*"))))
4766 (bwin (get-buffer-window buff 0)))
4769 (select-window bwin)
4770 (raise-frame (window-frame bwin)))
4771 (if speedbar-power-click
4772 (select-window (display-buffer buff 'other-frame))
4773 (speedbar-select-attached-frame)
4774 (switch-to-buffer buff)))
4775 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4776 (error "Invalid node %s" node)
4777 (Info-find-node (match-string 1 node) (match-string 2 node))
4778 ;; If we do a find-node, and we were in info mode, restore
4779 ;; the old default method. Once we are in info mode, it makes
4780 ;; sense to return to whatever method the user was using before.
4781 (if (string= speedbar-initial-expansion-list-name "Info")
4782 (speedbar-change-initial-expansion-list
4783 speedbar-previously-used-expansion-list-name)))))
4785 (defun Info-speedbar-expand-node (text token indent)
4786 "Expand the node the user clicked on.
4787 TEXT is the text of the button we clicked on, a + or - item.
4788 TOKEN is data related to this node (NAME . FILE).
4789 INDENT is the current indentation depth."
4790 (cond ((string-match "+" text) ;we have to expand this file
4791 (speedbar-change-expand-button-char ?-)
4792 (if (speedbar-with-writable
4794 (end-of-line) (forward-char 1)
4795 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4796 (speedbar-change-expand-button-char ?-)
4797 (speedbar-change-expand-button-char ??)))
4798 ((string-match "-" text) ;we have to contract this node
4799 (speedbar-change-expand-button-char ?+)
4800 (speedbar-delete-subblock indent))
4801 (t (error "Ooops... not sure what to do")))
4802 (speedbar-center-buffer-smartly))
4804 (defun Info-speedbar-fetch-file-nodes (nodespec)
4805 "Fetch the subnodes from the info NODESPEC.
4806 NODESPEC is a string of the form: (file)node."
4807 ;; Set up a buffer we can use to fake-out Info.
4808 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4809 (if (not (equal major-mode 'Info-mode))
4811 ;; Get the node into this buffer
4812 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4813 (error "Invalid node specification %s" nodespec)
4814 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4815 ;; Scan the created buffer
4816 (goto-char (point-min))
4817 (let ((completions nil)
4818 (case-fold-search t)
4819 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4820 (match-string 1 nodespec))))
4821 ;; Always skip the first one...
4822 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4823 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4824 (let ((name (match-string 1)))
4826 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4828 (if (looking-at " *\\(([^)]+)\\)\\.")
4829 (concat (match-string 1) "Top")
4830 (concat "(" thisfile ")"
4831 (if (looking-at " \\([^.]+\\).")
4835 (nreverse completions))))
4837 ;;; Info mode node listing
4838 ;; This is called by `speedbar-add-localized-speedbar-support'
4839 (defun Info-speedbar-buttons (buffer)
4840 "Create a speedbar display to help navigation in an Info file.
4841 BUFFER is the buffer speedbar is requesting buttons for."
4842 (if (save-excursion (goto-char (point-min))
4843 (let ((case-fold-search t))
4844 (not (looking-at "Info Nodes:"))))
4846 (Info-speedbar-hierarchy-buttons nil 0))
4848 (dolist (mess '("^First node in file$"
4849 "^No `.*' in index$"
4850 "^No cross-reference named"
4851 "^No cross.references in this node$"
4852 "^No current Info node$"
4853 "^No menu in this node$"
4854 "^No more items in menu$"
4856 "^No pointer \\(?:forward\\|backward\\) from this node$"
4857 "^No previous `i' command$"
4858 "^No previous items in menu$"
4859 "^No previous nodes$"
4860 "^No such item in menu$"
4861 "^No such node or anchor"
4863 "^Point neither on reference nor in menu item description$"
4864 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4866 (add-to-list 'debug-ignored-errors mess))
4868 ;;;; Desktop support
4870 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4871 "Auxiliary information to be saved in desktop file."
4872 (list Info-current-file
4874 ;; Additional data as an association list.
4877 (cons 'history Info-history))
4878 (and (Info-virtual-fun
4879 'slow Info-current-file Info-current-node)
4882 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4884 desktop-buffer-misc)
4885 "Restore an Info buffer specified in a desktop file."
4886 (let* ((file (nth 0 desktop-buffer-misc))
4887 (node (nth 1 desktop-buffer-misc))
4888 (data (nth 2 desktop-buffer-misc))
4889 (hist (assq 'history data))
4890 (slow (assq 'slow data)))
4891 ;; Don't restore nodes slow to regenerate.
4893 (when (and file node)
4894 (when desktop-buffer-name
4895 (set-buffer (get-buffer-create desktop-buffer-name))
4897 (Info-find-node file node)
4899 (setq Info-history (cdr hist)))
4900 (current-buffer)))))
4902 (add-to-list 'desktop-buffer-mode-handlers
4903 '(Info-mode . Info-restore-desktop-buffer))
4905 ;;;; Bookmark support
4906 (declare-function bookmark-make-record-default
4907 "bookmark" (&optional no-file no-context posn))
4908 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4909 (declare-function bookmark-default-handler "bookmark" (bmk))
4910 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4912 (defun Info-bookmark-make-record ()
4913 "This implements the `bookmark-make-record-function' type (which see)
4915 `(,Info-current-node
4916 ,@(bookmark-make-record-default 'no-file)
4917 (filename . ,Info-current-file)
4918 (info-node . ,Info-current-node)
4919 (handler . Info-bookmark-jump)))
4922 (defun Info-bookmark-jump (bmk)
4923 "This implements the `handler' function interface for the record
4924 type returned by `Info-bookmark-make-record', which see."
4925 (let* ((file (bookmark-prop-get bmk 'filename))
4926 (info-node (bookmark-prop-get bmk 'info-node))
4927 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4928 (Info-find-node file info-node) (current-buffer))))
4929 ;; Use bookmark-default-handler to move to the appropriate location
4931 (bookmark-default-handler
4932 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4936 ;;; info.el ends here