1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; 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."
243 (defcustom Info-search-whitespace-regexp
"\\s-+"
244 "If non-nil, regular expression to match a sequence of whitespace chars.
245 This applies to Info search for regular expressions.
246 You might want to use something like \"[ \\t\\r\\n]+\" instead.
247 In the Customization buffer, that is `[' followed by a space,
248 a tab, a carriage return (control-M), a newline, and `]+'."
252 (defcustom Info-isearch-search t
253 "If non-nil, isearch in Info searches through multiple nodes.
254 Before leaving the initial Info node, where isearch was started,
255 it fails once with the error message [initial node], and with
256 subsequent C-s/C-r continues through other nodes without failing
257 with this error message in other nodes. When isearch fails for
258 the rest of the manual, it wraps aroung the whole manual and
259 restarts the search from the top/final node depending on
262 Setting this option to nil restores the default isearch behavior
263 with wrapping around the current Info node."
268 (defvar Info-isearch-initial-node nil
)
270 (defcustom Info-mode-hook
271 ;; Try to obey obsolete Info-fontify settings.
272 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
273 '(turn-on-font-lock))
274 "Hooks run when `Info-mode' is called."
278 (defcustom Info-selection-hook nil
279 "Hooks run when `Info-select-node' is called."
283 (defvar Info-edit-mode-hook nil
284 "Hooks run when `Info-edit-mode' is called.")
286 (defvar Info-current-file nil
287 "Info file that Info is now looking at, or nil.
288 This is the name that was specified in Info, not the actual file name.
289 It doesn't contain directory names or file name extensions added by Info.")
291 (defvar Info-current-subfile nil
292 "Info subfile that is actually in the *info* buffer now.
293 It is nil if current Info file is not split into subfiles.")
295 (defvar Info-current-node nil
296 "Name of node that Info is now looking at, or nil.")
298 (defvar Info-tag-table-marker nil
299 "Marker pointing at beginning of current Info file's tag table.
300 Marker points nowhere if file has no tag table.")
302 (defvar Info-tag-table-buffer nil
303 "Buffer used for indirect tag tables.")
305 (defvar Info-current-file-completions nil
306 "Cached completion list for current Info file.")
308 (defvar Info-file-supports-index-cookies nil
309 "Non-nil if current Info file supports index cookies.")
311 (defvar Info-file-supports-index-cookies-list nil
312 "List of Info files with information about index cookies support.
313 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
314 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
316 (defvar Info-index-alternatives nil
317 "List of possible matches for last `Info-index' command.")
319 (defvar Info-point-loc nil
320 "Point location within a selected node.
321 If string, the point is moved to the proper occurrence of the
322 name of the followed cross reference within a selected node.
323 If number, the point is moved to the corresponding line.")
325 (defvar Info-standalone nil
326 "Non-nil if Emacs was started solely as an Info browser.")
328 (defvar Info-virtual-files nil
329 "List of definitions of virtual Info files.
330 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
331 where FILENAME is a regexp that matches a class of virtual Info file names.
332 It should be carefully chosen to not cause file name clashes with
333 existing file names. OPERATION is one of the following operation
334 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
335 function to call instead of calling the default corresponding function
338 (defvar Info-virtual-nodes nil
339 "List of definitions of virtual Info nodes.
340 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
341 where NODENAME is a regexp that matches a class of virtual Info node names.
342 It should be carefully chosen to not cause node name clashes with
343 existing node names. OPERATION is one of the following operation
344 symbols `find-node' that define what HANDLER
345 function to call instead of calling the default corresponding function
348 (defvar Info-current-node-virtual nil
349 "Non-nil if the current Info node is virtual.")
351 (defun Info-virtual-file-p (filename)
352 "Check if Info file FILENAME is virtual."
353 (Info-virtual-fun 'find-file filename nil
))
355 (defun Info-virtual-fun (op filename nodename
)
356 "Find a function that handles operations on virtual manuals.
357 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
358 FILENAME is a virtual Info file name, NODENAME is a virtual Info
359 node name. Return a function found either in `Info-virtual-files'
360 or `Info-virtual-nodes'."
361 (or (and (stringp filename
) ; some legacy code can still use a symbol
362 (cdr-safe (assoc op
(assoc-default filename
365 (and (stringp nodename
) ; some legacy code can still use a symbol
366 (cdr-safe (assoc op
(assoc-default nodename
370 (defun Info-virtual-call (virtual-fun &rest args
)
371 "Call a function that handles operations on virtual manuals."
372 (when (functionp virtual-fun
)
373 (or (apply virtual-fun args
) t
)))
376 (defvar Info-suffix-list
377 ;; The MS-DOS list should work both when long file names are
378 ;; supported (Windows 9X), and when only 8+3 file names are available.
379 (if (eq system-type
'ms-dos
)
380 '( (".gz" .
"gunzip")
382 (".bz2" .
("bzip2" "-dc"))
385 (".info.Z" .
"gunzip")
386 (".info.gz" .
"gunzip")
387 ("-info.Z" .
"gunzip")
388 ("-info.gz" .
"gunzip")
389 ("/index.gz".
"gunzip")
390 ("/index.z" .
"gunzip")
396 '( (".info.Z".
"uncompress")
397 (".info.Y".
"unyabba")
398 (".info.gz".
"gunzip")
399 (".info.z".
"gunzip")
400 (".info.bz2" .
("bzip2" "-dc"))
402 ("-info.Z".
"uncompress")
403 ("-info.Y".
"unyabba")
404 ("-info.gz".
"gunzip")
405 ("-info.bz2" .
("bzip2" "-dc"))
406 ("-info.z".
"gunzip")
408 ("/index.Z".
"uncompress")
409 ("/index.Y".
"unyabba")
410 ("/index.gz".
"gunzip")
411 ("/index.z".
"gunzip")
412 ("/index.bz2".
("bzip2" "-dc"))
418 (".bz2" .
("bzip2" "-dc"))
420 "List of file name suffixes and associated decoding commands.
421 Each entry should be (SUFFIX . STRING); the file is given to
422 the command as standard input.
424 STRING may be a list of strings. In that case, the first element is
425 the command name, and the rest are arguments to that command.
427 If STRING is nil, no decoding is done.
428 Because the SUFFIXes are tried in order, the empty string should
429 be last in the list.")
431 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
432 ;; First, on MS-DOS with no long file names support, delete some of
433 ;; the extension in FILENAME to make room.
434 (defun info-insert-file-contents-1 (filename suffix lfn
)
435 (if lfn
; long file names are supported
436 (concat filename suffix
)
437 (let* ((sans-exts (file-name-sans-extension filename
))
438 ;; How long is the extension in FILENAME (not counting the dot).
439 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
441 ;; SUFFIX starts with a dot. If FILENAME already has one,
442 ;; get rid of the one in SUFFIX (unless suffix is empty).
443 (or (and (<= ext-len
0)
444 (not (eq (aref filename
(1- (length filename
))) ?.
)))
445 (= (length suffix
) 0)
446 (setq suffix
(substring suffix
1)))
447 ;; How many chars of that extension should we keep?
448 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
449 ;; Get rid of the rest of the extension, and add SUFFIX.
450 (concat (substring filename
0 (- (length filename
)
451 (- ext-len ext-left
)))
454 (defun info-file-exists-p (filename)
455 (and (file-exists-p filename
)
456 (not (file-directory-p filename
))))
458 (defun info-insert-file-contents (filename &optional visit
)
459 "Insert the contents of an Info file in the current buffer.
460 Do the right thing if the file has been compressed or zipped."
461 (let* ((tail Info-suffix-list
)
462 (lfn (if (fboundp 'msdos-long-file-names
)
463 (msdos-long-file-names)
465 (check-short (and (fboundp 'msdos-long-file-names
)
467 fullname decoder done
)
468 (if (info-file-exists-p filename
)
469 ;; FILENAME exists--see if that name contains a suffix.
470 ;; If so, set DECODE accordingly.
474 (concat (regexp-quote (car (car tail
))) "$")
476 (setq tail
(cdr tail
)))
477 (setq fullname filename
478 decoder
(cdr (car tail
))))
479 ;; Try adding suffixes to FILENAME and see if we can find something.
480 (while (and tail
(not done
))
481 (setq fullname
(info-insert-file-contents-1 filename
482 (car (car tail
)) lfn
))
483 (if (info-file-exists-p fullname
)
485 ;; If we found a file with a suffix, set DECODER
486 ;; according to the suffix.
487 decoder
(cdr (car tail
)))
488 ;; When the MS-DOS port runs on Windows, we need to check
489 ;; the short variant of a long file name as well.
491 (setq fullname
(info-insert-file-contents-1 filename
492 (car (car tail
)) nil
))
493 (if (info-file-exists-p fullname
)
495 decoder
(cdr (car tail
))))))
496 (setq tail
(cdr tail
)))
498 (error "Can't find %s or any compressed version of it" filename
)))
499 ;; check for conflict with jka-compr
500 (if (and (jka-compr-installed-p)
501 (jka-compr-get-compression-info fullname
))
505 (insert-file-contents-literally fullname visit
)
506 (let ((inhibit-read-only t
)
507 (coding-system-for-write 'no-conversion
)
508 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
509 (default-directory (or (file-name-directory fullname
)
512 (setq decoder
(list decoder
)))
513 (apply 'call-process-region
(point-min) (point-max)
514 (car decoder
) t t nil
(cdr decoder
))))
515 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
516 (insert-file-contents fullname visit
)))))
518 (defun Info-file-supports-index-cookies (&optional file
)
519 "Return non-nil value if FILE supports Info index cookies.
520 Info index cookies were first introduced in 4.7, and all later
521 makeinfo versions output them in index nodes, so we can rely
522 solely on the makeinfo version. This function caches the information
523 in `Info-file-supports-index-cookies-list'."
524 (or file
(setq file Info-current-file
))
525 (or (assoc file Info-file-supports-index-cookies-list
)
526 ;; Skip virtual Info files
527 (and (or (not (stringp file
))
528 (Info-virtual-file-p file
))
529 (setq Info-file-supports-index-cookies-list
530 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
533 (goto-char (point-min))
535 (if (and (re-search-forward
536 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
537 (line-beginning-position 3) t
)
538 (not (version< (match-string 1) "4.7")))
541 (setq Info-file-supports-index-cookies-list
542 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
543 (cdr (assoc file Info-file-supports-index-cookies-list
)))
546 (defun Info-default-dirs ()
547 (let ((source (expand-file-name "info/" source-directory
))
548 (sibling (if installation-directory
549 (expand-file-name "info/" installation-directory
)
550 (if invocation-directory
551 (let ((infodir (expand-file-name
553 invocation-directory
)))
554 (if (file-exists-p infodir
)
556 (setq infodir
(expand-file-name
557 "../../../share/info/"
558 invocation-directory
))
559 (and (file-exists-p infodir
)
563 (if (and sibling
(file-exists-p sibling
))
564 ;; Uninstalled, Emacs builddir != srcdir.
566 ;; Uninstalled, builddir == srcdir
568 (if (or (member alternative Info-default-directory-list
)
569 ;; On DOS/NT, we use movable executables always,
570 ;; and we must always find the Info dir at run time.
571 (if (memq system-type
'(ms-dos windows-nt
))
573 ;; Use invocation-directory for Info
574 ;; only if we used it for exec-directory also.
575 (not (string= exec-directory
576 (expand-file-name "lib-src/"
577 installation-directory
))))
578 (not (file-exists-p alternative
)))
579 Info-default-directory-list
580 ;; `alternative' contains the Info files that came with this
581 ;; version, so we should look there first. `Info-insert-dir'
582 ;; currently expects to find `alternative' first on the list.
584 ;; Don't drop the last part, it might contain non-Emacs stuff.
585 ;; (reverse (cdr (reverse
586 Info-default-directory-list
)))) ;; )))
588 (defun info-initialize ()
589 "Initialize `Info-directory-list', if that hasn't been done yet."
590 (unless Info-directory-list
591 (let ((path (getenv "INFOPATH")))
592 (setq Info-directory-list
593 (prune-directory-list
595 (if (string-match ":\\'" path
)
596 (append (split-string (substring path
0 -
1)
597 (regexp-quote path-separator
))
599 (split-string path
(regexp-quote path-separator
)))
600 (Info-default-dirs)))))))
603 (defun info-other-window (&optional file-or-node
)
604 "Like `info' but show the Info buffer in another window."
605 (interactive (if current-prefix-arg
606 (list (read-file-name "Info file name: " nil nil t
))))
607 (let (same-window-buffer-names same-window-regexps
)
608 (info file-or-node
)))
610 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\*info\\*\\(\\|<[0-9]+>\\)"))
612 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
614 (defun info (&optional file-or-node buffer
)
615 "Enter Info, the documentation browser.
616 Optional argument FILE-OR-NODE specifies the file to examine;
617 the default is the top-level directory of Info.
618 Called from a program, FILE-OR-NODE may specify an Info node of the form
619 `(FILENAME)NODENAME'.
620 Optional argument BUFFER specifies the Info buffer name;
621 the default buffer name is *info*. If BUFFER exists,
622 just switch to BUFFER. Otherwise, create a new buffer
623 with the top-level Info directory.
625 In interactive use, a non-numeric prefix argument directs
626 this command to read a file name from the minibuffer.
627 A numeric prefix argument selects an Info buffer with the prefix number
628 appended to the Info buffer name.
630 The search path for Info files is in the variable `Info-directory-list'.
631 The top-level Info directory is made by combining all the files named `dir'
632 in all the directories in that path.
634 See a list of available Info commands in `Info-mode'."
636 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
637 (read-file-name "Info file name: " nil nil t
))
638 (if (numberp current-prefix-arg
)
639 (format "*info*<%s>" current-prefix-arg
))))
640 (pop-to-buffer (or buffer
"*info*"))
641 (if (and buffer
(not (eq major-mode
'Info-mode
)))
644 ;; If argument already contains parentheses, don't add another set
645 ;; since the argument will then be parsed improperly. This also
646 ;; has the added benefit of allowing node names to be included
647 ;; following the parenthesized filename.
649 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
651 (concat "(" file-or-node
")")))
652 (if (and (zerop (buffer-size))
654 ;; If we just created the Info buffer, go to the directory.
658 (defun info-emacs-manual ()
659 "Display the Emacs manual in Info mode."
664 (defun info-standalone ()
665 "Run Emacs as a standalone Info reader.
666 Usage: emacs -f info-standalone [filename]
667 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
668 (setq Info-standalone t
)
669 (if (and command-line-args-left
670 (not (string-match "^-" (car command-line-args-left
))))
673 (info (car command-line-args-left
))
674 (setq command-line-args-left
(cdr command-line-args-left
)))
675 (error (send-string-to-terminal
676 (format "%s\n" (if (eq (car-safe err
) 'error
)
678 (save-buffers-kill-emacs)))
681 ;; See if the accessible portion of the buffer begins with a node
682 ;; delimiter, and the node header line which follows matches REGEXP.
683 ;; Typically, this test will be followed by a loop that examines the
684 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
685 ;; to have the overhead of this special test inside the loop.
687 ;; This function changes match-data, but supposedly the caller might
688 ;; want to use the results of re-search-backward.
690 ;; The return value is the value of point at the beginning of matching
691 ;; REGEXP, if the function succeeds, nil otherwise.
692 (defun Info-node-at-bob-matching (regexp)
693 (and (bobp) ; are we at beginning of buffer?
694 (looking-at "\^_") ; does it begin with node delimiter?
698 (forward-line 1) ; does the line after delimiter match REGEXP?
699 (re-search-backward regexp beg t
))))
701 (defun Info-find-file (filename &optional noerror
)
702 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
703 Optional second argument NOERROR, if t, means if file is not found
704 just return nil (no error)."
705 ;; Convert filename to lower case if not found as specified.
709 (Info-virtual-fun 'find-file filename nil
)
712 (let (temp temp-downcase found
)
713 (setq filename
(substitute-in-file-name filename
))
714 (let ((dirs (if (string-match "^\\./" filename
)
715 ;; If specified name starts with `./'
716 ;; then just try current directory.
718 (if (file-name-absolute-p filename
)
719 ;; No point in searching for an
720 ;; absolute file name
722 (if Info-additional-directory-list
723 (append Info-directory-list
724 Info-additional-directory-list
)
725 Info-directory-list
)))))
726 ;; Search the directory list for file FILENAME.
727 (while (and dirs
(not found
))
728 (setq temp
(expand-file-name filename
(car dirs
)))
730 (expand-file-name (downcase filename
) (car dirs
)))
731 ;; Try several variants of specified name.
732 (let ((suffix-list Info-suffix-list
)
733 (lfn (if (fboundp 'msdos-long-file-names
)
734 (msdos-long-file-names)
736 (while (and suffix-list
(not found
))
737 (cond ((info-file-exists-p
738 (info-insert-file-contents-1
739 temp
(car (car suffix-list
)) lfn
))
742 (info-insert-file-contents-1
743 temp-downcase
(car (car suffix-list
)) lfn
))
744 (setq found temp-downcase
))
745 ((and (fboundp 'msdos-long-file-names
)
748 (info-insert-file-contents-1
749 temp
(car (car suffix-list
)) nil
)))
751 (setq suffix-list
(cdr suffix-list
))))
752 (setq dirs
(cdr dirs
))))
754 (setq filename found
)
757 (error "Info file %s does not exist" filename
)))
760 (defun Info-find-node (filename nodename
&optional no-going-back
)
761 "Go to an Info node specified as separate FILENAME and NODENAME.
762 NO-GOING-BACK is non-nil if recovering from an error in this function;
763 it says do not attempt further (recursive) error recovery."
765 (setq filename
(Info-find-file filename
))
766 ;; Go into Info buffer.
767 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
768 ;; Record the node we are leaving, if we were in one.
769 (and (not no-going-back
)
771 (push (list Info-current-file Info-current-node
(point))
773 (Info-find-node-2 filename nodename no-going-back
))
776 (defun Info-on-current-buffer (&optional nodename
)
777 "Use Info mode to browse the current Info buffer.
778 With a prefix arg, this queries for the node name to visit first;
779 otherwise, that defaults to `Top'."
781 (list (if current-prefix-arg
782 (completing-read "Node name: " (Info-build-node-completions)
784 (unless nodename
(setq nodename
"Top"))
787 (set (make-local-variable 'Info-current-file
)
789 ;; If called on a non-file buffer, make a fake file name.
790 (concat default-directory
(buffer-name))))
791 (Info-find-node-2 nil nodename
))
793 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
794 ;; but at least it keeps this routine (which is for makeinfo-buffer and
795 ;; Info-revert-buffer-function) out of the way of normal operations.
797 (defun Info-revert-find-node (filename nodename
)
798 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
799 When *info* is already displaying FILENAME and NODENAME, the window position
800 is preserved, if possible."
801 (pop-to-buffer "*info*")
802 (let ((old-filename Info-current-file
)
803 (old-nodename Info-current-node
)
804 (pcolumn (current-column))
805 (pline (count-lines (point-min) (line-beginning-position)))
806 (wline (count-lines (point-min) (window-start)))
807 (old-history Info-history
)
808 (new-history (and Info-current-file
809 (list Info-current-file Info-current-node
(point)))))
810 (kill-buffer (current-buffer))
811 (Info-find-node filename nodename
)
812 (setq Info-history old-history
)
813 (if (and (equal old-filename Info-current-file
)
814 (equal old-nodename Info-current-node
))
816 ;; note goto-line is no good, we want to measure from point-min
817 (goto-char (point-min))
819 (set-window-start (selected-window) (point))
820 (goto-char (point-min))
822 (move-to-column pcolumn
))
823 ;; only add to the history when coming from a different file+node
825 (setq Info-history
(cons new-history Info-history
))))))
827 (defun Info-revert-buffer-function (ignore-auto noconfirm
)
828 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
829 (Info-revert-find-node Info-current-file Info-current-node
)
830 (message "Reverted %s" Info-current-file
)))
832 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
833 "Find a node in a tag table.
834 MARKER specifies the buffer and position to start searching at.
835 REGEXP is a regular expression matching nodes or references. Its first
836 group should match `Node:' or `Ref:'.
837 CASE-FOLD t means search for a case-insensitive match.
838 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
839 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
840 where the match was found, and MODE is `major-mode' of the buffer in
841 which the match was found."
842 (let ((case-fold-search case-fold
))
843 (with-current-buffer (marker-buffer marker
)
848 (when (re-search-forward regexp nil t
)
849 (list (string-equal "Ref:" (match-string 1))
850 (+ (point-min) (read (current-buffer)))
853 (defun Info-find-in-tag-table (marker regexp
)
854 "Find a node in a tag table.
855 MARKER specifies the buffer and position to start searching at.
856 REGEXP is a regular expression matching nodes or references. Its first
857 group should match `Node:' or `Ref:'.
858 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
859 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
860 where the match was found, and MODE is `major-mode' of the buffer in
861 which the match was found.
862 This function tries to find a case-sensitive match first, then a
863 case-insensitive match is tried."
864 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
865 (when (null (car result
))
866 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
869 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
870 "Find a node or anchor in the current buffer.
871 REGEXP is a regular expression matching nodes or references. Its first
872 group should match `Node:' or `Ref:'.
873 CASE-FOLD t means search for a case-insensitive match.
874 Value is the position at which a match was found, or nil if not found."
875 (let ((case-fold-search case-fold
)
878 (when (Info-node-at-bob-matching regexp
)
879 (setq found
(point)))
880 (while (and (not found
)
881 (search-forward "\n\^_" nil t
))
885 (when (re-search-backward regexp beg t
)
887 (setq found
(point)))))
890 (defun Info-find-node-in-buffer (regexp)
891 "Find a node or anchor in the current buffer.
892 REGEXP is a regular expression matching nodes or references. Its first
893 group should match `Node:' or `Ref:'.
894 Value is the position at which a match was found, or nil if not found.
895 This function looks for a case-sensitive match first. If none is found,
896 a case-insensitive match is tried."
897 (or (Info-find-node-in-buffer-1 regexp nil
)
898 (Info-find-node-in-buffer-1 regexp t
)))
900 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
901 (buffer-disable-undo (current-buffer))
902 (or (eq major-mode
'Info-mode
)
905 (setq Info-current-node nil
)
907 (let ((case-fold-search t
)
908 (virtual-fun (Info-virtual-fun 'find-node
909 (or filename Info-current-file
)
913 ((functionp virtual-fun
)
914 (let ((filename (or filename Info-current-file
)))
915 (setq buffer-read-only nil
)
916 (setq Info-current-file filename
917 Info-current-subfile nil
918 Info-current-file-completions nil
919 buffer-file-name nil
)
921 (Info-virtual-call virtual-fun filename nodename no-going-back
)
922 (set-marker Info-tag-table-marker nil
)
923 (setq buffer-read-only t
)
924 (set-buffer-modified-p nil
)
925 (set (make-local-variable 'Info-current-node-virtual
) t
)))
927 ;; Reread a file when moving from a virtual node.
928 (not Info-current-node-virtual
)
930 (equal Info-current-file filename
))))
931 ;; Switch files if necessary
932 (let ((inhibit-read-only t
))
933 (when Info-current-node-virtual
934 ;; When moving from a virtual node.
935 (set (make-local-variable 'Info-current-node-virtual
) nil
)
937 (setq filename Info-current-file
)))
938 (setq Info-current-file nil
939 Info-current-subfile nil
940 Info-current-file-completions nil
941 buffer-file-name nil
)
943 (info-insert-file-contents filename nil
)
944 (setq default-directory
(file-name-directory filename
))
945 (set-buffer-modified-p nil
)
946 (set (make-local-variable 'Info-file-supports-index-cookies
)
947 (Info-file-supports-index-cookies filename
))
949 ;; See whether file has a tag table. Record the location if yes.
950 (goto-char (point-max))
952 ;; Use string-equal, not equal, to ignore text props.
953 (if (not (or (string-equal nodename
"*")
955 (search-forward "\^_\nEnd tag table\n" nil t
))))
957 ;; We have a tag table. Find its beginning.
958 ;; Is this an indirect file?
959 (search-backward "\nTag table:\n")
963 (looking-at "(Indirect)\n"))
964 ;; It is indirect. Copy it to another buffer
965 ;; and record that the tag table is in that buffer.
966 (let ((buf (current-buffer))
968 (or Info-tag-table-buffer
969 (generate-new-buffer " *info tag table*"))))
970 (setq Info-tag-table-buffer tagbuf
)
971 (with-current-buffer tagbuf
972 (buffer-disable-undo (current-buffer))
973 (setq case-fold-search t
)
975 (insert-buffer-substring buf
))
976 (set-marker Info-tag-table-marker
977 (match-end 0) tagbuf
))
978 (set-marker Info-tag-table-marker pos
)))
979 (set-marker Info-tag-table-marker nil
))
980 (setq Info-current-file filename
)
983 ;; Use string-equal, not equal, to ignore text props.
984 (if (string-equal nodename
"*")
985 (progn (setq Info-current-node nodename
)
986 (Info-set-mode-line))
989 ;; 1. Anchor found in tag table
990 ;; 2. Anchor *not* in tag table
992 ;; 3. Node found in tag table
993 ;; 4. Node *not* found in tag table, but found in file
994 ;; 5. Node *not* in tag table, and *not* in file
996 ;; *Or* the same, but in an indirect subfile.
998 ;; Search file for a suitable node.
999 (let ((guesspos (point-min))
1000 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1001 (if (stringp nodename
)
1002 (regexp-quote nodename
)
1004 "\\) *[,\t\n\177]")))
1008 ;; First, search a tag table, if any
1009 (when (marker-position Info-tag-table-marker
)
1010 (let* ((m Info-tag-table-marker
)
1011 (found (Info-find-in-tag-table m regexp
)))
1014 ;; FOUND is (ANCHOR POS MODE).
1015 (setq guesspos
(nth 1 found
))
1017 ;; If this is an indirect file, determine which
1018 ;; file really holds this node and read it in.
1019 (unless (eq (nth 2 found
) 'Info-mode
)
1020 ;; Note that the current buffer must be the
1021 ;; *info* buffer on entry to
1022 ;; Info-read-subfile. Thus the hackery above.
1023 (setq guesspos
(Info-read-subfile guesspos
)))
1027 (goto-char (setq anchorpos guesspos
))
1030 ;; Else we may have a node, which we search for:
1031 (goto-char (max (point-min)
1032 (- (byte-to-position guesspos
) 1000)))
1034 ;; Now search from our advised position (or from beg of
1035 ;; buffer) to find the actual node. First, check
1036 ;; whether the node is right where we are, in case the
1037 ;; buffer begins with a node.
1038 (let ((pos (Info-find-node-in-buffer regexp
)))
1043 (when (string-match "\\([^.]+\\)\\." nodename
)
1044 (let (Info-point-loc)
1046 filename
(match-string 1 nodename
) no-going-back
))
1050 ;; No such anchor in tag table or node in tag table or file
1051 (error "No such node or anchor: %s" nodename
))
1054 (goto-char (point-min))
1055 (forward-line 1) ; skip header line
1056 (when (> Info-breadcrumbs-depth
0) ; skip breadcrumbs line
1060 (let ((new-history (list Info-current-file
1061 (substring-no-properties nodename
))))
1062 ;; Add anchors to the history too
1063 (setq Info-history-list
1065 (delete new-history Info-history-list
))))
1066 (goto-char anchorpos
))
1067 ((numberp Info-point-loc
)
1068 (forward-line (- Info-point-loc
2))
1069 (setq Info-point-loc nil
))
1070 ((stringp Info-point-loc
)
1071 (Info-find-index-name Info-point-loc
)
1072 (setq Info-point-loc nil
))))))
1073 ;; If we did not finish finding the specified node,
1074 ;; go back to the previous one.
1075 (or Info-current-node no-going-back
(null Info-history
)
1076 (let ((hist (car Info-history
)))
1077 (setq Info-history
(cdr Info-history
))
1078 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1079 (goto-char (nth 2 hist
))))))
1081 ;; Cache the contents of the (virtual) dir file, once we have merged
1082 ;; it for the first time, so we can save time subsequently.
1083 (defvar Info-dir-contents nil
)
1085 ;; Cache for the directory we decided to use for the default-directory
1086 ;; of the merged dir text.
1087 (defvar Info-dir-contents-directory nil
)
1089 ;; Record the file attributes of all the files from which we
1090 ;; constructed Info-dir-contents.
1091 (defvar Info-dir-file-attributes nil
)
1093 (defvar Info-dir-file-name nil
)
1095 ;; Construct the Info directory node by merging the files named `dir'
1096 ;; from various directories. Set the *info* buffer's
1097 ;; default-directory to the first directory we actually get any text
1099 (defun Info-insert-dir ()
1100 (if (and Info-dir-contents Info-dir-file-attributes
1101 ;; Verify that none of the files we used has changed
1102 ;; since we used it.
1104 (mapcar (lambda (elt)
1105 (let ((curr (file-attributes
1107 (file-truename (car elt
)))))
1109 ;; Don't compare the access time.
1110 (if curr
(setcar (nthcdr 4 curr
) 0))
1111 (setcar (nthcdr 4 (cdr elt
)) 0)
1112 (equal (cdr elt
) curr
)))
1113 Info-dir-file-attributes
))))
1115 (insert Info-dir-contents
)
1116 (goto-char (point-min)))
1117 (let ((dirs (if Info-additional-directory-list
1118 (append Info-directory-list
1119 Info-additional-directory-list
)
1120 Info-directory-list
))
1121 (dir-file-attrs nil
)
1122 ;; Bind this in case the user sets it to nil.
1123 (case-fold-search t
)
1124 ;; This is set non-nil if we find a problem in some input files.
1126 buffers buffer others nodes dirs-done
)
1128 ;; Search the directory list for the directory file.
1130 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1131 (or (member truename dirs-done
)
1132 (member (directory-file-name truename
) dirs-done
)
1133 ;; Try several variants of specified name.
1134 ;; Try upcasing, appending `.info', or both.
1138 (progn (setq file
(expand-file-name "dir" truename
))
1139 (file-attributes file
))
1140 (progn (setq file
(expand-file-name "DIR" truename
))
1141 (file-attributes file
))
1142 (progn (setq file
(expand-file-name "dir.info" truename
))
1143 (file-attributes file
))
1144 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1145 (file-attributes file
)))))
1148 (cons (directory-file-name truename
)
1151 (with-current-buffer (generate-new-buffer " info dir")
1153 (message "Composing main Info directory..."))
1155 ;; Index nodes include null bytes. DIR
1156 ;; files should not have indices, but who
1158 (let ((inhibit-null-byte-detection t
))
1159 (insert-file-contents file
)
1160 (set (make-local-variable 'Info-dir-file-name
)
1162 (push (current-buffer) buffers
)
1163 (push (cons file attrs
) dir-file-attrs
))
1164 (error (kill-buffer (current-buffer))))))))
1166 (set (make-local-variable 'Info-dir-contents-directory
)
1167 (file-name-as-directory (car dirs
))))
1168 (setq dirs
(cdr dirs
))))
1171 (error "Can't find the Info directory node"))
1173 ;; Distinguish the dir file that comes with Emacs from all the
1174 ;; others. Yes, that is really what this is supposed to do.
1175 ;; The definition of `Info-directory-list' puts it first on that
1176 ;; list and so last in `buffers' at this point.
1177 (setq buffer
(car (last buffers
))
1178 others
(delq buffer buffers
))
1180 ;; Insert the entire original dir file as a start; note that we've
1181 ;; already saved its default directory to use as the default
1182 ;; directory for the whole concatenation.
1183 (save-excursion (insert-buffer-substring buffer
))
1185 ;; Look at each of the other buffers one by one.
1186 (dolist (other others
)
1187 (let (this-buffer-nodes)
1188 ;; In each, find all the menus.
1189 (with-current-buffer other
1190 (goto-char (point-min))
1191 ;; Find each menu, and add an elt to NODES for it.
1192 (while (re-search-forward "^\\* Menu:" nil t
)
1193 (while (and (zerop (forward-line 1)) (eolp)))
1196 (re-search-backward "^\^_")
1197 (search-forward "Node: ")
1198 (setq nodename
(Info-following-node-name))
1199 (search-forward "\n\^_" nil
'move
)
1202 (push (list nodename other beg end
) this-buffer-nodes
)))
1203 (if (assoc-string "top" this-buffer-nodes t
)
1204 (setq nodes
(nconc this-buffer-nodes nodes
))
1206 (message "No `top' node in %s" Info-dir-file-name
)))))
1207 ;; Add to the main menu a menu item for each other node.
1208 (re-search-forward "^\\* Menu:")
1210 (let ((menu-items '("top"))
1211 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1212 (dolist (node nodes
)
1213 (let ((nodename (car node
)))
1215 (or (member (downcase nodename
) menu-items
)
1216 (re-search-forward (concat "^\\* +"
1217 (regexp-quote nodename
)
1221 (insert "* " nodename
"::" "\n")
1222 (push nodename menu-items
)))))))
1223 ;; Now take each node of each of the other buffers
1224 ;; and merge it into the main buffer.
1225 (dolist (node nodes
)
1226 (let ((case-fold-search t
)
1227 (nodename (car node
)))
1228 (goto-char (point-min))
1229 ;; Find the like-named node in the main buffer.
1230 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1231 (regexp-quote nodename
)
1235 (search-forward "\n\^_" nil
'move
)
1238 ;; If none exists, add one.
1239 (goto-char (point-max))
1240 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1241 ;; Merge the text from the other buffer's menu
1242 ;; into the menu in the like-named node in the main buffer.
1243 (apply 'insert-buffer-substring
(cdr node
))))
1244 (Info-dir-remove-duplicates)
1245 ;; Kill all the buffers we just made, including the special one excised.
1246 (mapc 'kill-buffer
(cons buffer buffers
))
1247 (goto-char (point-min))
1249 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1250 (message "Composing main Info directory...done"))
1251 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1252 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1253 (setq default-directory Info-dir-contents-directory
))
1255 (defvar Info-streamline-headings
1256 '(("Emacs" .
"Emacs")
1257 ("Programming" .
"Programming")
1258 ("Libraries" .
"Libraries")
1259 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1260 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1262 (defun Info-dir-remove-duplicates ()
1264 (goto-char (point-min))
1265 ;; Remove duplicate headings in the same menu.
1266 (while (search-forward "\n* Menu:" nil t
)
1267 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1268 ;; Look for the next heading to unify.
1269 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1270 (let ((name (match-string 1))
1271 (start (match-beginning 0))
1273 ;; Check whether this heading should be streamlined.
1275 (dolist (x Info-streamline-headings
)
1276 (when (string-match (car x
) name
)
1278 (setq re
(car x
)))))
1279 (if re
(replace-match name t t nil
1))
1280 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1282 (or limit
(point-max))))
1283 ;; Look for other headings of the same category and merge them.
1285 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1286 (when (if re
(save-match-data (string-match re
(match-string 1)))
1287 (equal name
(match-string 1)))
1289 ;; Delete redundant heading.
1290 (delete-region (match-beginning 0) (point))
1291 ;; Push the entries onto `text'.
1293 (delete-and-extract-region
1295 (if (re-search-forward "^[^* \n\t]" nil t
)
1297 (or limit
(point-max))))
1300 ;; Insert the entries just found.
1301 (while (= (line-beginning-position 0) (1- (point)))
1303 (dolist (entry (nreverse entries
))
1305 (while (= (line-beginning-position 0) (1- (point)))
1306 (delete-region (1- (point)) (point))))
1308 ;; Now remove duplicate entries under the same heading.
1311 (narrow-to-region start
(point))
1312 (goto-char (point-min))
1313 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1314 ;; Fold case straight away; `member-ignore-case' here wasteful.
1315 (let ((x (downcase (match-string 1))))
1319 (if (re-search-forward "^[^ \t]" nil
'move
)
1320 (goto-char (match-beginning 0))
1322 (push x seen
)))))))))))
1324 ;; Note that on entry to this function the current-buffer must be the
1325 ;; *info* buffer; not the info tags buffer.
1326 (defun Info-read-subfile (nodepos)
1327 ;; NODEPOS is either a position (in the Info file as a whole,
1328 ;; not relative to a subfile) or the name of a subfile.
1331 (if (numberp nodepos
)
1332 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1333 (goto-char (point-min))
1334 (or (looking-at "\^_")
1335 (search-forward "\n\^_"))
1338 (while (not (looking-at "\^_"))
1341 thisfilepos thisfilename
)
1342 (search-forward ": ")
1343 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1344 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1345 ;; read in version 19 stops at the end of number.
1346 ;; Advance to the next line.
1348 (if (> thisfilepos nodepos
)
1350 (setq lastfilename thisfilename
)
1351 (setq lastfilepos thisfilepos
))
1352 (forward-line 1)))))
1353 (setq lastfilename nodepos
)
1354 (setq lastfilepos
0))
1355 ;; Assume previous buffer is in Info-mode.
1356 ;; (set-buffer (get-buffer "*info*"))
1357 (or (equal Info-current-subfile lastfilename
)
1358 (let ((inhibit-read-only t
))
1359 (setq buffer-file-name nil
)
1362 (info-insert-file-contents lastfilename
)
1363 (set-buffer-modified-p nil
)
1364 (setq Info-current-subfile lastfilename
)))
1365 ;; Widen in case we are in the same subfile as before.
1367 (goto-char (point-min))
1368 (if (looking-at "\^_")
1370 (search-forward "\n\^_"))
1371 (if (numberp nodepos
)
1372 (+ (- nodepos lastfilepos
) (point)))))
1374 (defun Info-unescape-quotes (value)
1375 "Unescape double quotes and backslashes in VALUE."
1378 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1379 (setq unquote
(replace-match "" t t unquote
1))
1380 (setq start
(- (match-end 0) 1)))
1383 ;; As of Texinfo 4.6, makeinfo writes constructs like
1384 ;; \0\h[image param=value ...\h\0]
1385 ;; into the Info file for handling images.
1386 (defun Info-split-parameter-string (parameter-string)
1387 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1388 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1389 whitespace or double quotes, it must be quoted in double quotes and
1390 any double quotes or backslashes must be escaped (\\\",\\\\)."
1393 (while (string-match
1394 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1395 parameter-string start
)
1396 (setq start
(match-end 0))
1397 (push (cons (match-string 1 parameter-string
)
1398 (or (match-string 2 parameter-string
)
1399 (Info-unescape-quotes
1400 (match-string 3 parameter-string
))))
1404 (defun Info-display-images-node ()
1405 "Display images in current node."
1407 (let ((inhibit-read-only t
)
1408 (case-fold-search t
))
1409 (goto-char (point-min))
1410 (while (re-search-forward
1411 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1413 (let* ((start (match-beginning 1))
1414 (parameter-alist (Info-split-parameter-string (match-string 2)))
1415 (src (cdr (assoc-string "src" parameter-alist
))))
1416 (if (display-images-p)
1417 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1418 (concat default-directory src
))
1420 (image (if (file-exists-p image-file
)
1421 (create-image image-file
)
1423 (if (not (get-text-property start
'display
))
1424 (add-text-properties
1425 start
(point) `(display ,image rear-nonsticky
(display)))))
1426 ;; text-only display, show alternative text if provided, or
1427 ;; otherwise a clue that there's meant to be a picture
1428 (delete-region start
(point))
1429 (insert (or (cdr (assoc-string "text" parameter-alist
))
1430 (cdr (assoc-string "alt" parameter-alist
))
1432 (concat "[image:" src
"]"))
1434 (set-buffer-modified-p nil
)))
1436 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1437 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1438 ;; including one optional trailing newline.
1439 (defun Info-hide-cookies-node ()
1440 "Hide unrecognized cookies in current node."
1442 (let ((inhibit-read-only t
)
1443 (case-fold-search t
))
1444 (goto-char (point-min))
1445 (while (re-search-forward
1446 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1448 (let* ((start (match-beginning 1)))
1449 (if (and (not (get-text-property start
'invisible
))
1450 (not (get-text-property start
'display
)))
1451 (put-text-property start
(point) 'invisible t
)))))
1452 (set-buffer-modified-p nil
)))
1454 (defun Info-select-node ()
1455 "Select the Info node that point is in."
1456 ;; Bind this in case the user sets it to nil.
1457 (let ((case-fold-search t
))
1459 ;; Find beginning of node.
1460 (if (search-backward "\n\^_" nil
'move
)
1462 (if (looking-at "\^_")
1464 (signal 'search-failed
(list "\n\^_"))))
1465 ;; Get nodename spelled as it is in the node.
1466 (re-search-forward "Node:[ \t]*")
1467 (setq Info-current-node
1468 (buffer-substring-no-properties (point)
1470 (skip-chars-forward "^,\t\n")
1472 (Info-set-mode-line)
1473 ;; Find the end of it, and narrow.
1475 (let (active-expression)
1476 ;; Narrow to the node contents
1477 (narrow-to-region (point)
1478 (if (re-search-forward "\n[\^_\f]" nil t
)
1481 (if (looking-at "[\n\^_\f]*execute: ")
1483 (goto-char (match-end 0))
1484 (setq active-expression
1485 (read (current-buffer))))))
1487 (if Info-enable-active-nodes
(eval active-expression
))
1488 ;; Add a new unique history item to full history list
1489 (let ((new-history (list Info-current-file Info-current-node
)))
1490 (setq Info-history-list
1491 (cons new-history
(delete new-history Info-history-list
)))
1492 (setq Info-history-forward nil
))
1493 (if (not (eq Info-fontify-maximum-menu-size nil
))
1494 (Info-fontify-node))
1495 (Info-display-images-node)
1496 (Info-hide-cookies-node)
1497 (run-hooks 'Info-selection-hook
)))))
1499 (defvar Info-mode-line-node-keymap
1500 (let ((map (make-sparse-keymap)))
1501 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1502 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1504 "Keymap to put on the Info node name in the mode line.")
1506 (defun Info-set-mode-line ()
1507 (setq mode-line-buffer-identification
1508 (nconc (propertized-buffer-identification "%b")
1512 (if (stringp Info-current-file
)
1513 (replace-regexp-in-string
1514 "%" "%%" (file-name-nondirectory Info-current-file
))
1515 (format "*%S*" Info-current-file
))
1517 (if Info-current-node
1518 (propertize (replace-regexp-in-string
1519 "%" "%%" Info-current-node
)
1520 'face
'mode-line-buffer-id
1522 "mouse-1: scroll forward, mouse-3: scroll back"
1523 'mouse-face
'mode-line-highlight
1524 'local-map Info-mode-line-node-keymap
)
1527 ;; Go to an Info node specified with a filename-and-nodename string
1528 ;; of the sort that is found in pointers in nodes.
1530 ;; Don't autoload this function: the correct entry point for other packages
1531 ;; to use is `info'. --Stef
1533 (defun Info-goto-node (nodename &optional fork
)
1534 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1535 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1536 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1538 Completion is available, but only for node names in the current Info file.
1539 If FORK is non-nil (interactively with a prefix arg), show the node in
1541 If FORK is a string, it is the name to use for the new buffer."
1542 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1546 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1548 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1550 (setq filename
(if (= (match-beginning 1) (match-end 1))
1552 (match-string 2 nodename
))
1553 nodename
(match-string 3 nodename
))
1554 (let ((trim (string-match "\\s +\\'" filename
)))
1555 (if trim
(setq filename
(substring filename
0 trim
))))
1556 (let ((trim (string-match "\\s +\\'" nodename
)))
1557 (if trim
(setq nodename
(substring nodename
0 trim
))))
1558 (if transient-mark-mode
(deactivate-mark))
1559 (Info-find-node (if (equal filename
"") nil filename
)
1560 (if (equal nodename
"") "Top" nodename
))))
1562 (defvar Info-read-node-completion-table
)
1564 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1565 "Virtual completion table for file names input in Info node names.
1566 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1567 (setq suffixes
(remove "" suffixes
))
1568 (when (file-name-absolute-p string
)
1569 (setq dirs
(list (file-name-directory string
))))
1571 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1572 (string-dir (file-name-directory string
)))
1575 (setq dir default-directory
))
1576 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1577 (when (file-directory-p dir
)
1578 (dolist (file (file-name-all-completions
1579 (file-name-nondirectory string
) dir
))
1580 ;; If the file name has no suffix or a standard suffix,
1582 (and (or (null (file-name-extension file
))
1583 (string-match suffix file
))
1584 ;; But exclude subfiles of split Info files.
1585 (not (string-match "-[0-9]+\\'" file
))
1586 ;; And exclude backup files.
1587 (not (string-match "~\\'" file
))
1588 (push (if string-dir
(concat string-dir file
) file
) names
))
1589 ;; If the file name ends in a standard suffix,
1590 ;; add the unsuffixed name as a completion option.
1591 (when (string-match suffix file
)
1592 (setq file
(substring file
0 (match-beginning 0)))
1593 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1594 (complete-with-action action names string pred
)))
1596 ;; This function is used as the "completion table" while reading a node name.
1597 ;; It does completion using the alist in Info-read-node-completion-table
1598 ;; unless STRING starts with an open-paren.
1599 (defun Info-read-node-name-1 (string predicate code
)
1601 ;; First complete embedded file names.
1602 ((string-match "\\`([^)]*\\'" string
)
1603 (completion-table-with-context
1605 (apply-partially 'completion-table-with-terminator
")"
1606 (apply-partially 'Info-read-node-name-2
1608 (mapcar 'car Info-suffix-list
)))
1609 (substring string
1)
1613 ;; If a file name was given, then any node is fair game.
1614 ((string-match "\\`(" string
)
1616 ((eq code nil
) string
)
1619 ;; Otherwise use Info-read-node-completion-table.
1620 (t (complete-with-action
1621 code Info-read-node-completion-table string predicate
))))
1623 ;; Arrange to highlight the proper letters in the completion list buffer.
1626 (defun Info-read-node-name (prompt)
1627 (let* ((completion-ignore-case t
)
1628 (Info-read-node-completion-table (Info-build-node-completions))
1629 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1630 (if (equal nodename
"")
1631 (Info-read-node-name prompt
)
1634 (defun Info-build-node-completions ()
1635 (or Info-current-file-completions
1637 ;; Bind this in case the user sets it to nil.
1638 (case-fold-search t
)
1639 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1642 (or Info-tag-table-marker
1643 (error "No Info tags found"))
1644 (if (marker-buffer Info-tag-table-marker
)
1645 (let ((marker Info-tag-table-marker
))
1646 (set-buffer (marker-buffer marker
))
1649 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1651 (cons (list (match-string-no-properties 2))
1654 (goto-char (point-min))
1655 ;; If the buffer begins with a node header, process that first.
1656 (if (Info-node-at-bob-matching node-regexp
)
1657 (setq compl
(list (match-string-no-properties 1))))
1658 ;; Now for the rest of the nodes.
1659 (while (search-forward "\n\^_" nil t
)
1661 (let ((beg (point)))
1663 (if (re-search-backward node-regexp beg t
)
1665 (cons (list (match-string-no-properties 1))
1667 (setq compl
(cons '("*") compl
))
1668 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1670 (defun Info-restore-point (hl)
1671 "If this node has been visited, restore the point value when we left."
1673 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1674 ;; Use string-equal, not equal, to ignore text props.
1675 (string-equal (nth 1 (car hl
)) Info-current-node
))
1677 (goto-char (nth 2 (car hl
)))
1678 (setq hl nil
)) ;terminate the while at next iter
1679 (setq hl
(cdr hl
)))))
1681 (defvar Info-search-history nil
1682 "The history list for `Info-search'.")
1684 (defvar Info-search-case-fold nil
1685 "The value of `case-fold-search' from previous `Info-search' command.")
1687 (defun Info-search (regexp &optional bound noerror count direction
)
1688 "Search for REGEXP, starting from point, and select node it's found in.
1689 If DIRECTION is `backward', search in the reverse direction."
1690 (interactive (list (read-string
1691 (if Info-search-history
1692 (format "Regexp search%s (default %s): "
1693 (if case-fold-search
"" " case-sensitively")
1694 (car Info-search-history
))
1695 (format "Regexp search%s: "
1696 (if case-fold-search
"" " case-sensitively")))
1697 nil
'Info-search-history
)))
1699 (when (equal regexp
"")
1700 (setq regexp
(car Info-search-history
)))
1702 (let (found beg-found give-up
1703 (backward (eq direction
'backward
))
1704 (onode Info-current-node
)
1705 (ofile Info-current-file
)
1707 (opoint-min (point-min))
1708 (opoint-max (point-max))
1709 (ostart (window-start))
1710 (osubfile Info-current-subfile
))
1711 (setq Info-search-case-fold case-fold-search
)
1716 ;; Hide Info file header for backward search
1717 (narrow-to-region (save-excursion
1718 (goto-char (point-min))
1719 (search-forward "\n\^_")
1722 (while (and (not give-up
)
1724 (not (funcall isearch-filter-predicate beg-found found
))))
1725 (let ((search-spaces-regexp
1726 (if (or (not isearch-mode
) isearch-regexp
)
1727 Info-search-whitespace-regexp
)))
1729 (re-search-backward regexp bound t
)
1730 (re-search-forward regexp bound t
))
1731 (setq found
(point) beg-found
(if backward
(match-end 0)
1732 (match-beginning 0)))
1733 (setq give-up t
))))))
1735 (when (and isearch-mode Info-isearch-search
1736 (not Info-isearch-initial-node
)
1738 (or give-up
(and found
(not (and (> found opoint-min
)
1739 (< found opoint-max
))))))
1740 (signal 'search-failed
(list regexp
"initial node")))
1742 ;; If no subfiles, give error now.
1744 (if (null Info-current-subfile
)
1745 (let ((search-spaces-regexp
1746 (if (or (not isearch-mode
) isearch-regexp
)
1747 Info-search-whitespace-regexp
)))
1749 (re-search-backward regexp
)
1750 (re-search-forward regexp
)))
1753 (if (and bound
(not found
))
1754 (signal 'search-failed
(list regexp
)))
1756 (unless (or found bound
)
1758 ;; Try other subfiles.
1760 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1761 (goto-char (point-min))
1762 (search-forward "\n\^_\nIndirect:")
1764 (narrow-to-region (point)
1765 (progn (search-forward "\n\^_")
1767 (goto-char (point-min))
1768 ;; Find the subfile we just searched.
1769 (search-forward (concat "\n" osubfile
": "))
1771 (forward-line (if backward
0 1))
1772 (if backward
(forward-char -
1))
1773 ;; Make a list of all following subfiles.
1774 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1775 (while (not (if backward
(bobp) (eobp)))
1777 (re-search-backward "\\(^.*\\): [0-9]+$")
1778 (re-search-forward "\\(^.*\\): [0-9]+$"))
1779 (goto-char (+ (match-end 1) 2))
1780 (setq list
(cons (cons (+ (point-min)
1781 (read (current-buffer)))
1782 (match-string-no-properties 1))
1784 (goto-char (if backward
1785 (1- (match-beginning 0))
1786 (1+ (match-end 0)))))
1787 ;; Put in forward order
1788 (setq list
(nreverse list
))))
1790 (message "Searching subfile %s..." (cdr (car list
)))
1791 (Info-read-subfile (car (car list
)))
1793 ;; Hide Info file header for backward search
1794 (narrow-to-region (save-excursion
1795 (goto-char (point-min))
1796 (search-forward "\n\^_")
1799 (goto-char (point-max)))
1800 (setq list
(cdr list
))
1801 (setq give-up nil found nil
)
1802 (while (and (not give-up
)
1804 (not (funcall isearch-filter-predicate beg-found found
))))
1805 (let ((search-spaces-regexp
1806 (if (or (not isearch-mode
) isearch-regexp
)
1807 Info-search-whitespace-regexp
)))
1809 (re-search-backward regexp nil t
)
1810 (re-search-forward regexp nil t
))
1811 (setq found
(point) beg-found
(if backward
(match-end 0)
1812 (match-beginning 0)))
1820 (signal 'search-failed
(list regexp
))))
1822 (progn (Info-read-subfile osubfile
)
1825 (set-window-start (selected-window) ostart
)))))
1827 (if (and (string= osubfile Info-current-subfile
)
1828 (> found opoint-min
)
1829 (< found opoint-max
))
1830 ;; Search landed in the same node
1834 (save-match-data (Info-select-node)))
1836 ;; Use string-equal, not equal, to ignore text props.
1837 (or (and (string-equal onode Info-current-node
)
1838 (equal ofile Info-current-file
))
1839 (and isearch-mode isearch-wrapped
1840 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1841 (setq Info-history
(cons (list ofile onode opoint
)
1844 (defun Info-search-case-sensitively ()
1845 "Search for a regexp case-sensitively."
1847 (let ((case-fold-search nil
))
1848 (call-interactively 'Info-search
)))
1850 (defun Info-search-next ()
1851 "Search for next regexp from a previous `Info-search' command."
1853 (let ((case-fold-search Info-search-case-fold
))
1854 (if Info-search-history
1855 (Info-search (car Info-search-history
))
1856 (call-interactively 'Info-search
))))
1858 (defun Info-search-backward (regexp &optional bound noerror count
)
1859 "Search for REGEXP in the reverse direction."
1860 (interactive (list (read-string
1861 (if Info-search-history
1862 (format "Regexp search%s backward (default %s): "
1863 (if case-fold-search
"" " case-sensitively")
1864 (car Info-search-history
))
1865 (format "Regexp search%s backward: "
1866 (if case-fold-search
"" " case-sensitively")))
1867 nil
'Info-search-history
)))
1868 (Info-search regexp bound noerror count
'backward
))
1870 (defun Info-isearch-search ()
1871 (if Info-isearch-search
1872 (lambda (string &optional bound noerror count
)
1874 (Info-search (concat "\\b" (replace-regexp-in-string
1876 (replace-regexp-in-string
1877 "^\\W+\\|\\W+$" "" string
)
1879 ;; Lax version of word search
1880 (if (or isearch-nonincremental
1882 (length (isearch-string-state
1883 (car isearch-cmds
)))))
1886 (unless isearch-forward
'backward
))
1887 (Info-search (if isearch-regexp string
(regexp-quote string
))
1889 (unless isearch-forward
'backward
)))
1891 (let ((isearch-search-fun-function nil
))
1892 (isearch-search-fun))))
1894 (defun Info-isearch-wrap ()
1895 (if Info-isearch-search
1896 (if Info-isearch-initial-node
1898 (if isearch-forward
(Info-top-node) (Info-final-node))
1899 (goto-char (if isearch-forward
(point-min) (point-max))))
1900 (setq Info-isearch-initial-node Info-current-node
)
1901 (setq isearch-wrapped nil
))
1902 (goto-char (if isearch-forward
(point-min) (point-max)))))
1904 (defun Info-isearch-push-state ()
1906 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
1908 (defun Info-isearch-pop-state (cmd file node
)
1909 (or (and (equal Info-current-file file
)
1910 (equal Info-current-node node
))
1911 (progn (Info-find-node file node
) (sit-for 0))))
1913 (defun Info-isearch-start ()
1914 (setq Info-isearch-initial-node
1915 ;; Don't stop at initial node for nonincremental search.
1916 ;; Otherwise this variable is set after first search failure.
1917 (and isearch-nonincremental Info-current-node
)))
1919 (defun Info-isearch-filter (beg-found found
)
1920 "Test whether the current search hit is a visible useful text.
1921 Return non-nil if the text from BEG-FOUND to FOUND is visible
1922 and is not in the header line or a tag table."
1924 (let ((backward (< found beg-found
)))
1927 (and (not (eq search-invisible t
))
1929 (or (text-property-not-all found beg-found
'invisible nil
)
1930 (text-property-not-all found beg-found
'display nil
))
1931 (or (text-property-not-all beg-found found
'invisible nil
)
1932 (text-property-not-all beg-found found
'display nil
))))
1933 ;; Skip node header line
1934 (and (save-excursion (forward-line -
1)
1936 (forward-line (if backward -
1 1)))
1937 ;; Skip Tag Table node
1939 (and (search-backward "\^_" nil t
)
1941 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1944 (defun Info-extract-pointer (name &optional errorname
)
1945 "Extract the value of the node-pointer named NAME.
1946 If there is none, use ERRORNAME in the error message;
1947 if ERRORNAME is nil, just return nil."
1948 ;; Bind this in case the user sets it to nil.
1949 (let ((case-fold-search t
))
1951 (goto-char (point-min))
1952 (let ((bound (point)))
1954 (cond ((re-search-backward
1955 (concat name
":" (Info-following-node-name-re)) bound t
)
1956 (match-string-no-properties 1))
1957 ((not (eq errorname t
))
1958 (error "Node has no %s"
1959 (capitalize (or errorname name
)))))))))
1961 (defun Info-following-node-name-re (&optional allowedchars
)
1962 "Return a regexp matching a node name.
1963 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1964 saying which chars may appear in the node name.
1965 Submatch 1 is the complete node name.
1966 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1967 Submatch 3 is the local part of the node name.
1968 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1969 (concat "[ \t]*" ;Skip leading space.
1970 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1971 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1972 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1973 "\\|\\)\\)")) ;Allow empty node names.
1975 ;;; For compatibility; other files have used this name.
1976 (defun Info-following-node-name ()
1977 (and (looking-at (Info-following-node-name-re))
1978 (match-string-no-properties 1)))
1981 "Go to the next node of this node."
1983 ;; In case another window is currently selected
1984 (save-window-excursion
1985 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
1986 (Info-goto-node (Info-extract-pointer "next"))))
1989 "Go to the previous node of this node."
1991 ;; In case another window is currently selected
1992 (save-window-excursion
1993 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
1994 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
1996 (defun Info-up (&optional same-file
)
1997 "Go to the superior node of this node.
1998 If SAME-FILE is non-nil, do not move to a different Info file."
2000 ;; In case another window is currently selected
2001 (save-window-excursion
2002 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
2003 (let ((old-node Info-current-node
)
2004 (old-file Info-current-file
)
2005 (node (Info-extract-pointer "up")) p
)
2007 (string-match "^(" node
)
2008 (error "Up node is in another Info file"))
2009 (Info-goto-node node
)
2011 (goto-char (point-min))
2012 (if (and (stringp old-file
)
2013 (search-forward "\n* Menu:" nil t
)
2015 (if (string-equal old-node
"Top")
2016 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2017 (concat "\n\\* +\\(" (regexp-quote old-node
)
2018 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2020 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2022 (Info-restore-point Info-history
)))))
2024 (defun Info-history-back ()
2025 "Go back in the history to the last node visited."
2028 (error "This is the first Info node you looked at"))
2029 (let ((history-forward
2030 (cons (list Info-current-file Info-current-node
(point))
2031 Info-history-forward
))
2032 filename nodename opoint
)
2033 (setq filename
(car (car Info-history
)))
2034 (setq nodename
(car (cdr (car Info-history
))))
2035 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2036 (setq Info-history
(cdr Info-history
))
2037 (Info-find-node filename nodename
)
2038 (setq Info-history
(cdr Info-history
))
2039 (setq Info-history-forward history-forward
)
2040 (goto-char opoint
)))
2042 (defalias 'Info-last
'Info-history-back
)
2044 (defun Info-history-forward ()
2045 "Go forward in the history of visited nodes."
2047 (or Info-history-forward
2048 (error "This is the last Info node you looked at"))
2049 (let ((history-forward (cdr Info-history-forward
))
2050 filename nodename opoint
)
2051 (setq filename
(car (car Info-history-forward
)))
2052 (setq nodename
(car (cdr (car Info-history-forward
))))
2053 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2054 (Info-find-node filename nodename
)
2055 (setq Info-history-forward history-forward
)
2056 (goto-char opoint
)))
2058 (add-to-list 'Info-virtual-files
2060 (toc-nodes . Info-directory-toc-nodes
)
2061 (find-file . Info-directory-find-file
)
2062 (find-node . Info-directory-find-node
)
2065 (defun Info-directory-toc-nodes (filename)
2066 "Directory-specific implementation of Info-directory-toc-nodes."
2068 ("Top" nil nil nil
)))
2070 (defun Info-directory-find-file (filename &optional noerror
)
2071 "Directory-specific implementation of Info-find-file."
2074 (defun Info-directory-find-node (filename nodename
&optional no-going-back
)
2075 "Directory-specific implementation of Info-find-node-2."
2079 (defun Info-directory ()
2080 "Go to the Info directory node."
2082 (Info-find-node "dir" "top"))
2084 (add-to-list 'Info-virtual-files
2085 '("\\`\\*History\\*\\'"
2086 (toc-nodes . Info-history-toc-nodes
)
2087 (find-file . Info-history-find-file
)
2088 (find-node . Info-history-find-node
)
2091 (defun Info-history-toc-nodes (filename)
2092 "History-specific implementation of Info-history-toc-nodes."
2094 ("Top" nil nil nil
)))
2096 (defun Info-history-find-file (filename &optional noerror
)
2097 "History-specific implementation of Info-find-file."
2100 (defun Info-history-find-node (filename nodename
&optional no-going-back
)
2101 "History-specific implementation of Info-find-node-2."
2102 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2103 (or filename Info-current-file
) nodename
))
2104 (insert "Recently Visited Nodes\n")
2105 (insert "**********************\n\n")
2106 (insert "* Menu:\n\n")
2107 (let ((hl (delete '("*History*" "Top") Info-history-list
)))
2109 (let ((file (nth 0 (car hl
)))
2110 (node (nth 1 (car hl
))))
2112 (insert "* " node
": ("
2113 (propertize (or (file-name-directory file
) "") 'invisible t
)
2114 (file-name-nondirectory file
)
2116 (setq hl
(cdr hl
)))))
2118 (defun Info-history ()
2119 "Go to a node with a menu of visited nodes."
2121 (Info-find-node "*History*" "Top")
2122 (Info-next-reference)
2123 (Info-next-reference))
2125 (add-to-list 'Info-virtual-nodes
2127 (find-node . Info-toc-find-node
)
2130 (defun Info-toc-find-node (filename nodename
&optional no-going-back
)
2131 "Toc-specific implementation of Info-find-node-2."
2132 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2133 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2134 (node-list (Info-toc-nodes curr-file
)))
2135 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2136 curr-file curr-node
))
2137 (insert "Table of Contents\n")
2138 (insert "*****************\n\n")
2139 (insert "*Note Top::\n")
2141 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2142 node-list
0 curr-file
)
2144 (let ((Info-hide-note-references 'hide
)
2145 (Info-fontify-visited-nodes nil
))
2146 (setq Info-current-file filename Info-current-node
"*TOC*")
2147 (goto-char (point-min))
2148 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2155 "Go to a node with table of contents of the current Info file.
2156 Table of contents is created from the tree structure of menus."
2158 (Info-find-node Info-current-file
"*TOC*")
2159 (let ((prev-node (nth 1 (car Info-history
))) p
)
2160 (goto-char (point-min))
2161 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2162 (setq p
(- p
(length prev-node
) 2)))
2163 (goto-char (or p
(point-min)))))
2165 (defun Info-toc-insert (nodes node-list level curr-file
)
2166 "Insert table of contents with references to nodes."
2167 (let ((section "Top"))
2169 (let ((node (assoc (car nodes
) node-list
)))
2170 (unless (member (nth 2 node
) (list nil section
))
2171 (insert (setq section
(nth 2 node
)) "\n"))
2172 (insert (make-string level ?
\t))
2173 (insert "*Note " (car nodes
) ":: \n")
2174 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2175 (setq nodes
(cdr nodes
))))))
2177 (defun Info-toc-build (file)
2178 "Build table of contents from menus of Info FILE and its subfiles."
2180 (let* ((file (and (stringp file
) (Info-find-file file
)))
2181 (default-directory (or (and (stringp file
)
2182 (file-name-directory file
))
2184 (main-file (and (stringp file
) file
))
2185 (sections '(("Top" "Top")))
2187 (while (or main-file subfiles
)
2188 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2190 (info-insert-file-contents (or main-file
(car subfiles
)))
2191 (goto-char (point-min))
2192 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2193 (search-forward "Node: " nil
'move
))
2194 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2195 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2197 (upnode (and (re-search-forward
2198 (concat "Up:" (Info-following-node-name-re))
2200 (match-string-no-properties 1)))
2203 (when (string-match "(" upnode
) (setq upnode nil
))
2204 (when (and (not (Info-index-node nodename file
))
2205 (re-search-forward "^\\* Menu:" bound t
))
2208 (setq bound
(or (and (equal nodename
"Top")
2211 "^[ \t-]*The Detailed Node Listing" nil t
)))
2213 (while (< (point) bound
)
2216 ((looking-at "^\\* +[^:]+:")
2219 (let ((menu-node-name (substring-no-properties
2220 (Info-extract-menu-node-name))))
2221 (setq menu-items
(cons menu-node-name menu-items
))
2222 (if (equal nodename
"Top")
2224 (cons (list menu-node-name section
) sections
)))))
2225 ;; Other non-empty strings in the Top node are section names
2226 ((and (equal nodename
"Top")
2227 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2228 (setq section
(match-string-no-properties 1))))
2230 (beginning-of-line)))
2231 (setq nodes
(cons (list nodename upnode
2232 (cadr (assoc nodename sections
))
2233 (nreverse menu-items
))
2238 (goto-char (point-min))
2239 (if (search-forward "\n\^_\nIndirect:" nil t
)
2240 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2241 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2242 (setq subfiles
(cons (match-string-no-properties 1)
2244 (setq subfiles
(nreverse subfiles
)
2246 (setq subfiles
(cdr subfiles
))))
2250 (defvar Info-toc-nodes nil
2251 "Alist of cached parent-children node information in visited Info files.
2252 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2253 where PARENT is the parent node extracted from the Up pointer,
2254 SECTION is the section name in the Top node where this node is placed,
2255 CHILDREN is a list of child nodes extracted from the node menu.")
2257 (defun Info-toc-nodes (filename)
2258 "Return a node list of Info FILENAME with parent-children information.
2259 This information is cached in the variable `Info-toc-nodes' with the help
2260 of the function `Info-toc-build'."
2263 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2266 (or filename
(setq filename Info-current-file
))
2267 (or (assoc filename Info-toc-nodes
)
2268 ;; Skip virtual Info files
2269 (and (or (not (stringp filename
))
2270 (Info-virtual-file-p filename
))
2271 (push (cons filename nil
) Info-toc-nodes
))
2272 ;; Scan the entire manual and cache the result in Info-toc-nodes
2273 (let ((nodes (Info-toc-build filename
)))
2274 (push (cons filename nodes
) Info-toc-nodes
)
2276 ;; If there is an error, still add nil to the cache
2277 (push (cons filename nil
) Info-toc-nodes
))
2278 (cdr (assoc filename Info-toc-nodes
)))))
2281 (defun Info-follow-reference (footnotename &optional fork
)
2282 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2283 FOOTNOTENAME may be an abbreviation of the reference name.
2284 If FORK is non-nil (interactively with a prefix arg), show the node in
2285 a new Info buffer. If FORK is a string, it is the name to use for the
2288 (let ((completion-ignore-case t
)
2289 (case-fold-search t
)
2290 completions default alt-default
(start-point (point)) str i bol eol
)
2292 ;; Store end and beginning of line.
2298 (goto-char (point-min))
2299 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2300 (setq str
(match-string-no-properties 1))
2301 ;; See if this one should be the default.
2303 (<= (match-beginning 0) start-point
)
2304 (<= start-point
(point))
2306 ;; See if this one should be the alternate default.
2307 (and (null alt-default
)
2308 (and (<= bol
(match-beginning 0))
2310 (setq alt-default t
))
2312 (while (setq i
(string-match "[ \n\t]+" str i
))
2313 (setq str
(concat (substring str
0 i
) " "
2314 (substring str
(match-end 0))))
2316 ;; Record as a completion and perhaps as default.
2317 (if (eq default t
) (setq default str
))
2318 (if (eq alt-default t
) (setq alt-default str
))
2319 ;; Don't add this string if it's a duplicate.
2320 (or (assoc-string str completions t
)
2321 (push str completions
))))
2322 ;; If no good default was found, try an alternate.
2324 (setq default alt-default
))
2325 ;; If only one cross-reference found, then make it default.
2326 (if (eq (length completions
) 1)
2327 (setq default
(car completions
)))
2329 (let ((input (completing-read (if default
2331 "Follow reference named (default "
2333 "Follow reference named: ")
2334 completions nil t
)))
2335 (list (if (equal input
"")
2336 default input
) current-prefix-arg
))
2337 (error "No cross-references in this node"))))
2339 (unless footnotename
2340 (error "No reference was specified"))
2342 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2343 (case-fold-search t
))
2344 (while (setq i
(string-match " " str i
))
2345 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2348 ;; Move point to the beginning of reference if point is on reference
2349 (or (looking-at "\\*note[ \n\t]+")
2350 (and (looking-back "\\*note[ \n\t]+")
2351 (goto-char (match-beginning 0)))
2352 (if (and (save-excursion
2353 (goto-char (+ (point) 5)) ; skip a possible *note
2354 (re-search-backward "\\*note[ \n\t]+" nil t
)
2356 (<= (point) (match-end 0)))
2357 (goto-char (match-beginning 0))))
2358 ;; Go to the reference closest to point
2359 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2360 (+ (match-beginning 0) 5))))
2361 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2362 (+ (match-beginning 0) 5)))))
2363 (goto-char (cond ((and next-ref prev-ref
)
2364 (if (< (abs (- next-ref
(point)))
2365 (abs (- prev-ref
(point))))
2367 ((or next-ref prev-ref
))
2368 ((error "No cross-reference named %s" footnotename
))))
2369 (setq target
(Info-extract-menu-node-name t
))))
2370 (while (setq i
(string-match "[ \t\n]+" target i
))
2371 (setq target
(concat (substring target
0 i
) " "
2372 (substring target
(match-end 0))))
2374 (Info-goto-node target fork
)))
2376 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2377 ;; We allow newline because this is also used in Info-follow-reference,
2378 ;; where the xref name might be wrapped over two lines.
2379 "Regexp that matches a menu entry name upto but not including the colon.
2380 Because of ambiguities, this should be concatenated with something like
2381 `:' and `Info-following-node-name-re'.")
2383 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2384 (skip-chars-forward " \t\n")
2385 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2386 (Info-following-node-name-re
2388 (index-node "^,\t\n")
2389 (multi-line "^.,\t")
2393 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2396 (setq Info-point-loc
2397 (if (match-beginning 5)
2398 (string-to-number (match-string 5))
2399 (buffer-substring-no-properties
2400 (match-beginning 0) (1- (match-beginning 1)))))
2401 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2402 ;;; (setq Info-point-loc
2403 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2405 (replace-regexp-in-string
2407 (or (match-string-no-properties 2)
2408 ;; If the node name is the menu entry name (using `entry::').
2409 (buffer-substring-no-properties
2410 (match-beginning 0) (1- (match-beginning 1)))))))
2412 ;; No one calls this.
2413 ;;(defun Info-menu-item-sequence (list)
2415 ;; (Info-menu (car list))
2416 ;; (setq list (cdr list))))
2418 (defvar Info-complete-menu-buffer
)
2419 (defvar Info-complete-next-re nil
)
2420 (defvar Info-complete-nodes nil
)
2421 (defvar Info-complete-cache nil
)
2423 (defconst Info-node-spec-re
2424 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2425 "Regexp to match the text after a : until the terminating `.'.")
2427 (defun Info-complete-menu-item (string predicate action
)
2428 ;; This uses two dynamically bound variables:
2429 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2430 ;; is the menu of items we're trying to complete.
2431 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2432 ;; also look for menu items in subsequent nodes as long as those
2433 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2435 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2436 ;; also look for menu items in these nodes. This feature is currently
2437 ;; only used for completion in Info-index.
2439 ;; Note that `Info-complete-menu-buffer' could be current already,
2440 ;; so we want to save point.
2441 (with-current-buffer Info-complete-menu-buffer
2443 (let ((completion-ignore-case t
)
2444 (case-fold-search t
)
2445 (orignode Info-current-node
)
2447 (goto-char (point-min))
2448 (search-forward "\n* Menu:")
2450 ((eq (car-safe action
) 'boundaries
) nil
)
2451 ((eq action
'lambda
)
2453 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2455 (let ((pattern (concat "\n\\* +\\("
2456 (regexp-quote string
)
2457 Info-menu-entry-name-re
"\\):"
2460 (complete-nodes Info-complete-nodes
))
2462 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2463 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2464 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2465 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2466 (let ((prev (nth 3 Info-complete-cache
)))
2467 (eq t
(compare-strings string
0 (length prev
)
2469 ;; We can reuse the previous list.
2470 (setq completions
(nth 4 Info-complete-cache
))
2471 ;; The cache can't be used.
2474 (while (re-search-forward pattern nil t
)
2475 (push (match-string-no-properties 1)
2477 ;; Check subsequent nodes if applicable.
2478 (or (and Info-complete-next-re
2479 (setq nextnode
(Info-extract-pointer "next" t
))
2480 (string-match Info-complete-next-re nextnode
))
2482 (setq complete-nodes
(cdr complete-nodes
)
2483 nextnode
(car complete-nodes
)))))
2484 (Info-goto-node nextnode
))
2485 ;; Go back to the start node (for the next completion).
2486 (unless (equal Info-current-node orignode
)
2487 (Info-goto-node orignode
))
2488 ;; Update the cache.
2489 (set (make-local-variable 'Info-complete-cache
)
2490 (list Info-current-file Info-current-node
2491 Info-complete-next-re string completions
2492 Info-complete-nodes
)))
2493 (complete-with-action action completions string predicate
))))))))
2496 (defun Info-menu (menu-item &optional fork
)
2497 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2498 The menu item should one of those listed in the current node's menu.
2499 Completion is allowed, and the default menu item is the one point is on.
2500 If FORK is non-nil (interactively with a prefix arg), show the node in
2501 a new Info buffer. If FORK is a string, it is the name to use for the
2504 (let (;; If point is within a menu item, use that item as the default
2508 (case-fold-search t
))
2510 (goto-char (point-min))
2511 (if (not (search-forward "\n* menu:" nil t
))
2512 (error "No menu in this node"))
2518 (if (re-search-backward (concat "\n\\* +\\("
2519 Info-menu-entry-name-re
2521 (setq default
(match-string-no-properties 1))))))
2524 (setq item
(let ((completion-ignore-case t
)
2525 (Info-complete-menu-buffer (current-buffer)))
2526 (completing-read (if default
2527 (format "Menu item (default %s): "
2530 'Info-complete-menu-item nil t
)))
2531 ;; we rely on the fact that completing-read accepts an input
2532 ;; of "" even when the require-match argument is true and ""
2533 ;; is not a valid possibility
2534 (if (string= item
"")
2539 (list item current-prefix-arg
))))
2540 ;; there is a problem here in that if several menu items have the same
2541 ;; name you can only go to the node of the first with this command.
2542 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2544 (defun Info-extract-menu-item (menu-item)
2545 (setq menu-item
(regexp-quote menu-item
))
2546 (let ((case-fold-search t
))
2548 (let ((case-fold-search t
))
2549 (goto-char (point-min))
2550 (or (search-forward "\n* menu:" nil t
)
2551 (error "No menu in this node"))
2552 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2553 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2554 (error "No such item in menu"))
2557 (Info-extract-menu-node-name nil
(Info-index-node))))))
2559 ;; If COUNT is nil, use the last item in the menu.
2560 (defun Info-extract-menu-counting (count &optional no-detail
)
2561 (let ((case-fold-search t
))
2563 (let ((case-fold-search t
)
2564 (bound (when (and no-detail
2566 "^[ \t-]*The Detailed Node Listing" nil t
))
2567 (match-beginning 0))))
2568 (goto-char (point-min))
2569 (or (search-forward "\n* menu:" bound t
)
2570 (error "No menu in this node"))
2572 (or (search-forward "\n* " bound t count
)
2573 (error "Too few items in menu"))
2574 (while (search-forward "\n* " bound t
)
2576 (Info-extract-menu-node-name nil
(Info-index-node))))))
2578 (defun Info-nth-menu-item ()
2579 "Go to the node of the Nth menu item.
2580 N is the digit argument used to invoke this command."
2583 (Info-extract-menu-counting
2584 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2586 (defun Info-top-node ()
2587 "Go to the Top node of this file."
2589 (Info-goto-node "Top"))
2591 (defun Info-final-node ()
2592 "Go to the final node in this file."
2594 (Info-goto-node "Top")
2595 (let ((Info-history nil
)
2596 (case-fold-search t
))
2597 ;; Go to the last node in the menu of Top. But don't delve into
2598 ;; detailed node listings.
2599 (Info-goto-node (Info-extract-menu-counting nil t
))
2600 ;; If the last node in the menu is not last in pointer structure,
2601 ;; move forward (but not down- or upward - see bug#1116) until we
2602 ;; can't go any farther.
2603 (while (Info-forward-node t t t
) nil
)
2604 ;; Then keep moving down to last subnode, unless we reach an index.
2605 (while (and (not (Info-index-node))
2606 (save-excursion (search-forward "\n* Menu:" nil t
)))
2607 (Info-goto-node (Info-extract-menu-counting nil
)))))
2609 (defun Info-forward-node (&optional not-down not-up no-error
)
2610 "Go forward one node, considering all nodes as forming one sequence."
2612 (goto-char (point-min))
2614 (let ((case-fold-search t
))
2615 ;; three possibilities, in order of priority:
2616 ;; 1. next node is in a menu in this node (but not in an index)
2617 ;; 2. next node is next at same level
2618 ;; 3. next node is up and next
2619 (cond ((and (not not-down
)
2620 (save-excursion (search-forward "\n* menu:" nil t
))
2621 (not (Info-index-node)))
2622 (Info-goto-node (Info-extract-menu-counting 1))
2624 ((save-excursion (search-backward "next:" nil t
))
2628 (save-excursion (search-backward "up:" nil t
))
2629 ;; Use string-equal, not equal, to ignore text props.
2630 (not (string-equal (downcase (Info-extract-pointer "up"))
2632 (let ((old-node Info-current-node
))
2634 (let (Info-history success
)
2636 (setq success
(Info-forward-node t nil no-error
))
2637 (or success
(Info-goto-node old-node
))))))
2639 (t (error "No pointer forward from this node")))))
2641 (defun Info-backward-node ()
2642 "Go backward one node, considering all nodes as forming one sequence."
2644 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2645 (upnode (Info-extract-pointer "up" t
))
2646 (case-fold-search t
))
2647 (cond ((and upnode
(string-match "(" upnode
))
2648 (error "First node in file"))
2649 ((and upnode
(or (null prevnode
)
2650 ;; Use string-equal, not equal,
2651 ;; to ignore text properties.
2652 (string-equal (downcase prevnode
)
2653 (downcase upnode
))))
2656 ;; If we move back at the same level,
2657 ;; go down to find the last subnode*.
2660 (while (and (not (Info-index-node))
2661 (save-excursion (search-forward "\n* Menu:" nil t
)))
2662 (Info-goto-node (Info-extract-menu-counting nil
)))))
2664 (error "No pointer backward from this node")))))
2667 "Exit Info by selecting some other buffer."
2670 (save-buffers-kill-emacs)
2673 (defun Info-next-menu-item ()
2674 "Go to the node of the next menu item."
2676 ;; Bind this in case the user sets it to nil.
2677 (let* ((case-fold-search t
)
2681 (search-forward "\n* menu:" nil t
)
2682 (and (search-forward "\n* " nil t
)
2683 (Info-extract-menu-node-name)))))
2684 (if node
(Info-goto-node node
)
2685 (error "No more items in menu"))))
2687 (defun Info-last-menu-item ()
2688 "Go to the node of the previous menu item."
2692 ;; Bind this in case the user sets it to nil.
2693 (let* ((case-fold-search t
)
2694 (beg (save-excursion
2695 (and (search-backward "\n* menu:" nil t
)
2697 (or (and beg
(search-backward "\n* " beg t
))
2698 (error "No previous items in menu")))
2699 (Info-goto-node (save-excursion
2700 (goto-char (match-end 0))
2701 (Info-extract-menu-node-name)))))
2703 (defmacro Info-no-error
(&rest body
)
2704 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2706 (defun Info-next-preorder ()
2707 "Go to the next subnode or the next node, or go up a level."
2709 (cond ((Info-no-error (Info-next-menu-item)))
2710 ((Info-no-error (Info-next)))
2711 ((Info-no-error (Info-up t
))
2712 ;; Since we have already gone thru all the items in this menu,
2713 ;; go up to the end of this node.
2714 (goto-char (point-max))
2715 ;; Since logically we are done with the node with that menu,
2716 ;; move on from it. But don't add intermediate nodes
2717 ;; to the history on recursive calls.
2719 (Info-next-preorder)))
2721 (error "No more nodes"))))
2723 (defun Info-last-preorder ()
2724 "Go to the last node, popping up a level if there is none."
2726 (cond ((Info-no-error
2727 (Info-last-menu-item)
2728 ;; If we go down a menu item, go to the end of the node
2729 ;; so we can scroll back through it.
2730 (goto-char (point-max)))
2731 ;; Keep going down, as long as there are nested menu nodes.
2732 (while (Info-no-error
2733 (Info-last-menu-item)
2734 ;; If we go down a menu item, go to the end of the node
2735 ;; so we can scroll back through it.
2736 (goto-char (point-max))))
2738 ((and (Info-no-error (Info-extract-pointer "prev"))
2739 (not (equal (Info-extract-pointer "up")
2740 (Info-extract-pointer "prev"))))
2741 (Info-no-error (Info-prev))
2742 (goto-char (point-max))
2743 (while (Info-no-error
2744 (Info-last-menu-item)
2745 ;; If we go down a menu item, go to the end of the node
2746 ;; so we can scroll back through it.
2747 (goto-char (point-max))))
2749 ((Info-no-error (Info-up t
))
2750 (goto-char (point-min))
2751 (let ((case-fold-search t
))
2752 (or (search-forward "\n* Menu:" nil t
)
2753 (goto-char (point-max)))))
2754 (t (error "No previous nodes"))))
2756 (defun Info-scroll-up ()
2757 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2758 Once you scroll far enough in a node that its menu appears on the screen
2759 but after point, the next scroll moves into its first subnode, unless
2760 `Info-scroll-prefer-subnodes' is nil.
2762 When you scroll past the end of a node, that goes to the next node if
2763 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2764 if this node has no successor, it moves to the parent node's successor,
2765 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2766 the menu of a node, it moves to subnode indicated by the following menu
2767 item. (That case won't normally result from this command, but can happen
2771 (if (or (< (window-start) (point-min))
2772 (> (window-start) (point-max)))
2773 (set-window-start (selected-window) (point)))
2774 (let* ((case-fold-search t
)
2775 (virtual-end (save-excursion
2776 (goto-char (point-min))
2777 (if (and Info-scroll-prefer-subnodes
2778 (search-forward "\n* Menu:" nil t
))
2781 (if (or (< virtual-end
(window-start))
2782 (pos-visible-in-window-p virtual-end
))
2784 (Info-scroll-prefer-subnodes (Info-next-preorder))
2785 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2786 (t (Info-next-preorder)))
2789 (defun Info-mouse-scroll-up (e)
2790 "Scroll one screenful forward in Info, using the mouse.
2791 See `Info-scroll-up'."
2793 (save-selected-window
2795 (select-window (posn-window (event-start e
))))
2798 (defun Info-scroll-down ()
2799 "Scroll one screenful back in Info, considering all nodes as one sequence.
2800 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2801 is non-nil, this goes to its last subnode. When you scroll past the
2802 beginning of a node, that goes to the previous node or back up to the
2805 (if (or (< (window-start) (point-min))
2806 (> (window-start) (point-max)))
2807 (set-window-start (selected-window) (point)))
2808 (let* ((case-fold-search t
)
2809 (current-point (point))
2811 (and Info-scroll-prefer-subnodes
2814 (setq current-point
(point))
2815 (goto-char (point-min))
2816 (search-forward "\n* Menu:"
2820 (pos-visible-in-window-p (point-min) nil t
))
2821 (Info-last-preorder)
2824 (defun Info-mouse-scroll-down (e)
2825 "Scroll one screenful backward in Info, using the mouse.
2826 See `Info-scroll-down'."
2828 (save-selected-window
2830 (select-window (posn-window (event-start e
))))
2831 (Info-scroll-down)))
2833 (defun Info-next-reference (&optional recur
)
2834 "Move cursor to the next cross-reference or menu item in the node."
2836 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2838 (case-fold-search t
))
2839 (or (eobp) (forward-char 1))
2840 (or (re-search-forward pat nil t
)
2842 (goto-char (point-min))
2843 (or (re-search-forward pat nil t
)
2846 (error "No cross references in this node")))))
2847 (goto-char (or (match-beginning 1) (match-beginning 0)))
2848 (if (looking-at "\\* Menu:")
2850 (error "No cross references in this node")
2851 (Info-next-reference t
))
2852 (if (looking-at "^\\* ")
2853 (forward-char 2)))))
2855 (defun Info-prev-reference (&optional recur
)
2856 "Move cursor to the previous cross-reference or menu item in the node."
2858 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2860 (case-fold-search t
))
2861 (or (re-search-backward pat nil t
)
2863 (goto-char (point-max))
2864 (or (re-search-backward pat nil t
)
2867 (error "No cross references in this node")))))
2868 (goto-char (or (match-beginning 1) (match-beginning 0)))
2869 (if (looking-at "\\* Menu:")
2871 (error "No cross references in this node")
2872 (Info-prev-reference t
))
2873 (if (looking-at "^\\* ")
2874 (forward-char 2)))))
2876 (defvar Info-index-nodes nil
2877 "Alist of cached index node names of visited Info files.
2878 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2880 (defun Info-index-nodes (&optional file
)
2881 "Return a list of names of all index nodes in Info FILE.
2882 If FILE is omitted, it defaults to the current Info file.
2883 First look in a list of cached index node names. Then scan Info
2884 file and its subfiles for nodes with the index cookie. Then try
2885 to find index nodes starting from the first node in the top level
2886 menu whose name contains the word \"Index\", plus any immediately
2887 following nodes whose names also contain the word \"Index\"."
2888 (or file
(setq file Info-current-file
))
2889 (or (assoc file Info-index-nodes
)
2890 ;; Skip virtual Info files
2891 (and (or (not (stringp file
))
2892 (Info-virtual-file-p file
))
2893 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2894 (if (Info-file-supports-index-cookies file
)
2895 ;; Find nodes with index cookie
2896 (let* ((default-directory (or (and (stringp file
)
2897 (file-name-directory
2898 (setq file
(Info-find-file file
))))
2900 Info-history Info-history-list Info-fontify-maximum-menu-size
2901 (main-file file
) subfiles nodes
)
2904 (while (or main-file subfiles
)
2906 (info-insert-file-contents (or main-file
(car subfiles
)))
2907 (goto-char (point-min))
2908 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2910 (re-search-backward "^\^_")
2911 (search-forward "Node: ")
2912 (setq nodes
(cons (Info-following-node-name) nodes
))))
2915 (goto-char (point-min))
2916 (if (search-forward "\n\^_\nIndirect:" nil t
)
2917 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2918 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2919 (setq subfiles
(cons (match-string-no-properties 1)
2921 (setq subfiles
(nreverse subfiles
)
2923 (setq subfiles
(cdr subfiles
)))))
2926 (setq nodes
(nreverse nodes
)
2927 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2929 ;; Else find nodes with the word "Index" in the node name
2930 (let ((case-fold-search t
)
2931 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2936 (Info-find-node file
"Top")
2937 (when (and (search-forward "\n* menu:" nil t
)
2938 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2939 (goto-char (match-beginning 1))
2940 (setq nodes
(list (Info-extract-menu-node-name)))
2941 (Info-goto-node (car nodes
))
2942 (while (and (setq node
(Info-extract-pointer "next" t
))
2943 (string-match "\\<Index\\>" node
))
2945 (Info-goto-node node
))))
2948 (setq nodes
(nreverse nodes
)
2949 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2951 ;; If file has no index nodes, still add it to the cache
2952 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2953 (cdr (assoc file Info-index-nodes
)))
2955 (defun Info-index-node (&optional node file
)
2956 "Return non-nil value if NODE is an index node.
2957 If NODE is nil, check the current Info node.
2958 If FILE is nil, check the current Info file."
2959 (or file
(setq file Info-current-file
))
2960 (if (and (or (and node
(not (equal node Info-current-node
)))
2961 (assoc file Info-index-nodes
))
2962 (not Info-current-node-virtual
))
2963 (member (or node Info-current-node
) (Info-index-nodes file
))
2964 ;; Don't search all index nodes if request is only for the current node
2965 ;; and file is not in the cache of index nodes
2967 (if (Info-file-supports-index-cookies file
)
2969 (goto-char (+ (or (save-excursion
2970 (search-backward "\n\^_" nil t
))
2972 (search-forward "\0\b[index\0\b]"
2974 (search-forward "\n\^_" nil t
))
2976 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
2978 (defun Info-goto-index ()
2979 "Go to the first index node."
2980 (let ((node (car (Info-index-nodes))))
2981 (or node
(error "No index"))
2982 (Info-goto-node node
)))
2985 (defun Info-index (topic)
2986 "Look up a string TOPIC in the index for this manual and go to that entry.
2987 If there are no exact matches to the specified topic, this chooses
2988 the first match which is a case-insensitive substring of a topic.
2989 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2990 Give an empty topic name to go to the Index node itself."
2993 (let ((completion-ignore-case t
)
2994 (Info-complete-menu-buffer (clone-buffer))
2995 (Info-complete-nodes (Info-index-nodes))
2996 (Info-history-list nil
))
2997 (if (equal Info-current-file
"dir")
2998 (error "The Info directory node has no index; use m to select a manual"))
3000 (with-current-buffer Info-complete-menu-buffer
3002 (completing-read "Index topic: " 'Info-complete-menu-item
))
3003 (kill-buffer Info-complete-menu-buffer
)))))
3004 (if (equal Info-current-file
"dir")
3005 (error "The Info directory node has no index; use m to select a manual"))
3006 ;; Strip leading colon in topic; index format does not allow them.
3007 (if (and (stringp topic
)
3008 (> (length topic
) 0)
3009 (= (aref topic
0) ?
:))
3010 (setq topic
(substring topic
1)))
3011 (let ((orignode Info-current-node
)
3012 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3013 (regexp-quote topic
)))
3014 node
(nodes (Info-index-nodes))
3015 (ohist-list Info-history-list
)
3016 (case-fold-search t
))
3018 (or (equal topic
"")
3021 ;; We bind Info-history to nil for internal node-switches so
3022 ;; that we don't put junk in the history. In the first
3023 ;; Info-goto-index call, above, we do update the history
3024 ;; because that is what the user's previous node choice into it.
3029 (goto-char (point-min))
3030 (while (re-search-forward pattern nil t
)
3031 (push (list (match-string-no-properties 1)
3032 (match-string-no-properties 2)
3034 (string-to-number (concat "0"
3037 (setq nodes
(cdr nodes
) node
(car nodes
)))
3038 (Info-goto-node node
))
3041 (Info-goto-node orignode
)
3042 (error "No `%s' in index" topic
)))
3043 ;; Here it is a feature that assoc is case-sensitive.
3044 (while (setq found
(assoc topic matches
))
3045 (setq exact
(cons found exact
)
3046 matches
(delq found matches
)))
3047 (setq Info-history-list ohist-list
)
3048 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3049 (Info-index-next 0)))))
3051 (defun Info-index-next (num)
3052 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3054 (or Info-index-alternatives
3055 (error "No previous `i' command"))
3057 (setq num
(+ num
(length Info-index-alternatives
))))
3059 (setq Info-index-alternatives
3060 (nconc (cdr Info-index-alternatives
)
3061 (list (car Info-index-alternatives
)))
3063 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3064 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3065 ;; Forward 2 lines less because `Info-find-node-2' initially
3066 ;; puts point to the 2nd line.
3067 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3068 (forward-line 3) ; don't search in headers
3069 (let ((name (car (car Info-index-alternatives
))))
3070 (Info-find-index-name name
)))
3071 (message "Found `%s' in %s. %s"
3072 (car (car Info-index-alternatives
))
3073 (nth 2 (car Info-index-alternatives
))
3074 (if (cdr Info-index-alternatives
)
3075 (format "(%s total; use `%s' for next)"
3076 (length Info-index-alternatives
)
3077 (key-description (where-is-internal
3078 'Info-index-next overriding-local-map
3082 (defun Info-find-index-name (name)
3083 "Move point to the place within the current node where NAME is defined."
3084 (let ((case-fold-search t
))
3085 (if (or (re-search-forward (format
3086 "[a-zA-Z]+: %s\\( \\|$\\)"
3087 (regexp-quote name
)) nil t
)
3088 ;; Find a function definition with a return type.
3089 (re-search-forward (format
3090 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3091 (regexp-quote name
)) nil t
)
3092 (search-forward (format "`%s'" name
) nil t
)
3093 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3095 (format "`%s'" (substring name
0 (match-beginning 1)))
3097 (search-forward name nil t
)
3098 ;; Try again without the " <1>" makeinfo can append
3099 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3100 (Info-find-index-name (match-string 1 name
))))
3101 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3102 (goto-char (point-min)))))
3104 (add-to-list 'Info-virtual-nodes
3105 '("\\`\\*Index.*\\*\\'"
3106 (find-node . Info-virtual-index-find-node
)
3109 (defvar Info-virtual-index-nodes nil
3110 "Alist of cached matched index search nodes.
3111 Each element is ((FILENAME . TOPIC) MATCHES) where
3112 FILENAME is the file name of the manual,
3113 TOPIC is the search string given as an argument to `Info-virtual-index',
3114 MATCHES is a list of index matches found by `Info-index'.")
3116 (defun Info-virtual-index-find-node (filename nodename
&optional no-going-back
)
3117 "Index-specific implementation of Info-find-node-2."
3118 ;; Generate Index-like menu of matches
3119 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3120 ;; Generate Index-like menu of matches
3121 (let* ((topic (match-string 1 nodename
))
3122 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3123 Info-virtual-index-nodes
))))
3124 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3125 (or filename Info-current-file
) nodename
))
3126 (insert "Info Virtual Index\n")
3127 (insert "******************\n\n")
3128 (insert "Index entries that match `" topic
"':\n\n")
3129 (insert "\0\b[index\0\b]\n")
3131 (insert "No matches found.\n")
3132 (insert "* Menu:\n\n")
3133 (dolist (entry matches
)
3134 (insert (format "* %-38s %s.%s\n"
3135 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3138 (format " (line %s)" (nth 3 entry
))
3140 ;; Else, Generate a list of previous search results
3141 (let ((nodes (reverse Info-virtual-index-nodes
)))
3142 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3143 (or filename Info-current-file
) nodename
))
3144 (insert "Info Virtual Index\n")
3145 (insert "******************\n\n")
3146 (insert "This is a list of search results produced by\n"
3147 "`Info-virtual-index' for the current manual.\n\n")
3148 (insert "* Menu:\n\n")
3149 (dolist (nodeinfo nodes
)
3150 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3152 (format "* %-20s %s.\n"
3153 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3154 (cdr (nth 0 nodeinfo
)))))))))
3156 (defun Info-virtual-index (topic)
3157 "Show a node with all lines in the index containing a string TOPIC.
3158 Like `Info-index' but displays a node with index search results.
3159 Give an empty topic name to go to the node with links to previous
3161 ;; `interactive' is a copy from `Info-index'
3164 (let ((completion-ignore-case t
)
3165 (Info-complete-menu-buffer (clone-buffer))
3166 (Info-complete-nodes (Info-index-nodes))
3167 (Info-history-list nil
))
3168 (if (equal Info-current-file
"dir")
3169 (error "The Info directory node has no index; use m to select a manual"))
3171 (with-current-buffer Info-complete-menu-buffer
3173 (completing-read "Index topic: " 'Info-complete-menu-item
))
3174 (kill-buffer Info-complete-menu-buffer
)))))
3175 (if (equal topic
"")
3176 (Info-find-node Info-current-file
"*Index*")
3177 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3178 (let ((orignode Info-current-node
)
3179 (ohist-list Info-history-list
)
3181 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3183 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3184 Info-virtual-index-nodes
)
3185 ;; Clean up unneccessary side-effects of `Info-index'.
3186 (setq Info-history-list ohist-list
)
3187 (Info-goto-node orignode
)
3189 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3191 (add-to-list 'Info-virtual-files
3192 '("\\`\\*Apropos\\*\\'"
3193 (toc-nodes . Info-apropos-toc-nodes
)
3194 (find-file . Info-apropos-find-file
)
3195 (find-node . Info-apropos-find-node
)
3198 (defvar Info-apropos-file
"*Apropos*"
3199 "Info file name of the virtual manual for matches of `info-apropos'.")
3201 (defvar Info-apropos-nodes nil
3202 "Alist of cached apropos matched nodes.
3203 Each element is (NODENAME STRING MATCHES) where
3204 NODENAME is the name of the node that holds the search result,
3205 STRING is the search string given as an argument to `info-apropos',
3206 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3208 (defun Info-apropos-toc-nodes (filename)
3209 "Apropos-specific implementation of Info-apropos-toc-nodes."
3210 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3212 ("Top" nil nil
,nodes
)
3213 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3215 (defun Info-apropos-find-file (filename &optional noerror
)
3216 "Apropos-specific implementation of Info-find-file."
3219 (defun Info-apropos-find-node (filename nodename
&optional no-going-back
)
3220 "Apropos-specific implementation of Info-find-node-2."
3221 (if (equal nodename
"Top")
3222 ;; Generate Top menu
3223 (let ((nodes (reverse Info-apropos-nodes
)))
3224 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3225 Info-apropos-file nodename
))
3226 (insert "Apropos Index\n")
3227 (insert "*************\n\n")
3228 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3229 (insert "* Menu:\n\n")
3230 (dolist (nodeinfo nodes
)
3231 (insert (format "* %-20s %s.\n"
3232 (format "%s::" (nth 0 nodeinfo
))
3233 (nth 1 nodeinfo
)))))
3234 ;; Else, Generate Index-like menu of matches
3235 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3236 (matches (nth 2 nodeinfo
)))
3238 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3239 Info-apropos-file nodename
))
3240 (insert "Apropos Index\n")
3241 (insert "*************\n\n")
3242 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3243 (insert "\0\b[index\0\b]\n")
3245 (insert "No matches found.\n")
3246 (insert "* Menu:\n\n")
3247 (dolist (entry matches
)
3248 (insert (format "* %-38s (%s)%s.%s\n"
3249 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3253 (format " (line %s)" (nth 3 entry
))
3256 (defun Info-apropos-matches (string)
3257 "Collect STRING matches from all known Info files on your system.
3258 Return a list of matches where each element is in the format
3259 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3260 (interactive "sIndex apropos: ")
3261 (unless (string= string
"")
3262 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3263 (regexp-quote string
)))
3264 (ohist Info-history
)
3265 (ohist-list Info-history-list
)
3266 (current-node Info-current-node
)
3267 (current-file Info-current-file
)
3268 manuals matches node nodes
)
3269 (let ((Info-fontify-maximum-menu-size nil
))
3271 ;; current-node and current-file are nil when they invoke info-apropos
3272 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3273 ;; case, we use (DIR)Top instead, to avoid signalling an error after
3274 ;; the search is complete.
3275 (when (null current-node
)
3276 (setq current-file Info-current-file
)
3277 (setq current-node Info-current-node
))
3278 (message "Searching indices...")
3279 (goto-char (point-min))
3280 (re-search-forward "\\* Menu: *\n" nil t
)
3281 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3282 ;; add-to-list makes sure we don't have duplicates in `manuals',
3283 ;; so that the following dolist loop runs faster.
3284 (add-to-list 'manuals
(match-string 1)))
3285 (dolist (manual (nreverse manuals
))
3286 (message "Searching %s" manual
)
3288 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3290 (Info-find-node manual
(car nodes
))
3293 (goto-char (point-min))
3294 (while (re-search-forward pattern nil t
)
3297 (match-string-no-properties 1)
3298 (match-string-no-properties 2)
3299 (match-string-no-properties 3))
3301 (setq nodes
(cdr nodes
) node
(car nodes
)))
3302 (Info-goto-node node
))))
3304 (message "%s" (if (eq (car-safe err
) 'error
)
3307 (Info-find-node current-file current-node
)
3308 (setq Info-history ohist
3309 Info-history-list ohist-list
)
3310 (message "Searching indices...done")
3311 (or (nreverse matches
) t
))))
3314 (defun info-apropos (string)
3315 "Grovel indices of all known Info files on your system for STRING.
3316 Build a menu of the possible matches."
3317 (interactive "sIndex apropos: ")
3318 (if (equal string
"")
3319 (Info-find-node Info-apropos-file
"Top")
3320 (let* ((nodes Info-apropos-nodes
) nodename
)
3321 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3322 (setq nodes
(cdr nodes
)))
3324 (Info-find-node Info-apropos-file
(car (car nodes
)))
3325 (setq nodename
(format "Index for `%s'" string
))
3326 (push (list nodename string
(Info-apropos-matches string
))
3328 (Info-find-node Info-apropos-file nodename
)))))
3330 (add-to-list 'Info-virtual-files
3331 '("\\`\\*Finder.*\\*\\'"
3332 (find-file . Info-finder-find-file
)
3333 (find-node . Info-finder-find-node
)
3336 (defvar Info-finder-file
"*Finder*"
3337 "Info file name of the virtual Info keyword finder manual.")
3339 (defun Info-finder-find-file (filename &optional noerror
)
3340 "Finder-specific implementation of Info-find-file."
3343 (defvar finder-known-keywords
)
3344 (defvar finder-package-info
)
3345 (declare-function find-library-name
"find-func" (library))
3346 (declare-function finder-unknown-keywords
"finder" ())
3347 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3349 (defun Info-finder-find-node (filename nodename
&optional no-going-back
)
3350 "Finder-specific implementation of Info-find-node-2."
3352 ((equal nodename
"Top")
3353 ;; Display Top menu with descriptions of the keywords
3354 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3355 Info-finder-file nodename
))
3356 (insert "Finder Keywords\n")
3357 (insert "***************\n\n")
3358 (insert "* Menu:\n\n")
3361 (let ((keyword (car assoc
)))
3362 (insert (format "* %-14s %s.\n"
3363 (concat (symbol-name keyword
) "::")
3365 (append '((all .
"All package info")
3366 (unknown .
"unknown keywords"))
3367 finder-known-keywords
)))
3368 ((equal nodename
"unknown")
3369 ;; Display unknown keywords
3370 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3371 Info-finder-file nodename
))
3372 (insert "Finder Unknown Keywords\n")
3373 (insert "***********************\n\n")
3374 (insert "* Menu:\n\n")
3377 (insert (format "* %-14s %s.\n"
3378 (concat (symbol-name (car assoc
)) "::")
3380 (finder-unknown-keywords)))
3381 ((equal nodename
"all")
3382 ;; Display all package info.
3383 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3384 Info-finder-file nodename
))
3385 (insert "Finder Package Info\n")
3386 (insert "*******************\n\n")
3387 (mapc (lambda (package)
3388 (insert (format "%s - %s\n"
3389 (format "*Note %s::" (nth 0 package
))
3391 (insert "Keywords: "
3392 (mapconcat (lambda (keyword)
3393 (format "*Note %s::" (symbol-name keyword
)))
3394 (nth 2 package
) ", ")
3396 finder-package-info
))
3397 ((string-match-p "\\.el\\'" nodename
)
3398 ;; Display commentary section
3399 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3400 Info-finder-file nodename
))
3401 (insert "Finder Commentary\n")
3402 (insert "*****************\n\n")
3404 "Commentary section of the package `" nodename
"':\n\n")
3405 (let ((str (lm-commentary (find-library-name nodename
))))
3407 (insert "Can't find any Commentary section\n\n")
3411 (goto-char (point-min))
3412 (delete-blank-lines)
3413 (goto-char (point-max))
3414 (delete-blank-lines)
3415 (goto-char (point-min))
3416 (while (re-search-forward "^;+ ?" nil t
)
3417 (replace-match "" nil nil
))
3418 (buffer-string))))))
3420 ;; Display packages that match the keyword
3421 ;; or the list of keywords separated by comma.
3422 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3423 Info-finder-file nodename
))
3424 (insert "Finder Packages\n")
3425 (insert "***************\n\n")
3427 "The following packages match the keyword `" nodename
"':\n\n")
3428 (insert "* Menu:\n\n")
3430 (mapcar 'intern
(if (string-match-p "," nodename
)
3431 (split-string nodename
",[ \t\n]*" t
)
3435 (unless (memq nil
(mapcar (lambda (k) (memq k
(nth 2 package
)))
3437 (insert (format "* %-16s %s.\n"
3438 (concat (nth 0 package
) "::")
3440 finder-package-info
)))))
3443 (defun info-finder (&optional keywords
)
3444 "Display descriptions of the keywords in the Finder virtual manual.
3445 In interactive use, a prefix argument directs this command to read
3446 a list of keywords separated by comma. After that, it displays a node
3447 with a list packages that contain all specified keywords."
3449 (when current-prefix-arg
3452 (completing-read-multiple
3453 "Keywords (separated by comma): "
3454 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3455 (finder-unknown-keywords))))
3459 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3460 (Info-find-node Info-finder-file
"Top")))
3463 (defun Info-undefined ()
3464 "Make command be undefined in Info."
3469 "Enter the Info tutorial."
3471 (delete-other-windows)
3472 (Info-find-node "info"
3473 (if (< (window-height) 23)
3477 (defun Info-summary ()
3478 "Display a brief summary of all Info commands."
3480 (save-window-excursion
3481 (switch-to-buffer "*Help*")
3482 (setq buffer-read-only nil
)
3484 (insert (documentation 'Info-mode
))
3486 (goto-char (point-min))
3488 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3489 (message (if flag
"Type Space to see more"
3490 "Type Space to return to Info"))
3491 (if (not (eq ?\s
(setq ch
(read-event))))
3492 (progn (setq unread-command-events
(list ch
)) nil
)
3495 (bury-buffer "*Help*")))
3497 (defun Info-get-token (pos start all
&optional errorstring
)
3498 "Return the token around POS.
3499 POS must be somewhere inside the token
3500 START is a regular expression which will match the
3501 beginning of the tokens delimited string
3502 ALL is a regular expression with a single
3503 parenthesized subpattern which is the token to be
3504 returned. E.g. '{\(.*\)}' would return any string
3505 enclosed in braces around POS.
3506 ERRORSTRING optional fourth argument, controls action on no match
3509 a string: signal an error, using that string."
3510 (let ((case-fold-search t
))
3513 ;; First look for a match for START that goes across POS.
3514 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3515 (not (looking-at start
)))
3517 ;; If we did not find one, search back for START
3518 ;; (this finds only matches that end at or before POS).
3519 (or (looking-at start
)
3522 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3524 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3525 (not (setq found
(and (<= (match-beginning 0) pos
)
3526 (> (match-end 0) pos
))))))
3527 (if (and found
(<= (match-beginning 0) pos
)
3528 (> (match-end 0) pos
))
3529 (match-string-no-properties 1)
3530 (cond ((null errorstring
)
3536 (error "No %s around position %d" errorstring pos
))))))))
3538 (defun Info-mouse-follow-nearest-node (click)
3539 "\\<Info-mode-map>Follow a node reference near point.
3540 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3541 At end of the node's text, moves to the next node, or up if none."
3543 (mouse-set-point click
)
3544 (and (not (Info-follow-nearest-node))
3545 (save-excursion (forward-line 1) (eobp))
3546 (Info-next-preorder)))
3548 (defun Info-follow-nearest-node (&optional fork
)
3549 "Follow a node reference near point.
3550 If point is on a reference, follow that reference. Otherwise,
3551 if point is in a menu item description, follow that menu item.
3553 If FORK is non-nil (interactively with a prefix arg), show the node in
3555 If FORK is a string, it is the name to use for the new buffer."
3557 (or (Info-try-follow-nearest-node fork
)
3558 (when (save-excursion
3559 (search-backward "\n* menu:" nil t
))
3562 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3563 (beginning-of-line 0))
3564 (when (looking-at "\\* +\\([^\t\n]*\\):")
3566 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3568 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3569 ;; Don't raise an error when mouse-1 is bound to this - it's
3570 ;; often used to simply select the window or frame.
3571 (eq 'mouse-1
(event-basic-type last-input-event
)))
3572 (error "Point neither on reference nor in menu item description")))
3574 ;; Common subroutine.
3575 (defun Info-try-follow-nearest-node (&optional fork
)
3576 "Follow a node reference near point. Return non-nil if successful.
3577 If FORK is non-nil, it is passed to `Info-goto-node'."
3580 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3581 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3584 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3585 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3586 (Info-follow-reference node fork
))
3587 ;; menu item: node name
3588 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3589 (Info-goto-node node fork
))
3590 ;; menu item: node name or index entry
3591 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3594 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3595 (Info-goto-node node fork
))
3596 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3597 (Info-goto-node node fork
))
3598 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3599 (Info-goto-node node fork
))
3600 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3601 (Info-goto-node "Top" fork
))
3602 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3603 (Info-goto-node node fork
)))
3606 (defvar Info-mode-map
3607 (let ((map (make-keymap)))
3608 (suppress-keymap map
)
3609 (define-key map
"." 'beginning-of-buffer
)
3610 (define-key map
" " 'Info-scroll-up
)
3611 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3612 (define-key map
"\t" 'Info-next-reference
)
3613 (define-key map
"\e\t" 'Info-prev-reference
)
3614 (define-key map
[(shift tab
)] 'Info-prev-reference
)
3615 (define-key map
[backtab] 'Info-prev-reference)
3616 (define-key map "1" 'Info-nth-menu-item)
3617 (define-key map "2" 'Info-nth-menu-item)
3618 (define-key map "3" 'Info-nth-menu-item)
3619 (define-key map "4" 'Info-nth-menu-item)
3620 (define-key map "5" 'Info-nth-menu-item)
3621 (define-key map "6" 'Info-nth-menu-item)
3622 (define-key map "7" 'Info-nth-menu-item)
3623 (define-key map "8" 'Info-nth-menu-item)
3624 (define-key map "9" 'Info-nth-menu-item)
3625 (define-key map "0" 'undefined)
3626 (define-key map "?" 'Info-summary)
3627 (define-key map "]" 'Info-forward-node)
3628 (define-key map "[" 'Info-backward-node)
3629 (define-key map "<" 'Info-top-node)
3630 (define-key map ">" 'Info-final-node)
3631 (define-key map "b" 'beginning-of-buffer)
3632 (define-key map "d" 'Info-directory)
3633 (define-key map "e" 'Info-edit)
3634 (define-key map "f" 'Info-follow-reference)
3635 (define-key map "g" 'Info-goto-node)
3636 (define-key map "h" 'Info-help)
3637 (define-key map "i" 'Info-index)
3638 (define-key map "I" 'Info-virtual-index)
3639 (define-key map "l" 'Info-history-back)
3640 (define-key map "L" 'Info-history)
3641 (define-key map "m" 'Info-menu)
3642 (define-key map "n" 'Info-next)
3643 (define-key map "p" 'Info-prev)
3644 (define-key map "q" 'Info-exit)
3645 (define-key map "r" 'Info-history-forward)
3646 (define-key map "s" 'Info-search)
3647 (define-key map "S" 'Info-search-case-sensitively)
3648 (define-key map "\M-n" 'clone-buffer)
3649 (define-key map "t" 'Info-top-node)
3650 (define-key map "T" 'Info-toc)
3651 (define-key map "u" 'Info-up)
3652 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3653 (define-key map "w" 'Info-copy-current-node-name)
3654 (define-key map "c" 'Info-copy-current-node-name)
3655 ;; `^' for consistency with `dired-up-directory'.
3656 (define-key map "^" 'Info-up)
3657 (define-key map "," 'Info-index-next)
3658 (define-key map "\177" 'Info-scroll-down)
3659 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3660 (define-key map [follow-link] 'mouse-face)
3662 "Keymap containing Info commands.")
3665 (defun Info-check-pointer (item)
3666 "Non-nil if ITEM is present in this node."
3668 (Info-extract-pointer item)
3672 Info-mode-menu Info-mode-map
3673 "Menu for Info files."
3675 ["Up" Info-up :active (Info-check-pointer "up")
3676 :help "Go up in the Info tree"]
3677 ["Next" Info-next :active (Info-check-pointer "next")
3678 :help "Go to the next node"]
3679 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3680 :help "Go to the previous node"]
3681 ["Backward" Info-backward-node
3682 :help "Go backward one node, considering all as a sequence"]
3683 ["Forward" Info-forward-node
3684 :help "Go forward one node, considering all as a sequence"]
3685 ["Beginning" beginning-of-buffer
3686 :help "Go to beginning of this node"]
3687 ["Top" Info-top-node
3688 :help "Go to top node of file"]
3689 ["Final Node" Info-final-node
3690 :help "Go to final node in this file"]
3691 ("Menu Item" ["You should never see this" report-emacs-bug t])
3692 ("Reference" ["You should never see this" report-emacs-bug t])
3693 ["Search..." Info-search
3694 :help "Search for regular expression in this Info file"]
3695 ["Search Next" Info-search-next
3696 :help "Search for another occurrence of regular expression"]
3697 ["Go to Node..." Info-goto-node
3698 :help "Go to a named node"]
3699 ["Back in history" Info-history-back :active Info-history
3700 :help "Go back in history to the last node you were at"]
3701 ["Forward in history" Info-history-forward :active Info-history-forward
3702 :help "Go forward in history"]
3703 ["History" Info-history :active Info-history-list
3704 :help "Go to menu of visited nodes"]
3705 ["Table of Contents" Info-toc
3706 :help "Go to table of contents"]
3708 ["Lookup a String..." Info-index
3709 :help "Look for a string in the index items"]
3710 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3711 :help "Look for another occurrence of previous item"]
3712 ["Lookup a string and display index of results..." Info-virtual-index
3713 :help "Look for a string in the index items and display node with results"]
3714 ["Lookup a string in all indices..." info-apropos
3715 :help "Look for a string in the indices of all manuals"])
3716 ["Copy Node Name" Info-copy-current-node-name
3717 :help "Copy the name of the current node into the kill ring"]
3718 ["Clone Info buffer" clone-buffer
3719 :help "Create a twin copy of the current Info buffer."]
3720 ["Exit" Info-exit :help "Stop reading Info"]))
3723 (defvar info-tool-bar-map
3724 (let ((map (make-sparse-keymap)))
3725 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3727 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3729 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3731 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3733 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map)
3734 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3735 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3736 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3737 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3738 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map)
3741 (defvar Info-menu-last-node nil)
3742 ;; Last node the menu was created for.
3743 ;; Value is a list, (FILE-NAME NODE-NAME).
3745 (defun Info-menu-update ()
3746 "Update the Info menu for the current node."
3748 (if (or (not (eq major-mode 'Info-mode))
3749 (equal (list Info-current-file Info-current-node)
3750 Info-menu-last-node))
3752 ;; Update menu menu.
3753 (let* ((Info-complete-menu-buffer (current-buffer))
3754 (items (nreverse (condition-case nil
3755 (Info-complete-menu-item "" nil t)
3759 (while (and items (< number 9))
3760 (setq current (car items)
3763 (setq entries (cons `[,current
3764 (Info-menu ,current)
3765 :keys ,(format "%d" number)]
3768 (setq entries (cons ["Other..." Info-menu t] entries)))
3770 (setq entries (list ["No menu" nil nil] nil :active)))
3771 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3772 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3774 str i entries current
3776 (case-fold-search t))
3778 (goto-char (point-min))
3779 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3780 (setq str (match-string 1))
3782 (while (setq i (string-match "[ \n\t]+" str i))
3783 (setq str (concat (substring str 0 i) " "
3784 (substring str (match-end 0))))
3788 (while (and items (< number 9))
3789 (setq current (car items)
3792 (setq entries (cons `[,current
3793 (Info-follow-reference ,current)
3797 (setq entries (cons ["Other..." Info-follow-reference t]
3800 (setq entries (list ["No references" nil nil] nil :active)))
3801 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3802 ;; Update last seen node.
3803 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3804 ;; Try to avoid entering infinite beep mode in case of errors.
3808 (defun Info-copy-current-node-name (&optional arg)
3809 "Put the name of the current Info node into the kill ring.
3810 The name of the Info file is prepended to the node name in parentheses.
3811 With a zero prefix arg, put the name inside a function call to `info'."
3813 (unless Info-current-node
3814 (error "No current Info node"))
3815 (let ((node (if (stringp Info-current-file)
3816 (concat "(" (file-name-nondirectory Info-current-file) ") "
3817 Info-current-node))))
3818 (if (zerop (prefix-numeric-value arg))
3819 (setq node (concat "(info \"" node "\")")))
3820 (unless (stringp Info-current-file)
3821 (setq node (format "(Info-find-node '%S '%S)"
3822 Info-current-file Info-current-node)))
3824 (message "%s" node)))
3827 ;; Info mode is suitable only for specially formatted data.
3828 (put 'Info-mode 'mode-class 'special)
3829 (put 'Info-mode 'no-clone-indirect t)
3831 (defvar tool-bar-map)
3832 (defvar bookmark-make-record-function)
3834 ;; Autoload cookie needed by desktop.el
3837 "Info mode provides commands for browsing through the Info documentation tree.
3838 Documentation in Info is divided into \"nodes\", each of which discusses
3839 one topic and contains references to other nodes which discuss related
3840 topics. Info has commands to follow the references and show you other nodes.
3843 \\[Info-help] Invoke the Info tutorial.
3844 \\[Info-exit] Quit Info: reselect previously selected buffer.
3846 Selecting other nodes:
3847 \\[Info-mouse-follow-nearest-node]
3848 Follow a node reference you click on.
3849 This works with menu items, cross references, and
3850 the \"next\", \"previous\" and \"up\", depending on where you click.
3851 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3852 \\[Info-next] Move to the \"next\" node of this node.
3853 \\[Info-prev] Move to the \"previous\" node of this node.
3854 \\[Info-up] Move \"up\" from this node.
3855 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3856 Picking a menu item causes another node to be selected.
3857 \\[Info-directory] Go to the Info directory node.
3858 \\[Info-top-node] Go to the Top node of this file.
3859 \\[Info-final-node] Go to the final node in this file.
3860 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3861 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3862 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3863 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3864 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3865 \\[Info-history-back] Move back in history to the last node you were at.
3866 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3867 \\[Info-history] Go to menu of visited nodes.
3868 \\[Info-toc] Go to table of contents of the current Info file.
3870 Moving within a node:
3871 \\[Info-scroll-up] Normally, scroll forward a full screen.
3872 Once you scroll far enough in a node that its menu appears on the
3873 screen but after point, the next scroll moves into its first
3874 subnode. When after all menu items (or if there is no menu),
3875 move up to the parent node.
3876 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3877 already visible, try to go to the previous menu entry, or up
3879 \\[beginning-of-buffer] Go to beginning of node.
3882 \\[Info-search] Search through this Info file for specified regexp,
3883 and select the node in which the next occurrence is found.
3884 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3885 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3886 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3887 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3888 \\[Info-virtual-index] Look for a string and display the index node with results.
3889 \\[info-apropos] Look for a string in the indices of all manuals.
3890 \\[Info-goto-node] Move to node specified by name.
3891 You may include a filename as well, as (FILENAME)NODENAME.
3892 1 .. 9 Pick first ... ninth item in node's menu.
3893 Every third `*' is highlighted to help pick the right number.
3894 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3895 \\[clone-buffer] Select a new cloned Info buffer in another window.
3896 \\[universal-argument] \\[info] Move to new Info file with completion.
3897 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3898 (kill-all-local-variables)
3899 (setq major-mode 'Info-mode)
3900 (setq mode-name "Info")
3902 (use-local-map Info-mode-map)
3903 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3904 (set-syntax-table text-mode-syntax-table)
3905 (setq local-abbrev-table text-mode-abbrev-table)
3906 (setq case-fold-search t)
3907 (setq buffer-read-only t)
3908 (make-local-variable 'Info-current-file)
3909 (make-local-variable 'Info-current-subfile)
3910 (make-local-variable 'Info-current-node)
3911 (make-local-variable 'Info-tag-table-marker)
3912 (setq Info-tag-table-marker (make-marker))
3913 (make-local-variable 'Info-tag-table-buffer)
3914 (setq Info-tag-table-buffer nil)
3915 (make-local-variable 'Info-history)
3916 (make-local-variable 'Info-history-forward)
3917 (make-local-variable 'Info-index-alternatives)
3918 (if Info-use-header-line ; do not override global header lines
3919 (setq header-line-format
3920 '(:eval (get-text-property (point-min) 'header-line))))
3921 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3922 ;; This is for the sake of the invisible text we use handling titles.
3923 (make-local-variable 'line-move-ignore-invisible)
3924 (setq line-move-ignore-invisible t)
3925 (make-local-variable 'desktop-save-buffer)
3926 (make-local-variable 'widen-automatically)
3927 (setq widen-automatically nil)
3928 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3929 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3930 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
3931 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3932 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3933 (set (make-local-variable 'isearch-search-fun-function)
3934 'Info-isearch-search)
3935 (set (make-local-variable 'isearch-wrap-function)
3937 (set (make-local-variable 'isearch-push-state-function)
3938 'Info-isearch-push-state)
3939 (set (make-local-variable 'isearch-filter-predicate)
3940 'Info-isearch-filter)
3941 (set (make-local-variable 'search-whitespace-regexp)
3942 Info-search-whitespace-regexp)
3943 (set (make-local-variable 'revert-buffer-function)
3944 'Info-revert-buffer-function)
3945 (Info-set-mode-line)
3946 (set (make-local-variable 'bookmark-make-record-function)
3947 'Info-bookmark-make-record)
3948 (run-mode-hooks 'Info-mode-hook))
3950 ;; When an Info buffer is killed, make sure the associated tags buffer
3952 (defun Info-kill-buffer ()
3953 (and (eq major-mode 'Info-mode)
3954 Info-tag-table-buffer
3955 (kill-buffer Info-tag-table-buffer)))
3957 ;; Placed on `clone-buffer-hook'.
3958 (defun Info-clone-buffer ()
3959 (when (bufferp Info-tag-table-buffer)
3960 (setq Info-tag-table-buffer
3961 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3962 (let ((m Info-tag-table-marker))
3964 (setq Info-tag-table-marker
3965 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3966 (with-current-buffer Info-tag-table-buffer
3967 (copy-marker (marker-position m)))
3970 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3971 (set-keymap-parent map text-mode-map)
3972 (define-key map "\C-c\C-c" 'Info-cease-edit)
3974 "Local keymap used within `e' command of Info.")
3976 ;; Info-edit mode is suitable only for specially formatted data.
3977 (put 'Info-edit-mode 'mode-class 'special)
3979 (defun Info-edit-mode ()
3980 "Major mode for editing the contents of an Info node.
3981 Like text mode with the addition of `Info-cease-edit'
3982 which returns to Info mode for browsing.
3984 (use-local-map Info-edit-map)
3985 (setq major-mode 'Info-edit-mode)
3986 (setq mode-name "Info Edit")
3987 (kill-local-variable 'mode-line-buffer-identification)
3988 (setq buffer-read-only nil)
3989 (force-mode-line-update)
3990 (buffer-enable-undo (current-buffer))
3991 (run-mode-hooks 'Info-edit-mode-hook))
3994 "Edit the contents of this Info node.
3995 Allowed only if variable `Info-enable-edit' is non-nil."
3997 (or Info-enable-edit
3998 (error "Editing Info nodes is not enabled"))
4000 (message "%s" (substitute-command-keys
4001 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4003 (defun Info-cease-edit ()
4004 "Finish editing Info node; switch back to Info proper."
4006 ;; Do this first, so nothing has changed if user C-g's at query.
4007 (and (buffer-modified-p)
4008 (y-or-n-p "Save the file? ")
4010 (use-local-map Info-mode-map)
4011 (setq major-mode 'Info-mode)
4012 (setq mode-name "Info")
4013 (Info-set-mode-line)
4014 (setq buffer-read-only t)
4015 (force-mode-line-update)
4016 (and (marker-position Info-tag-table-marker)
4018 (message "Tags may have changed. Use Info-tagify if necessary")))
4020 (defvar Info-file-list-for-emacs
4021 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4022 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4023 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4024 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4025 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4026 ("copyright" . "autotype") ("executable" . "autotype")
4027 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4028 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4029 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4030 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4031 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4032 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4033 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4034 ("rfc2045" . "emacs-mime")
4035 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4036 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4037 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4038 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4039 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4040 ("mml" . "emacs-mime"))
4041 "List of Info files that describe Emacs commands.
4042 An element can be a file name, or a list of the form (PREFIX . FILE)
4043 where PREFIX is a name prefix and FILE is the file to look in.
4044 If the element is just a file name, the file name also serves as the prefix.")
4046 (defun Info-find-emacs-command-nodes (command)
4047 "Return a list of locations documenting COMMAND.
4048 The `info-file' property of COMMAND says which Info manual to search.
4049 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4050 defines heuristics for which Info manual to try.
4051 The locations are of the format used in `Info-history', i.e.
4052 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
4053 in the first element of the returned list (which is treated specially in
4054 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4055 (let ((where '()) line-number
4056 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4057 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4058 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4059 (info-file "emacs")) ;default
4060 ;; Determine which Info file this command is documented in.
4061 (if (get command 'info-file)
4062 (setq info-file (get command 'info-file))
4063 ;; If it doesn't say explicitly, test its name against
4064 ;; various prefixes that we know.
4065 (let ((file-list Info-file-list-for-emacs))
4067 (let* ((elt (car file-list))
4068 (name (if (consp elt)
4071 (file (if (consp elt) (cdr elt) elt))
4072 (case-fold-search nil)
4073 (regexp (concat "\\`" (regexp-quote name)
4075 (if (string-match regexp (symbol-name command))
4076 (setq info-file file file-list nil))
4077 (setq file-list (cdr file-list))))))
4078 (Info-find-node info-file "Top")
4079 ;; Bind Info-history to nil, to prevent the index nodes from
4080 ;; getting into the node history.
4081 (let ((Info-history nil)
4082 (Info-history-list nil)
4083 node (nodes (Info-index-nodes)))
4084 (Info-goto-node (car nodes))
4087 (goto-char (point-min))
4088 (while (re-search-forward cmd-desc nil t)
4090 (cons (list Info-current-file
4091 (match-string-no-properties 2)
4094 (setq line-number (and (match-beginning 3)
4095 (string-to-number (match-string 3)))))
4096 (and (setq nodes (cdr nodes) node (car nodes))))
4097 (Info-goto-node node)))
4098 (if (and line-number where)
4099 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4103 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4105 (defun Info-goto-emacs-command-node (command)
4106 "Go to the Info node in the Emacs manual for command COMMAND.
4107 The command is found by looking up in Emacs manual's indices
4108 or in another manual found via COMMAND's `info-file' property or
4109 the variable `Info-file-list-for-emacs'.
4110 COMMAND must be a symbol or string."
4111 (interactive "CFind documentation for command: ")
4112 ;; If command is given as a string, convert it to a symbol.
4113 (if (stringp command)
4114 (setq command (intern command)))
4115 (or (commandp command)
4116 (signal 'wrong-type-argument (list 'commandp command)))
4117 (let ((where (Info-find-emacs-command-nodes command)))
4119 (let ((num-matches (length where)))
4120 ;; Get Info running, and pop to it in another window.
4121 (save-window-excursion
4123 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4124 ;; Bind Info-history to nil, to prevent the last Index node
4125 ;; visited by Info-find-emacs-command-nodes from being
4126 ;; pushed onto the history.
4127 (let ((Info-history nil) (Info-history-list nil)
4128 (line-number (nth 2 (car where))))
4129 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4130 (if (and (integerp line-number) (> line-number 0))
4131 (forward-line (1- line-number))))
4132 (if (> num-matches 1)
4134 ;; (car where) will be pushed onto Info-history
4135 ;; when/if they go to another node. Put the other
4136 ;; nodes that were found on the history.
4137 (setq Info-history (nconc (cdr where) Info-history))
4138 (message "Found %d other entr%s. Use %s to see %s."
4140 (if (> num-matches 2) "ies" "y")
4141 (substitute-command-keys "\\[Info-history-back]")
4142 (if (> num-matches 2) "them" "it")))))
4143 (error "Couldn't find documentation for %s" command))))
4145 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4147 (defun Info-goto-emacs-key-command-node (key)
4148 "Go to the node in the Emacs manual which describes the command bound to KEY.
4150 Interactively, if the binding is `execute-extended-command', a command is read.
4151 The command is found by looking up in Emacs manual's indices
4152 or in another manual found via COMMAND's `info-file' property or
4153 the variable `Info-file-list-for-emacs'."
4154 (interactive "kFind documentation for key: ")
4155 (let ((command (key-binding key)))
4156 (cond ((null command)
4157 (message "%s is undefined" (key-description key)))
4158 ((and (called-interactively-p 'interactive)
4159 (eq command 'execute-extended-command))
4160 (Info-goto-emacs-command-node
4161 (read-command "Find documentation for command: ")))
4163 (Info-goto-emacs-command-node command)))))
4165 (defvar Info-next-link-keymap
4166 (let ((keymap (make-sparse-keymap)))
4167 (define-key keymap [header-line mouse-1] 'Info-next)
4168 (define-key keymap [header-line mouse-2] 'Info-next)
4169 (define-key keymap [header-line down-mouse-1] 'ignore)
4170 (define-key keymap [mouse-2] 'Info-next)
4171 (define-key keymap [follow-link] 'mouse-face)
4173 "Keymap to put on the Next link in the text or the header line.")
4175 (defvar Info-prev-link-keymap
4176 (let ((keymap (make-sparse-keymap)))
4177 (define-key keymap [header-line mouse-1] 'Info-prev)
4178 (define-key keymap [header-line mouse-2] 'Info-prev)
4179 (define-key keymap [header-line down-mouse-1] 'ignore)
4180 (define-key keymap [mouse-2] 'Info-prev)
4181 (define-key keymap [follow-link] 'mouse-face)
4183 "Keymap to put on the Prev link in the text or the header line.")
4185 (defvar Info-up-link-keymap
4186 (let ((keymap (make-sparse-keymap)))
4187 (define-key keymap [header-line mouse-1] 'Info-up)
4188 (define-key keymap [header-line mouse-2] 'Info-up)
4189 (define-key keymap [header-line down-mouse-1] 'ignore)
4190 (define-key keymap [mouse-2] 'Info-up)
4191 (define-key keymap [follow-link] 'mouse-face)
4193 "Keymap to put on the Up link in the text or the header line.")
4195 (defun Info-insert-breadcrumbs ()
4196 (let ((nodes (Info-toc-nodes Info-current-file))
4197 (node Info-current-node)
4199 (depth Info-breadcrumbs-depth))
4201 ;; Get ancestors from the cached parent-children node info
4202 (while (and (not (equal "Top" node)) (> depth 0))
4203 (setq node (nth 1 (assoc node nodes)))
4204 (if node (push node crumbs))
4205 (setq depth (1- depth)))
4208 (when Info-use-header-line
4209 ;; Let it disappear if crumbs is nil.
4210 (nconc crumbs (list Info-current-node)))
4211 (when (or Info-use-header-line crumbs)
4212 ;; Add top node (and continuation if needed).
4214 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4215 crumbs (cons nil crumbs))))
4216 ;; Eliminate duplicate.
4218 (dolist (node crumbs)
4220 (if (not (equal node "Top")) node
4222 (if (stringp Info-current-file)
4223 (file-name-nondirectory Info-current-file)
4224 ;; Some legacy code can still use a symbol.
4225 Info-current-file)))))
4226 (insert (if (bolp) "" " > ")
4229 ((equal node Info-current-node)
4230 ;; No point linking to ourselves.
4231 (propertize text 'font-lock-face 'info-header-node))
4233 (concat "*Note " text "::"))))))
4236 (defun Info-fontify-node ()
4239 (let* ((inhibit-read-only t)
4240 (case-fold-search t)
4242 (not-fontified-p ; the node hasn't already been fontified
4243 (not (let ((where (next-single-property-change (point-min)
4245 (and where (not (= where (point-max)))))))
4246 (fontify-visited-p ; visited nodes need to be re-fontified
4247 (and Info-fontify-visited-nodes
4248 ;; Don't take time to refontify visited nodes in huge nodes
4249 Info-fontify-maximum-menu-size
4250 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4253 ;; Fontify header line
4254 (goto-char (point-min))
4255 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4256 (goto-char (match-end 0))
4257 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4258 (goto-char (match-end 0))
4259 (let* ((nbeg (match-beginning 2))
4260 (nend (match-end 2))
4261 (tbeg (match-beginning 1))
4262 (tag (match-string 1)))
4263 (if (string-equal (downcase tag) "node")
4264 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4265 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4266 (put-text-property tbeg nend 'mouse-face 'highlight)
4267 (put-text-property tbeg nend
4269 (concat "mouse-2: Go to node "
4270 (buffer-substring nbeg nend)))
4271 ;; Always set up the text property keymap.
4272 ;; It will either be used in the buffer
4273 ;; or copied in the header line.
4277 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4278 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4279 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4281 (when (> Info-breadcrumbs-depth 0)
4282 (Info-insert-breadcrumbs))
4284 ;; Treat header line.
4285 (when Info-use-header-line
4286 (goto-char (point-min))
4287 (let* ((header-end (line-end-position))
4289 ;; If we find neither Next: nor Prev: link, show the entire
4290 ;; node header. Otherwise, don't show the File: and Node:
4291 ;; parts, to avoid wasting precious space on information that
4292 ;; is available in the mode line.
4293 (if (re-search-forward
4294 "\\(next\\|up\\|prev[ious]*\\): "
4297 (goto-char (match-beginning 1))
4298 (buffer-substring (point) header-end))
4299 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4301 (concat "No next, prev or up links -- "
4302 (buffer-substring (point) header-end))
4303 (buffer-substring (point) header-end)))))
4304 (put-text-property (point-min) (1+ (point-min))
4306 (replace-regexp-in-string
4308 ;; Preserve text properties on duplicated `%'.
4309 (lambda (s) (concat s s)) header))
4310 ;; Hide the part of the first line
4311 ;; that is in the header, if it is just part.
4313 ((> Info-breadcrumbs-depth 0)
4314 (put-text-property (point-min) (1+ header-end) 'invisible t))
4316 ;; Hide the punctuation at the end, too.
4317 (skip-chars-backward " \t,")
4318 (put-text-property (point) header-end 'invisible t))))))
4321 (goto-char (point-min))
4322 (when (and font-lock-mode not-fontified-p)
4323 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4325 ;; Only consider it as an underlined title if the ASCII
4326 ;; underline has the same size as the text. A typical
4327 ;; counter example is when a continuation "..." is alone
4329 (= (string-width (match-string 1))
4330 (string-width (match-string 2))))
4331 (let* ((c (preceding-char))
4333 (cond ((= c ?*) 'info-title-1)
4334 ((= c ?=) 'info-title-2)
4335 ((= c ?-) 'info-title-3)
4336 (t 'info-title-4))))
4337 (put-text-property (match-beginning 1) (match-end 1)
4338 'font-lock-face face))
4339 ;; This is a serious problem for trying to handle multiple
4340 ;; frame types at once. We want this text to be invisible
4341 ;; on frames that can display the font above.
4342 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4343 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4344 '(invisible t front-sticky nil rear-nonsticky t)))))
4346 ;; Fontify cross references
4347 (goto-char (point-min))
4348 (when (or not-fontified-p fontify-visited-p)
4349 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4350 (let ((start (match-beginning 0))
4353 (when not-fontified-p
4354 (when Info-hide-note-references
4355 (when (and (not (eq Info-hide-note-references 'hide))
4356 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4357 ;; *Note is often used where *note should have been
4359 (skip-syntax-backward " ")
4360 (when (memq (char-before) '(?\( ?\[ ?\{))
4361 ;; Check whether the paren is preceded by
4362 ;; an end of sentence
4363 (skip-syntax-backward " ("))
4365 (cond ((save-match-data (looking-back "\\<see"))
4367 ((save-match-data (looking-back "\\<in"))
4369 ((memq (char-before) '(nil ?\. ?! ??))
4373 (search-forward "\n\n" start t)))
4377 (add-text-properties
4379 (or (save-match-data
4380 ;; Don't hide \n after *Note
4381 (let ((start1 (match-beginning 1)))
4382 (if (string-match "\n" (match-string 1))
4383 (+ start1 (match-beginning 0)))))
4386 `(display ,other-tag front-sticky nil rear-nonsticky t)
4387 '(invisible t front-sticky nil rear-nonsticky t))))
4388 (add-text-properties
4389 (match-beginning 2) (match-end 2)
4391 'help-echo (if (or (match-end 5)
4392 (not (equal (match-string 4) "")))
4393 (concat "mouse-2: go to " (or (match-string 5)
4395 "mouse-2: go to this node")
4396 'mouse-face 'highlight)))
4397 (when (or not-fontified-p fontify-visited-p)
4398 (setq rbeg (match-beginning 2)
4403 ;; Display visited nodes in a different face
4404 (if (and Info-fontify-visited-nodes
4406 (let* ((node (replace-regexp-in-string
4408 (replace-regexp-in-string
4410 (or (match-string-no-properties 5)
4411 (and (not (equal (match-string 4) ""))
4412 (match-string-no-properties 4))
4413 (match-string-no-properties 2)))))
4415 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4416 (file (if external-link-p
4417 (file-name-nondirectory
4418 (match-string-no-properties 1 node))
4420 (hl Info-history-list)
4423 (setq node (if (equal (match-string 2 node) "")
4425 (match-string-no-properties 2 node))))
4427 (if (and (string-equal node (nth 1 (car hl)))
4429 (if (and external-link-p
4430 (stringp (caar hl)))
4431 (file-name-nondirectory
4434 (setq res (car hl) hl nil)
4435 (setq hl (cdr hl))))
4436 res))) 'info-xref-visited 'info-xref))
4437 ;; For multiline ref, unfontify newline and surrounding whitespace
4441 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4442 (remove-text-properties (match-beginning 0)
4444 '(font-lock-face t))))))
4445 (when not-fontified-p
4446 (when (memq Info-hide-note-references '(t hide))
4447 (add-text-properties (match-beginning 3) (match-end 3)
4448 '(invisible t front-sticky nil rear-nonsticky t))
4449 ;; Unhide the file name of the external reference in parens
4450 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4451 (remove-text-properties (match-beginning 6) (match-end 6)
4452 '(invisible t front-sticky nil rear-nonsticky t)))
4453 ;; Unhide newline because hidden newlines cause too long lines
4455 (let ((beg3 (match-beginning 3))
4456 (end3 (match-end 3)))
4457 (if (and (string-match "\n[ \t]*" (match-string 3))
4458 (not (save-match-data
4460 (goto-char (1+ end3))
4461 (looking-at "[.)]*$")))))
4462 (remove-text-properties (+ beg3 (match-beginning 0))
4463 (+ beg3 (match-end 0))
4464 '(invisible t front-sticky nil rear-nonsticky t))))))
4465 (when (and Info-refill-paragraphs Info-hide-note-references)
4466 (push (set-marker (make-marker) start)
4467 paragraph-markers))))))
4469 ;; Refill paragraphs (experimental feature)
4470 (when (and not-fontified-p
4471 Info-refill-paragraphs
4473 (let ((fill-nobreak-invisible t)
4474 (fill-individual-varying-indent nil)
4475 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4476 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4477 (adaptive-fill-mode nil))
4478 (goto-char (point-max))
4479 (dolist (m paragraph-markers)
4483 (let ((beg (point)))
4484 (when (zerop (forward-paragraph))
4485 (fill-individual-paragraphs beg (point) nil nil)
4487 (set-marker m nil))))
4489 ;; Fontify menu items
4490 (goto-char (point-min))
4491 (when (and (or not-fontified-p fontify-visited-p)
4492 (search-forward "\n* Menu:" nil t)
4493 ;; Don't take time to annotate huge menus
4494 Info-fontify-maximum-menu-size
4495 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4498 (while (re-search-forward
4499 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4500 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4502 (when (match-beginning 1)
4503 (when not-fontified-p
4505 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4506 (put-text-property (match-beginning 0)
4507 (1+ (match-beginning 0))
4508 'font-lock-face 'info-menu-star)))
4509 (when not-fontified-p
4510 (add-text-properties
4511 (match-beginning 1) (match-end 1)
4513 'help-echo (if (and (match-end 3)
4514 (not (equal (match-string 3) "")))
4515 (concat "mouse-2: go to " (match-string 3))
4516 "mouse-2: go to this node")
4517 'mouse-face 'highlight)))
4518 (when (or not-fontified-p fontify-visited-p)
4520 (match-beginning 1) (match-end 1)
4522 ;; Display visited menu items in a different face
4523 (if (and Info-fontify-visited-nodes
4525 (let* ((node (if (equal (match-string 3) "")
4526 (match-string-no-properties 1)
4527 (match-string-no-properties 3)))
4529 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4530 (file (if external-link-p
4531 (file-name-nondirectory
4532 (match-string-no-properties 1 node))
4534 (hl Info-history-list)
4537 (setq node (if (equal (match-string 2 node) "")
4539 (match-string-no-properties 2 node))))
4541 (if (and (string-equal node (nth 1 (car hl)))
4543 (if (and external-link-p
4544 (stringp (caar hl)))
4545 (file-name-nondirectory
4548 (setq res (car hl) hl nil)
4549 (setq hl (cdr hl))))
4550 res))) 'info-xref-visited 'info-xref)))
4551 (when (and not-fontified-p
4552 (memq Info-hide-note-references '(t hide))
4553 (not (Info-index-node)))
4554 (put-text-property (match-beginning 2) (1- (match-end 6))
4556 ;; Unhide the file name in parens
4557 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4558 (remove-text-properties (match-beginning 4) (match-end 4)
4560 ;; We need a stretchable space like :align-to but with
4562 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4563 (if (>= 22 (- (match-end 1)
4564 (match-beginning 0)))
4565 '(space :align-to 24)
4567 (setq cont (looking-at "."))
4568 (while (and (= (forward-line 1) 0)
4569 (looking-at "\\([ \t]+\\)[^*\n]"))
4570 (put-text-property (match-beginning 1) (1- (match-end 1))
4572 (put-text-property (1- (match-end 1)) (match-end 1)
4575 '(space :align-to 26)
4576 '(space :align-to 24)))
4579 ;; Fontify menu headers
4580 ;; Add the face `info-menu-header' to any header before a menu entry
4581 (goto-char (point-min))
4582 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4583 (put-text-property (match-beginning 0) (match-end 0)
4584 'font-lock-face 'info-menu-header)
4585 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4586 (put-text-property (match-beginning 1) (match-end 1)
4587 'font-lock-face 'info-menu-header)))
4589 ;; Hide index line numbers
4590 (goto-char (point-min))
4591 (when (and not-fontified-p (Info-index-node))
4592 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4593 (put-text-property (match-beginning 0) (match-end 0)
4596 ;; Fontify http and ftp references
4597 (goto-char (point-min))
4598 (when not-fontified-p
4599 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4601 (add-text-properties (match-beginning 0) (match-end 0)
4602 '(font-lock-face info-xref
4603 mouse-face highlight
4604 help-echo "mouse-2: go to this URL"))))
4606 (set-buffer-modified-p nil))))
4608 ;;; Speedbar support:
4609 ;; These functions permit speedbar to display the "tags" in the
4610 ;; current Info node.
4611 (eval-when-compile (require 'speedbar))
4613 (defvar Info-speedbar-key-map nil
4614 "Keymap used when in the info display mode.")
4616 (defun Info-install-speedbar-variables ()
4617 "Install those variables used by speedbar to enhance Info."
4618 (if Info-speedbar-key-map
4620 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4622 ;; Basic tree features
4623 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4624 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4625 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4626 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4629 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4630 Info-speedbar-key-map
4631 Info-speedbar-hierarchy-buttons)))
4633 (defvar Info-speedbar-menu-items
4634 '(["Browse Node" speedbar-edit-line t]
4635 ["Expand Node" speedbar-expand-line
4636 (save-excursion (beginning-of-line)
4637 (looking-at "[0-9]+: *.\\+. "))]
4638 ["Contract Node" speedbar-contract-line
4639 (save-excursion (beginning-of-line)
4640 (looking-at "[0-9]+: *.-. "))]
4642 "Additional menu-items to add to speedbar frame.")
4644 ;; Make sure our special speedbar major mode is loaded
4645 (if (featurep 'speedbar)
4646 (Info-install-speedbar-variables)
4647 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4649 ;;; Info hierarchy display method
4651 (defun Info-speedbar-browser ()
4652 "Initialize speedbar to display an Info node browser.
4653 This will add a speedbar major display mode."
4656 ;; Make sure that speedbar is active
4657 (speedbar-frame-mode 1)
4658 ;; Now, throw us into Info mode on speedbar.
4659 (speedbar-change-initial-expansion-list "Info")
4662 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4663 "Display an Info directory hierarchy in speedbar.
4664 DIRECTORY is the current directory in the attached frame.
4665 DEPTH is the current indentation depth.
4666 NODE is an optional argument that is used to represent the
4667 specific node to expand."
4669 (save-excursion (goto-char (point-min))
4670 (let ((case-fold-search t))
4671 (looking-at "Info Nodes:"))))
4672 ;; Update our "current node" maybe?
4674 ;; We cannot use the generic list code, that depends on all leaves
4675 ;; being known at creation time.
4677 (speedbar-with-writable (insert "Info Nodes:\n")))
4678 (let ((completions nil))
4679 (speedbar-select-attached-frame)
4680 (save-window-excursion
4682 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4683 (select-frame (speedbar-current-frame))
4685 (speedbar-with-writable
4686 (dolist (completion completions)
4687 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4690 'Info-speedbar-goto-node
4696 (defun Info-speedbar-goto-node (text node indent)
4697 "When user clicks on TEXT, go to an info NODE.
4698 The INDENT level is ignored."
4699 (speedbar-select-attached-frame)
4700 (let* ((buff (or (get-buffer "*info*")
4701 (progn (info) (get-buffer "*info*"))))
4702 (bwin (get-buffer-window buff 0)))
4705 (select-window bwin)
4706 (raise-frame (window-frame bwin)))
4707 (if speedbar-power-click
4708 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4709 (speedbar-select-attached-frame)
4710 (switch-to-buffer buff)))
4711 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4712 (error "Invalid node %s" node)
4713 (Info-find-node (match-string 1 node) (match-string 2 node))
4714 ;; If we do a find-node, and we were in info mode, restore
4715 ;; the old default method. Once we are in info mode, it makes
4716 ;; sense to return to whatever method the user was using before.
4717 (if (string= speedbar-initial-expansion-list-name "Info")
4718 (speedbar-change-initial-expansion-list
4719 speedbar-previously-used-expansion-list-name)))))
4721 (defun Info-speedbar-expand-node (text token indent)
4722 "Expand the node the user clicked on.
4723 TEXT is the text of the button we clicked on, a + or - item.
4724 TOKEN is data related to this node (NAME . FILE).
4725 INDENT is the current indentation depth."
4726 (cond ((string-match "+" text) ;we have to expand this file
4727 (speedbar-change-expand-button-char ?-)
4728 (if (speedbar-with-writable
4730 (end-of-line) (forward-char 1)
4731 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4732 (speedbar-change-expand-button-char ?-)
4733 (speedbar-change-expand-button-char ??)))
4734 ((string-match "-" text) ;we have to contract this node
4735 (speedbar-change-expand-button-char ?+)
4736 (speedbar-delete-subblock indent))
4737 (t (error "Ooops... not sure what to do")))
4738 (speedbar-center-buffer-smartly))
4740 (defun Info-speedbar-fetch-file-nodes (nodespec)
4741 "Fetch the subnodes from the info NODESPEC.
4742 NODESPEC is a string of the form: (file)node."
4743 ;; Set up a buffer we can use to fake-out Info.
4744 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4745 (if (not (equal major-mode 'Info-mode))
4747 ;; Get the node into this buffer
4748 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4749 (error "Invalid node specification %s" nodespec)
4750 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4751 ;; Scan the created buffer
4752 (goto-char (point-min))
4753 (let ((completions nil)
4754 (case-fold-search t)
4755 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4756 (match-string 1 nodespec))))
4757 ;; Always skip the first one...
4758 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4759 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4760 (let ((name (match-string 1)))
4762 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4764 (if (looking-at " *\\(([^)]+)\\)\\.")
4765 (concat (match-string 1) "Top")
4766 (concat "(" thisfile ")"
4767 (if (looking-at " \\([^.]+\\).")
4771 (nreverse completions))))
4773 ;;; Info mode node listing
4774 ;; This is called by `speedbar-add-localized-speedbar-support'
4775 (defun Info-speedbar-buttons (buffer)
4776 "Create a speedbar display to help navigation in an Info file.
4777 BUFFER is the buffer speedbar is requesting buttons for."
4778 (if (save-excursion (goto-char (point-min))
4779 (let ((case-fold-search t))
4780 (not (looking-at "Info Nodes:"))))
4782 (Info-speedbar-hierarchy-buttons nil 0))
4784 (dolist (mess '("^First node in file$"
4785 "^No `.*' in index$"
4786 "^No cross-reference named"
4787 "^No cross.references in this node$"
4788 "^No current Info node$"
4789 "^No menu in this node$"
4790 "^No more items in menu$"
4792 "^No pointer \\(?:forward\\|backward\\) from this node$"
4793 "^No previous `i' command$"
4794 "^No previous items in menu$"
4795 "^No previous nodes$"
4796 "^No such item in menu$"
4797 "^No such node or anchor"
4799 "^Point neither on reference nor in menu item description$"
4800 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4802 (add-to-list 'debug-ignored-errors mess))
4804 ;;;; Desktop support
4806 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4807 "Auxiliary information to be saved in desktop file."
4808 (unless (Info-virtual-file-p Info-current-file)
4809 (list Info-current-file Info-current-node)))
4811 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4813 desktop-buffer-misc)
4814 "Restore an Info buffer specified in a desktop file."
4815 (let ((first (nth 0 desktop-buffer-misc))
4816 (second (nth 1 desktop-buffer-misc)))
4817 (when (and first second)
4818 (when desktop-buffer-name
4819 (set-buffer (get-buffer-create desktop-buffer-name))
4821 (Info-find-node first second)
4824 (add-to-list 'desktop-buffer-mode-handlers
4825 '(Info-mode . Info-restore-desktop-buffer))
4827 ;;;; Bookmark support
4828 (declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
4829 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4830 (declare-function bookmark-default-handler "bookmark" (bmk))
4831 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4833 (defun Info-bookmark-make-record ()
4834 "This implements the `bookmark-make-record-function' type (which see)
4836 `(,Info-current-node
4837 ,@(bookmark-make-record-default 'point-only)
4838 (filename . ,Info-current-file)
4839 (info-node . ,Info-current-node)
4840 (handler . Info-bookmark-jump)))
4843 (defun Info-bookmark-jump (bmk)
4844 "This implements the `handler' function interface for the record
4845 type returned by `Info-bookmark-make-record', which see."
4846 (let* ((file (bookmark-prop-get bmk 'filename))
4847 (info-node (bookmark-prop-get bmk 'info-node))
4848 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4849 (Info-find-node file info-node) (current-buffer))))
4850 ;; Use bookmark-default-handler to move to the appropriate location
4852 (bookmark-default-handler
4853 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4857 ;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4858 ;;; info.el ends here