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 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29 ;; In particular we make these assumptions:
30 ;; - a menu item MAY contain colons but not colon-space ": "
31 ;; - a menu item ending with ": " (but not ":: ") is an index entry
32 ;; - a node name MAY NOT contain a colon
33 ;; This distinction is to support indexing of computer programming
34 ;; language terms that may contain ":" but not ": ".
38 (eval-when-compile (require 'jka-compr
))
46 (defvar Info-history nil
47 "Stack of info nodes user has visited.
48 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50 (defvar Info-history-forward nil
51 "Stack of info nodes user has visited with `Info-history-back' command.
52 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
54 (defvar Info-history-list nil
55 "List of all info nodes user has visited.
56 Each element of list is a list (FILENAME NODENAME).")
58 (defcustom Info-enable-edit nil
59 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
60 This is convenient if you want to write info files by hand.
61 However, we recommend that you not do this.
62 It is better to write a Texinfo file and generate the Info file from that,
63 because that gives you a printed manual as well."
67 (defvar Info-enable-active-nodes nil
68 "Non-nil allows Info to execute Lisp code associated with nodes.
69 The Lisp code is executed when the node is selected.")
70 (put 'Info-enable-active-nodes
'risky-local-variable t
)
73 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
74 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
75 (t :weight bold
:slant italic
))
76 "Face for Info node names."
80 '((((class color
)) :foreground
"red1")
82 "Face for every third `*' in an Info menu."
87 (class color
) (background light
)) :foreground
"blue1" :underline t
)
88 (((class color
) (background light
)) :foreground
"blue" :underline t
)
90 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
91 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
93 "Face for Info cross-references."
96 (defface info-xref-visited
97 '((default :inherit info-xref
)
98 (((class color
) (background light
)) :foreground
"magenta4")
99 (((class color
) (background dark
)) :foreground
"magenta3")) ;"violet"?
100 "Face for visited Info cross-references."
103 (defcustom Info-fontify-visited-nodes t
104 "*Non-nil means to fontify visited nodes in a different face."
109 (defcustom Info-fontify-maximum-menu-size
100000
110 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
114 (defcustom Info-use-header-line t
115 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
116 A header-line does not scroll with the rest of the buffer."
120 (defface info-header-xref
121 '((t :inherit info-xref
))
122 "Face for Info cross-references in a node header."
125 (defface info-header-node
126 '((t :inherit info-node
))
127 "Face for Info nodes in a node header."
130 (defvar Info-directory-list nil
131 "List of directories to search for Info documentation files.
132 If nil, meaning not yet initialized, Info uses the environment
133 variable INFOPATH to initialize it, or `Info-default-directory-list'
134 if there is no INFOPATH variable in the environment, or the
135 concatenation of the two if INFOPATH ends with a colon.
137 When `Info-directory-list' is initialized from the value of
138 `Info-default-directory-list', and Emacs is installed in one of the
139 standard directories, the directory of Info files that come with Emacs
140 is put last (so that local Info files override standard ones).
142 When `Info-directory-list' is initialized from the value of
143 `Info-default-directory-list', and Emacs is not installed in one
144 of the standard directories, the first element of the resulting
145 list is the directory where Emacs installs the Info files that
146 come with it. This is so that Emacs's own manual, which suits the
147 version of Emacs you are using, will always be found first. This
148 is useful when you install an experimental version of Emacs without
149 removing the standard installation.
151 If you want to override the order of directories in
152 `Info-default-directory-list', set INFOPATH in the environment.
154 If you run the Emacs executable from the `src' directory in the Emacs
155 source tree, and INFOPATH is not defined, the `info' directory in the
156 source tree is used as the first element of `Info-directory-list', in
157 place of the installation Info directory. This is useful when you run
158 a version of Emacs without installing it.")
160 (defcustom Info-additional-directory-list nil
161 "List of additional directories to search for Info documentation files.
162 These directories are searched after those in `Info-directory-list'."
163 :type
'(repeat directory
)
166 (defcustom Info-scroll-prefer-subnodes nil
167 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
168 If this is non-nil, and you scroll far enough in a node that its menu
169 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
170 moves to a subnode indicated by the following menu item. This means
171 that you visit a subnode before getting to the end of the menu.
173 Setting this option to nil results in behavior similar to the stand-alone
174 Info reader program, which visits the first subnode from the menu only
175 when you hit the end of the current node."
180 (defcustom Info-hide-note-references t
181 "*If non-nil, hide the tag and section reference in *note and * menu items.
182 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
183 If value is non-nil but not t or `hide', the reference section is still shown."
185 :type
'(choice (const :tag
"No hiding" nil
)
186 (const :tag
"Replace tag and hide reference" t
)
187 (const :tag
"Hide tag and reference" hide
)
188 (other :tag
"Only replace tag" tag
))
191 (defcustom Info-refill-paragraphs nil
192 "*If non-nil, attempt to refill paragraphs with hidden references.
193 This refilling may accidentally remove explicit line breaks in the info
194 file, so be prepared for a few surprises if you enable this feature."
199 (defcustom Info-search-whitespace-regexp
"\\s-+"
200 "*If non-nil, regular expression to match a sequence of whitespace chars.
201 This applies to Info search for regular expressions.
202 You might want to use something like \"[ \\t\\r\\n]+\" instead.
203 In the Customization buffer, that is `[' followed by a space,
204 a tab, a carriage return (control-M), a newline, and `]+'."
208 (defcustom Info-isearch-search t
209 "*If non-nil, isearch in Info searches through multiple nodes.
210 Before leaving the initial Info node, where isearch was started,
211 it fails once with the error message [initial node], and with
212 subsequent C-s/C-r continues through other nodes without failing
213 with this error message in other nodes. When isearch fails for
214 the rest of the manual, it wraps aroung the whole manual and
215 restarts the search from the top/final node depending on
218 Setting this option to nil restores the default isearch behavior
219 with wrapping around the current Info node."
224 (defvar Info-isearch-initial-node nil
)
226 (defcustom Info-mode-hook
227 ;; Try to obey obsolete Info-fontify settings.
228 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
229 '(turn-on-font-lock))
230 "Hooks run when `Info-mode' is called."
234 (defcustom Info-selection-hook nil
235 "Hooks run when `Info-select-node' is called."
239 (defvar Info-edit-mode-hook nil
240 "Hooks run when `Info-edit-mode' is called.")
242 (defvar Info-current-file nil
243 "Info file that Info is now looking at, or nil.
244 This is the name that was specified in Info, not the actual file name.
245 It doesn't contain directory names or file name extensions added by Info.
246 Can also be t when using `Info-on-current-buffer'.")
248 (defvar Info-current-subfile nil
249 "Info subfile that is actually in the *info* buffer now.
250 nil if current info file is not split into subfiles.")
252 (defvar Info-current-node nil
253 "Name of node that Info is now looking at, or nil.")
255 (defvar Info-tag-table-marker nil
256 "Marker pointing at beginning of current Info file's tag table.
257 Marker points nowhere if file has no tag table.")
259 (defvar Info-tag-table-buffer nil
260 "Buffer used for indirect tag tables.")
262 (defvar Info-current-file-completions nil
263 "Cached completion list for current Info file.")
265 (defvar Info-index-alternatives nil
266 "List of possible matches for last `Info-index' command.")
268 (defvar Info-point-loc nil
269 "Point location within a selected node.
270 If string, the point is moved to the proper occurrence of the
271 name of the followed cross reference within a selected node.
272 If number, the point is moved to the corresponding line.")
274 (defvar Info-standalone nil
275 "Non-nil if Emacs was started solely as an Info browser.")
277 (defvar Info-suffix-list
278 ;; The MS-DOS list should work both when long file names are
279 ;; supported (Windows 9X), and when only 8+3 file names are available.
280 (if (eq system-type
'ms-dos
)
281 '( (".gz" .
"gunzip")
283 (".bz2" .
("bzip2" "-dc"))
286 (".info.Z" .
"gunzip")
287 (".info.gz" .
"gunzip")
288 ("-info.Z" .
"gunzip")
289 ("-info.gz" .
"gunzip")
290 ("/index.gz".
"gunzip")
291 ("/index.z" .
"gunzip")
297 '( (".info.Z".
"uncompress")
298 (".info.Y".
"unyabba")
299 (".info.gz".
"gunzip")
300 (".info.z".
"gunzip")
301 (".info.bz2" .
("bzip2" "-dc"))
303 ("-info.Z".
"uncompress")
304 ("-info.Y".
"unyabba")
305 ("-info.gz".
"gunzip")
306 ("-info.bz2" .
("bzip2" "-dc"))
307 ("-info.z".
"gunzip")
309 ("/index.Z".
"uncompress")
310 ("/index.Y".
"unyabba")
311 ("/index.gz".
"gunzip")
312 ("/index.z".
"gunzip")
313 ("/index.bz2".
("bzip2" "-dc"))
319 (".bz2" .
("bzip2" "-dc"))
321 "List of file name suffixes and associated decoding commands.
322 Each entry should be (SUFFIX . STRING); the file is given to
323 the command as standard input.
325 STRING may be a list of strings. In that case, the first element is
326 the command name, and the rest are arguments to that command.
328 If STRING is nil, no decoding is done.
329 Because the SUFFIXes are tried in order, the empty string should
330 be last in the list.")
332 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
333 ;; First, on MS-DOS with no long file names support, delete some of
334 ;; the extension in FILENAME to make room.
335 (defun info-insert-file-contents-1 (filename suffix lfn
)
336 (if lfn
; long file names are supported
337 (concat filename suffix
)
338 (let* ((sans-exts (file-name-sans-extension filename
))
339 ;; How long is the extension in FILENAME (not counting the dot).
340 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
342 ;; SUFFIX starts with a dot. If FILENAME already has one,
343 ;; get rid of the one in SUFFIX (unless suffix is empty).
344 (or (and (<= ext-len
0)
345 (not (eq (aref filename
(1- (length filename
))) ?.
)))
346 (= (length suffix
) 0)
347 (setq suffix
(substring suffix
1)))
348 ;; How many chars of that extension should we keep?
349 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
350 ;; Get rid of the rest of the extension, and add SUFFIX.
351 (concat (substring filename
0 (- (length filename
)
352 (- ext-len ext-left
)))
355 (defun info-file-exists-p (filename)
356 (and (file-exists-p filename
)
357 (not (file-directory-p filename
))))
359 (defun info-insert-file-contents (filename &optional visit
)
360 "Insert the contents of an info file in the current buffer.
361 Do the right thing if the file has been compressed or zipped."
362 (let* ((tail Info-suffix-list
)
363 (lfn (if (fboundp 'msdos-long-file-names
)
364 (msdos-long-file-names)
366 (check-short (and (fboundp 'msdos-long-file-names
)
368 fullname decoder done
)
369 (if (info-file-exists-p filename
)
370 ;; FILENAME exists--see if that name contains a suffix.
371 ;; If so, set DECODE accordingly.
375 (concat (regexp-quote (car (car tail
))) "$")
377 (setq tail
(cdr tail
)))
378 (setq fullname filename
379 decoder
(cdr (car tail
))))
380 ;; Try adding suffixes to FILENAME and see if we can find something.
381 (while (and tail
(not done
))
382 (setq fullname
(info-insert-file-contents-1 filename
383 (car (car tail
)) lfn
))
384 (if (info-file-exists-p fullname
)
386 ;; If we found a file with a suffix, set DECODER
387 ;; according to the suffix.
388 decoder
(cdr (car tail
)))
389 ;; When the MS-DOS port runs on Windows, we need to check
390 ;; the short variant of a long file name as well.
392 (setq fullname
(info-insert-file-contents-1 filename
393 (car (car tail
)) nil
))
394 (if (info-file-exists-p fullname
)
396 decoder
(cdr (car tail
))))))
397 (setq tail
(cdr tail
)))
399 (error "Can't find %s or any compressed version of it" filename
)))
400 ;; check for conflict with jka-compr
401 (if (and (featurep 'jka-compr
)
402 (jka-compr-installed-p)
403 (jka-compr-get-compression-info fullname
))
407 (insert-file-contents-literally fullname visit
)
408 (let ((buffer-read-only nil
)
409 (coding-system-for-write 'no-conversion
)
410 (default-directory (or (file-name-directory fullname
)
413 (setq decoder
(list decoder
)))
414 (apply 'call-process-region
(point-min) (point-max)
415 (car decoder
) t t nil
(cdr decoder
))))
416 (insert-file-contents fullname visit
))))
418 (defun Info-default-dirs ()
419 (let ((source (expand-file-name "info/" source-directory
))
420 (sibling (if installation-directory
421 (expand-file-name "info/" installation-directory
)
422 (if invocation-directory
423 (let ((infodir (expand-file-name
425 invocation-directory
)))
426 (if (file-exists-p infodir
)
428 (setq infodir
(expand-file-name
430 invocation-directory
))
431 (and (file-exists-p infodir
)
435 (if (and sibling
(file-exists-p sibling
))
436 ;; Uninstalled, Emacs builddir != srcdir.
438 ;; Uninstalled, builddir == srcdir
440 (if (or (member alternative Info-default-directory-list
)
441 ;; On DOS/NT, we use movable executables always,
442 ;; and we must always find the Info dir at run time.
443 (if (memq system-type
'(ms-dos windows-nt
))
445 ;; Use invocation-directory for Info
446 ;; only if we used it for exec-directory also.
447 (not (string= exec-directory
448 (expand-file-name "lib-src/"
449 installation-directory
))))
450 (not (file-exists-p alternative
)))
451 Info-default-directory-list
452 ;; `alternative' contains the Info files that came with this
453 ;; version, so we should look there first. `Info-insert-dir'
454 ;; currently expects to find `alternative' first on the list.
456 ;; Don't drop the last part, it might contain non-Emacs stuff.
457 ;; (reverse (cdr (reverse
458 Info-default-directory-list
)))) ;; )))
460 (defun info-initialize ()
461 "Initialize `Info-directory-list', if that hasn't been done yet."
462 (unless Info-directory-list
463 (let ((path (getenv "INFOPATH")))
464 (setq Info-directory-list
465 (prune-directory-list
467 (if (string-match ":\\'" path
)
468 (append (split-string (substring path
0 -
1)
469 (regexp-quote path-separator
))
471 (split-string path
(regexp-quote path-separator
)))
472 (Info-default-dirs)))))))
475 (defun info-other-window (&optional file
)
476 "Like `info' but show the Info buffer in another window."
477 (interactive (if current-prefix-arg
478 (list (read-file-name "Info file name: " nil nil t
))))
479 (let (same-window-buffer-names same-window-regexps
)
482 ;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
484 ;;;###autoload (put 'info 'info-file "emacs")
486 (defun info (&optional file buffer
)
487 "Enter Info, the documentation browser.
488 Optional argument FILE specifies the file to examine;
489 the default is the top-level directory of Info.
490 Called from a program, FILE may specify an Info node of the form
491 `(FILENAME)NODENAME'.
492 Optional argument BUFFER specifies the Info buffer name;
493 the default buffer name is *info*. If BUFFER exists,
494 just switch to BUFFER. Otherwise, create a new buffer
495 with the top-level Info directory.
497 In interactive use, a non-numeric prefix argument directs
498 this command to read a file name from the minibuffer.
499 A numeric prefix argument selects an Info buffer with the prefix number
500 appended to the Info buffer name.
502 The search path for Info files is in the variable `Info-directory-list'.
503 The top-level Info directory is made by combining all the files named `dir'
504 in all the directories in that path."
506 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
507 (read-file-name "Info file name: " nil nil t
))
508 (if (numberp current-prefix-arg
)
509 (format "*info*<%s>" current-prefix-arg
))))
510 (pop-to-buffer (or buffer
"*info*"))
511 (if (and buffer
(not (eq major-mode
'Info-mode
)))
514 ;; If argument already contains parentheses, don't add another set
515 ;; since the argument will then be parsed improperly. This also
516 ;; has the added benefit of allowing node names to be included
517 ;; following the parenthesized filename.
519 (if (and (stringp file
) (string-match "(.*)" file
))
521 (concat "(" file
")")))
522 (if (zerop (buffer-size))
526 (defun info-emacs-manual ()
527 "Display the Emacs manual in Info mode."
532 (defun info-standalone ()
533 "Run Emacs as a standalone Info reader.
534 Usage: emacs -f info-standalone [filename]
535 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
536 (setq Info-standalone t
)
537 (if (and command-line-args-left
538 (not (string-match "^-" (car command-line-args-left
))))
541 (info (car command-line-args-left
))
542 (setq command-line-args-left
(cdr command-line-args-left
)))
543 (error (send-string-to-terminal
544 (format "%s\n" (if (eq (car-safe err
) 'error
)
546 (save-buffers-kill-emacs)))
549 ;; See if the accessible portion of the buffer begins with a node
550 ;; delimiter, and the node header line which follows matches REGEXP.
551 ;; Typically, this test will be followed by a loop that examines the
552 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
553 ;; to have the overhead of this special test inside the loop.
555 ;; This function changes match-data, but supposedly the caller might
556 ;; want to use the results of re-search-backward.
558 ;; The return value is the value of point at the beginning of matching
559 ;; REGEXP, if the function succeeds, nil otherwise.
560 (defun Info-node-at-bob-matching (regexp)
561 (and (bobp) ; are we at beginning of buffer?
562 (looking-at "\^_") ; does it begin with node delimiter?
566 (forward-line 1) ; does the line after delimiter match REGEXP?
567 (re-search-backward regexp beg t
))))
569 (defun Info-find-file (filename &optional noerror
)
570 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
571 Optional second argument NOERROR, if t, means if file is not found
572 just return nil (no error)."
573 ;; Convert filename to lower case if not found as specified.
575 (if (stringp filename
)
576 (let (temp temp-downcase found
)
577 (setq filename
(substitute-in-file-name filename
))
579 ((string= (downcase filename
) "dir")
581 ((string= filename
"apropos")
582 (setq found
'apropos
))
583 ((string= filename
"history")
584 (setq found
'history
))
585 ((string= filename
"toc")
588 (let ((dirs (if (string-match "^\\./" filename
)
589 ;; If specified name starts with `./'
590 ;; then just try current directory.
592 (if (file-name-absolute-p filename
)
593 ;; No point in searching for an
594 ;; absolute file name
596 (if Info-additional-directory-list
597 (append Info-directory-list
598 Info-additional-directory-list
)
599 Info-directory-list
)))))
600 ;; Search the directory list for file FILENAME.
601 (while (and dirs
(not found
))
602 (setq temp
(expand-file-name filename
(car dirs
)))
604 (expand-file-name (downcase filename
) (car dirs
)))
605 ;; Try several variants of specified name.
606 (let ((suffix-list Info-suffix-list
)
607 (lfn (if (fboundp 'msdos-long-file-names
)
608 (msdos-long-file-names)
610 (while (and suffix-list
(not found
))
611 (cond ((info-file-exists-p
612 (info-insert-file-contents-1
613 temp
(car (car suffix-list
)) lfn
))
616 (info-insert-file-contents-1
617 temp-downcase
(car (car suffix-list
)) lfn
))
618 (setq found temp-downcase
))
619 ((and (fboundp 'msdos-long-file-names
)
622 (info-insert-file-contents-1
623 temp
(car (car suffix-list
)) nil
)))
625 (setq suffix-list
(cdr suffix-list
))))
626 (setq dirs
(cdr dirs
))))))
628 (setq filename found
)
631 (error "Info file %s does not exist" filename
)))
634 (defun Info-find-node (filename nodename
&optional no-going-back
)
635 "Go to an info node specified as separate FILENAME and NODENAME.
636 NO-GOING-BACK is non-nil if recovering from an error in this function;
637 it says do not attempt further (recursive) error recovery."
639 (setq filename
(Info-find-file filename
))
640 ;; Go into info buffer.
641 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
642 ;; Record the node we are leaving.
643 (if (and Info-current-file
(not no-going-back
))
645 (cons (list Info-current-file Info-current-node
(point))
647 (Info-find-node-2 filename nodename no-going-back
))
649 (defun Info-on-current-buffer (&optional nodename
)
650 "Use the `Info-mode' to browse the current info buffer.
651 If a prefix arg is provided, it queries for the NODENAME which
652 else defaults to \"Top\"."
654 (list (if current-prefix-arg
655 (completing-read "Node name: " (Info-build-node-completions)
657 (unless nodename
(setq nodename
"Top"))
660 (set (make-local-variable 'Info-current-file
) t
)
661 (Info-find-node-2 nil nodename
))
663 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
664 ;; but at least it keeps this routine (which is only for the benefit of
665 ;; makeinfo-buffer) out of the way of normal operations.
667 (defun Info-revert-find-node (filename nodename
)
668 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
669 When *info* is already displaying FILENAME and NODENAME, the window position
670 is preserved, if possible."
671 (pop-to-buffer "*info*")
672 (let ((old-filename Info-current-file
)
673 (old-nodename Info-current-node
)
674 (pcolumn (current-column))
675 (pline (count-lines (point-min) (line-beginning-position)))
676 (wline (count-lines (point-min) (window-start)))
677 (old-history Info-history
)
678 (new-history (and Info-current-file
679 (list Info-current-file Info-current-node
(point)))))
680 (kill-buffer (current-buffer))
681 (Info-find-node filename nodename
)
682 (setq Info-history old-history
)
683 (if (and (equal old-filename Info-current-file
)
684 (equal old-nodename Info-current-node
))
686 ;; note goto-line is no good, we want to measure from point-min
687 (goto-char (point-min))
689 (set-window-start (selected-window) (point))
690 (goto-char (point-min))
692 (move-to-column pcolumn
))
693 ;; only add to the history when coming from a different file+node
695 (setq Info-history
(cons new-history Info-history
))))))
697 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
698 "Find a node in a tag table.
699 MARKER specifies the buffer and position to start searching at.
700 REGEXP is a regular expression matching nodes or references. Its first
701 group should match `Node:' or `Ref:'.
702 CASE-FOLD t means search for a case-insensitive match.
703 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
704 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
705 where the match was found, and MODE is `major-mode' of the buffer in
706 which the match was found."
707 (let ((case-fold-search case-fold
))
709 (set-buffer (marker-buffer marker
))
714 (when (re-search-forward regexp nil t
)
715 (list (string-equal "Ref:" (match-string 1))
716 (+ (point-min) (read (current-buffer)))
719 (defun Info-find-in-tag-table (marker regexp
)
720 "Find a node in a tag table.
721 MARKER specifies the buffer and position to start searching at.
722 REGEXP is a regular expression matching nodes or references. Its first
723 group should match `Node:' or `Ref:'.
724 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
725 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
726 where the match was found, and MODE is `major-mode' of the buffer in
727 which the match was found.
728 This function tries to find a case-sensitive match first, then a
729 case-insensitive match is tried."
730 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
731 (when (null (car result
))
732 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
735 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
736 "Find a node or anchor in the current buffer.
737 REGEXP is a regular expression matching nodes or references. Its first
738 group should match `Node:' or `Ref:'.
739 CASE-FOLD t means search for a case-insensitive match.
740 Value is the position at which a match was found, or nil if not found."
741 (let ((case-fold-search case-fold
)
744 (when (Info-node-at-bob-matching regexp
)
745 (setq found
(point)))
746 (while (and (not found
)
747 (search-forward "\n\^_" nil t
))
751 (when (re-search-backward regexp beg t
)
753 (setq found
(point)))))
756 (defun Info-find-node-in-buffer (regexp)
757 "Find a node or anchor in the current buffer.
758 REGEXP is a regular expression matching nodes or references. Its first
759 group should match `Node:' or `Ref:'.
760 Value is the position at which a match was found, or nil if not found.
761 This function looks for a case-sensitive match first. If none is found,
762 a case-insensitive match is tried."
763 (or (Info-find-node-in-buffer-1 regexp nil
)
764 (Info-find-node-in-buffer-1 regexp t
)))
766 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
767 (buffer-disable-undo (current-buffer))
768 (or (eq major-mode
'Info-mode
)
771 (setq Info-current-node nil
)
773 (let ((case-fold-search t
)
775 ;; Switch files if necessary
777 (equal Info-current-file filename
)
778 (let ((buffer-read-only nil
))
779 (setq Info-current-file nil
780 Info-current-subfile nil
781 Info-current-file-completions nil
782 buffer-file-name nil
)
787 ((eq filename
'apropos
)
788 (insert-buffer-substring " *info-apropos*"))
789 ((eq filename
'history
)
790 (insert-buffer-substring " *info-history*"))
792 (insert-buffer-substring " *info-toc*"))
794 (info-insert-file-contents filename nil
)
795 (setq default-directory
(file-name-directory filename
))))
796 (set-buffer-modified-p nil
)
797 ;; See whether file has a tag table. Record the location if yes.
798 (goto-char (point-max))
800 ;; Use string-equal, not equal, to ignore text props.
801 (if (not (or (string-equal nodename
"*")
803 (search-forward "\^_\nEnd tag table\n" nil t
))))
805 ;; We have a tag table. Find its beginning.
806 ;; Is this an indirect file?
807 (search-backward "\nTag table:\n")
811 (looking-at "(Indirect)\n"))
812 ;; It is indirect. Copy it to another buffer
813 ;; and record that the tag table is in that buffer.
814 (let ((buf (current-buffer))
816 (or Info-tag-table-buffer
817 (generate-new-buffer " *info tag table*"))))
818 (setq Info-tag-table-buffer tagbuf
)
821 (buffer-disable-undo (current-buffer))
822 (setq case-fold-search t
)
824 (insert-buffer-substring buf
))
825 (set-marker Info-tag-table-marker
826 (match-end 0) tagbuf
))
827 (set-marker Info-tag-table-marker pos
)))
828 (set-marker Info-tag-table-marker nil
))
829 (setq Info-current-file
831 ((eq filename t
) "dir")
832 ((eq filename
'apropos
) "apropos")
833 ((eq filename
'history
) "history")
834 ((eq filename
'toc
) "toc")
837 ;; Use string-equal, not equal, to ignore text props.
838 (if (string-equal nodename
"*")
839 (progn (setq Info-current-node nodename
)
840 (Info-set-mode-line))
843 ;; 1. Anchor found in tag table
844 ;; 2. Anchor *not* in tag table
846 ;; 3. Node found in tag table
847 ;; 4. Node *not* found in tag table, but found in file
848 ;; 5. Node *not* in tag table, and *not* in file
850 ;; *Or* the same, but in an indirect subfile.
852 ;; Search file for a suitable node.
853 (let ((guesspos (point-min))
854 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
855 (if (stringp nodename
)
856 (regexp-quote nodename
)
858 "\\) *[,\t\n\177]")))
862 ;; First, search a tag table, if any
863 (when (marker-position Info-tag-table-marker
)
864 (let* ((m Info-tag-table-marker
)
865 (found (Info-find-in-tag-table m regexp
)))
868 ;; FOUND is (ANCHOR POS MODE).
869 (setq guesspos
(nth 1 found
))
871 ;; If this is an indirect file, determine which
872 ;; file really holds this node and read it in.
873 (unless (eq (nth 2 found
) 'Info-mode
)
874 ;; Note that the current buffer must be the
875 ;; *info* buffer on entry to
876 ;; Info-read-subfile. Thus the hackery above.
877 (setq guesspos
(Info-read-subfile guesspos
)))
881 (goto-char (setq anchorpos guesspos
))
884 ;; Else we may have a node, which we search for:
885 (goto-char (max (point-min)
886 (- (byte-to-position guesspos
) 1000)))
888 ;; Now search from our advised position (or from beg of
889 ;; buffer) to find the actual node. First, check
890 ;; whether the node is right where we are, in case the
891 ;; buffer begins with a node.
892 (let ((pos (Info-find-node-in-buffer regexp
)))
897 (when (string-match "\\([^.]+\\)\\." nodename
)
898 (let (Info-point-loc)
900 filename
(match-string 1 nodename
) no-going-back
))
904 ;; No such anchor in tag table or node in tag table or file
905 (error "No such node or anchor: %s" nodename
))
908 (goto-char (point-min))
910 (let ((new-history (list Info-current-file
911 (substring-no-properties nodename
))))
912 ;; Add anchors to the history too
913 (setq Info-history-list
915 (delete new-history Info-history-list
))))
916 (goto-char anchorpos
))
917 ((numberp Info-point-loc
)
918 (forward-line (1- Info-point-loc
))
919 (setq Info-point-loc nil
))
920 ((stringp Info-point-loc
)
921 (Info-find-index-name Info-point-loc
)
922 (setq Info-point-loc nil
))))))
923 ;; If we did not finish finding the specified node,
924 ;; go back to the previous one.
925 (or Info-current-node no-going-back
(null Info-history
)
926 (let ((hist (car Info-history
)))
927 (setq Info-history
(cdr Info-history
))
928 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
929 (goto-char (nth 2 hist
))))))
931 ;; Cache the contents of the (virtual) dir file, once we have merged
932 ;; it for the first time, so we can save time subsequently.
933 (defvar Info-dir-contents nil
)
935 ;; Cache for the directory we decided to use for the default-directory
936 ;; of the merged dir text.
937 (defvar Info-dir-contents-directory nil
)
939 ;; Record the file attributes of all the files from which we
940 ;; constructed Info-dir-contents.
941 (defvar Info-dir-file-attributes nil
)
943 (defvar Info-dir-file-name nil
)
945 ;; Construct the Info directory node by merging the files named `dir'
946 ;; from various directories. Set the *info* buffer's
947 ;; default-directory to the first directory we actually get any text
949 (defun Info-insert-dir ()
950 (if (and Info-dir-contents Info-dir-file-attributes
951 ;; Verify that none of the files we used has changed
954 (mapcar (lambda (elt)
955 (let ((curr (file-attributes
957 (file-truename (car elt
)))))
959 ;; Don't compare the access time.
960 (if curr
(setcar (nthcdr 4 curr
) 0))
961 (setcar (nthcdr 4 (cdr elt
)) 0)
962 (equal (cdr elt
) curr
)))
963 Info-dir-file-attributes
))))
965 (insert Info-dir-contents
)
966 (goto-char (point-min)))
967 (let ((dirs (if Info-additional-directory-list
968 (append Info-directory-list
969 Info-additional-directory-list
)
970 Info-directory-list
))
972 ;; Bind this in case the user sets it to nil.
974 ;; This is set non-nil if we find a problem in some input files.
976 buffers buffer others nodes dirs-done
)
978 ;; Search the directory list for the directory file.
980 (let ((truename (file-truename (expand-file-name (car dirs
)))))
981 (or (member truename dirs-done
)
982 (member (directory-file-name truename
) dirs-done
)
983 ;; Try several variants of specified name.
984 ;; Try upcasing, appending `.info', or both.
988 (progn (setq file
(expand-file-name "dir" truename
))
989 (file-attributes file
))
990 (progn (setq file
(expand-file-name "DIR" truename
))
991 (file-attributes file
))
992 (progn (setq file
(expand-file-name "dir.info" truename
))
993 (file-attributes file
))
994 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
995 (file-attributes file
)))))
998 (cons (directory-file-name truename
)
1003 (message "Composing main Info directory..."))
1004 (set-buffer (generate-new-buffer " info dir"))
1007 (insert-file-contents file
)
1008 (set (make-local-variable 'Info-dir-file-name
)
1010 (push (current-buffer) buffers
)
1011 (push (cons file attrs
) dir-file-attrs
))
1012 (error (kill-buffer (current-buffer))))))))
1014 (set (make-local-variable 'Info-dir-contents-directory
)
1015 (file-name-as-directory (car dirs
))))
1016 (setq dirs
(cdr dirs
))))
1019 (error "Can't find the Info directory node"))
1021 ;; Distinguish the dir file that comes with Emacs from all the
1022 ;; others. Yes, that is really what this is supposed to do.
1023 ;; The definition of `Info-directory-list' puts it first on that
1024 ;; list and so last in `buffers' at this point.
1025 (setq buffer
(car (last buffers
))
1026 others
(delq buffer buffers
))
1028 ;; Insert the entire original dir file as a start; note that we've
1029 ;; already saved its default directory to use as the default
1030 ;; directory for the whole concatenation.
1031 (insert-buffer buffer
)
1033 ;; Look at each of the other buffers one by one.
1034 (dolist (other others
)
1035 (let (this-buffer-nodes)
1036 ;; In each, find all the menus.
1037 (with-current-buffer other
1038 (goto-char (point-min))
1039 ;; Find each menu, and add an elt to NODES for it.
1040 (while (re-search-forward "^\\* Menu:" nil t
)
1041 (while (and (zerop (forward-line 1)) (eolp)))
1044 (re-search-backward "^\^_")
1045 (search-forward "Node: ")
1046 (setq nodename
(Info-following-node-name))
1047 (search-forward "\n\^_" nil
'move
)
1050 (push (list nodename other beg end
) this-buffer-nodes
)))
1051 (if (assoc-string "top" this-buffer-nodes t
)
1052 (setq nodes
(nconc this-buffer-nodes nodes
))
1054 (message "No `top' node in %s" Info-dir-file-name
)))))
1055 ;; Add to the main menu a menu item for each other node.
1056 (re-search-forward "^\\* Menu:")
1058 (let ((menu-items '("top"))
1059 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1060 (dolist (node nodes
)
1061 (let ((nodename (car node
)))
1063 (or (member (downcase nodename
) menu-items
)
1064 (re-search-forward (concat "^\\* +"
1065 (regexp-quote nodename
)
1069 (insert "* " nodename
"::" "\n")
1070 (push nodename menu-items
)))))))
1071 ;; Now take each node of each of the other buffers
1072 ;; and merge it into the main buffer.
1073 (dolist (node nodes
)
1074 (let ((case-fold-search t
)
1075 (nodename (car node
)))
1076 (goto-char (point-min))
1077 ;; Find the like-named node in the main buffer.
1078 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1079 (regexp-quote nodename
)
1083 (search-forward "\n\^_" nil
'move
)
1086 ;; If none exists, add one.
1087 (goto-char (point-max))
1088 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1089 ;; Merge the text from the other buffer's menu
1090 ;; into the menu in the like-named node in the main buffer.
1091 (apply 'insert-buffer-substring
(cdr node
))))
1092 (Info-dir-remove-duplicates)
1093 ;; Kill all the buffers we just made, including the special one excised.
1094 (mapc 'kill-buffer
(cons buffer buffers
))
1095 (goto-char (point-min))
1097 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1098 (message "Composing main Info directory...done"))
1099 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1100 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1101 (setq default-directory Info-dir-contents-directory
))
1103 (defvar Info-streamline-headings
1104 '(("Emacs" .
"Emacs")
1105 ("Programming" .
"Programming")
1106 ("Libraries" .
"Libraries")
1107 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1108 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1110 (defun Info-dir-remove-duplicates ()
1112 (goto-char (point-min))
1113 ;; Remove duplicate headings in the same menu.
1114 (while (search-forward "\n* Menu:" nil t
)
1115 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1116 ;; Look for the next heading to unify.
1117 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1118 (let ((name (match-string 1))
1119 (start (match-beginning 0))
1121 ;; Check whether this heading should be streamlined.
1123 (dolist (x Info-streamline-headings
)
1124 (when (string-match (car x
) name
)
1126 (setq re
(car x
)))))
1127 (if re
(replace-match name t t nil
1))
1128 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1130 (or limit
(point-max))))
1131 ;; Look for other headings of the same category and merge them.
1133 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1134 (when (if re
(save-match-data (string-match re
(match-string 1)))
1135 (equal name
(match-string 1)))
1137 ;; Delete redundant heading.
1138 (delete-region (match-beginning 0) (point))
1139 ;; Push the entries onto `text'.
1141 (delete-and-extract-region
1143 (if (re-search-forward "^[^* \n\t]" nil t
)
1145 (or limit
(point-max)))) entries
))))
1146 ;; Insert the entries just found.
1147 (while (= (line-beginning-position 0) (1- (point)))
1149 (dolist (entry (nreverse entries
))
1151 (while (= (line-beginning-position 0) (1- (point)))
1152 (delete-region (1- (point)) (point))))
1154 ;; Now remove duplicate entries under the same heading.
1158 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1160 (let ((x (match-string 1)))
1161 (if (member-ignore-case x seen
)
1162 (delete-region (match-beginning 0)
1163 (progn (re-search-forward "^[^ \t]" nil t
)
1164 (match-beginning 0)))
1165 (push x seen
))))))))))
1167 ;; Note that on entry to this function the current-buffer must be the
1168 ;; *info* buffer; not the info tags buffer.
1169 (defun Info-read-subfile (nodepos)
1170 ;; NODEPOS is either a position (in the Info file as a whole,
1171 ;; not relative to a subfile) or the name of a subfile.
1174 (if (numberp nodepos
)
1176 (set-buffer (marker-buffer Info-tag-table-marker
))
1177 (goto-char (point-min))
1178 (or (looking-at "\^_")
1179 (search-forward "\n\^_"))
1182 (while (not (looking-at "\^_"))
1185 thisfilepos thisfilename
)
1186 (search-forward ": ")
1187 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1188 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1189 ;; read in version 19 stops at the end of number.
1190 ;; Advance to the next line.
1192 (if (> thisfilepos nodepos
)
1194 (setq lastfilename thisfilename
)
1195 (setq lastfilepos thisfilepos
))
1196 (forward-line 1)))))
1197 (setq lastfilename nodepos
)
1198 (setq lastfilepos
0))
1199 ;; Assume previous buffer is in Info-mode.
1200 ;; (set-buffer (get-buffer "*info*"))
1201 (or (equal Info-current-subfile lastfilename
)
1202 (let ((buffer-read-only nil
))
1203 (setq buffer-file-name nil
)
1206 (info-insert-file-contents lastfilename
)
1207 (set-buffer-modified-p nil
)
1208 (setq Info-current-subfile lastfilename
)))
1209 ;; Widen in case we are in the same subfile as before.
1211 (goto-char (point-min))
1212 (if (looking-at "\^_")
1214 (search-forward "\n\^_"))
1215 (if (numberp nodepos
)
1216 (+ (- nodepos lastfilepos
) (point)))))
1218 (defun Info-unescape-quotes (value)
1219 "Unescape double quotes and backslashes in VALUE."
1222 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1223 (setq unquote
(replace-match "" t t unquote
1))
1224 (setq start
(- (match-end 0) 1)))
1227 ;; As of Texinfo 4.6, makeinfo writes constructs like
1228 ;; \0\h[image param=value ...\h\0]
1229 ;; into the Info file for handling images.
1230 (defun Info-split-parameter-string (parameter-string)
1231 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1232 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1233 whitespace or double quotes, it must be quoted in double quotes and
1234 any double quotes or backslashes must be escaped (\\\",\\\\)."
1237 (while (string-match
1238 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1239 parameter-string start
)
1240 (setq start
(match-end 0))
1241 (push (cons (match-string 1 parameter-string
)
1242 (or (match-string 2 parameter-string
)
1243 (Info-unescape-quotes
1244 (match-string 3 parameter-string
))))
1248 (defun Info-display-images-node ()
1249 "Display images in current node."
1251 (let ((inhibit-read-only t
)
1252 (case-fold-search t
))
1253 (goto-char (point-min))
1254 (while (re-search-forward
1255 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1257 (let* ((start (match-beginning 1))
1258 (parameter-alist (Info-split-parameter-string (match-string 2)))
1259 (src (cdr (assoc-string "src" parameter-alist
)))
1260 (image-file (if src
(if (file-name-absolute-p src
) src
1261 (concat default-directory src
))
1263 (image (if (file-exists-p image-file
)
1264 (create-image image-file
)
1266 (if (not (get-text-property start
'display
))
1267 (add-text-properties
1268 start
(point) `(display ,image rear-nonsticky
(display)))))))
1269 (set-buffer-modified-p nil
)))
1271 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1272 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1273 ;; including one optional trailing newline.
1274 (defun Info-hide-cookies-node ()
1275 "Hide unrecognized cookies in current node."
1277 (let ((inhibit-read-only t
)
1278 (case-fold-search t
))
1279 (goto-char (point-min))
1280 (while (re-search-forward
1281 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1283 (let* ((start (match-beginning 1)))
1284 (if (not (get-text-property start
'invisible
))
1285 (put-text-property start
(point) 'invisible t
)))))
1286 (set-buffer-modified-p nil
)))
1288 (defun Info-select-node ()
1289 "Select the info node that point is in."
1290 ;; Bind this in case the user sets it to nil.
1291 (let ((case-fold-search t
))
1293 ;; Find beginning of node.
1294 (if (search-backward "\n\^_" nil
'move
)
1296 (if (looking-at "\^_")
1298 (signal 'search-failed
(list "\n\^_"))))
1299 ;; Get nodename spelled as it is in the node.
1300 (re-search-forward "Node:[ \t]*")
1301 (setq Info-current-node
1302 (buffer-substring-no-properties (point)
1304 (skip-chars-forward "^,\t\n")
1306 (Info-set-mode-line)
1307 ;; Find the end of it, and narrow.
1309 (let (active-expression)
1310 ;; Narrow to the node contents
1311 (narrow-to-region (point)
1312 (if (re-search-forward "\n[\^_\f]" nil t
)
1315 (if (looking-at "[\n\^_\f]*execute: ")
1317 (goto-char (match-end 0))
1318 (setq active-expression
1319 (read (current-buffer))))))
1321 (if Info-enable-active-nodes
(eval active-expression
))
1322 ;; Add a new unique history item to full history list
1323 (let ((new-history (list Info-current-file Info-current-node
)))
1324 (setq Info-history-list
1325 (cons new-history
(delete new-history Info-history-list
)))
1326 (setq Info-history-forward nil
))
1327 (if (not (eq Info-fontify-maximum-menu-size nil
))
1328 (Info-fontify-node))
1329 (Info-display-images-node)
1330 (Info-hide-cookies-node)
1331 (run-hooks 'Info-selection-hook
)))))
1333 (defun Info-set-mode-line ()
1334 (setq mode-line-buffer-identification
1335 (nconc (propertized-buffer-identification "%b")
1338 (file-name-nondirectory
1339 (if (stringp Info-current-file
)
1341 (or buffer-file-name
"")))
1343 (or Info-current-node
""))))))
1345 ;; Go to an info node specified with a filename-and-nodename string
1346 ;; of the sort that is found in pointers in nodes.
1348 ;; Don't autoload this function: the correct entry point for other packages
1349 ;; to use is `info'. --Stef
1351 (defun Info-goto-node (nodename &optional fork
)
1352 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1353 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1354 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1356 Completion is available, but only for node names in the current Info file.
1357 If FORK is non-nil (interactively with a prefix arg), show the node in
1359 If FORK is a string, it is the name to use for the new buffer."
1360 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1364 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1366 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1368 (setq filename
(if (= (match-beginning 1) (match-end 1))
1370 (match-string 2 nodename
))
1371 nodename
(match-string 3 nodename
))
1372 (let ((trim (string-match "\\s +\\'" filename
)))
1373 (if trim
(setq filename
(substring filename
0 trim
))))
1374 (let ((trim (string-match "\\s +\\'" nodename
)))
1375 (if trim
(setq nodename
(substring nodename
0 trim
))))
1376 (if transient-mark-mode
(deactivate-mark))
1377 (Info-find-node (if (equal filename
"") nil filename
)
1378 (if (equal nodename
"") "Top" nodename
))))
1380 (defvar Info-read-node-completion-table
)
1382 (defun Info-read-node-name-2 (string path-and-suffixes action
)
1383 "Virtual completion table for file names input in Info node names.
1384 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1386 (suffixes (remove "" (cdr path-and-suffixes
)))
1387 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1388 (string-dir (file-name-directory string
))
1390 (if (file-name-absolute-p string
)
1391 (list (file-name-directory string
))
1392 (car path-and-suffixes
))))
1395 (setq dir default-directory
))
1396 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1397 (when (file-directory-p dir
)
1398 (dolist (file (file-name-all-completions
1399 (file-name-nondirectory string
) dir
))
1400 ;; If the file name has no suffix or a standard suffix,
1402 (and (or (null (file-name-extension file
))
1403 (string-match suffix file
))
1404 ;; But exclude subfiles of split info files.
1405 (not (string-match "-[0-9]+\\'" file
))
1406 ;; And exclude backup files.
1407 (not (string-match "~\\'" file
))
1408 (push (if string-dir
(concat string-dir file
) file
) names
))
1409 ;; If the file name ends in a standard suffix,
1410 ;; add the unsuffixed name as a completion option.
1411 (when (string-match suffix file
)
1412 (setq file
(substring file
0 (match-beginning 0)))
1413 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1415 ((eq action t
) (all-completions string names
))
1416 ((null action
) (try-completion string names
))
1417 (t (test-completion string names
)))))
1419 ;; This function is used as the "completion table" while reading a node name.
1420 ;; It does completion using the alist in Info-read-node-completion-table
1421 ;; unless STRING starts with an open-paren.
1422 (defun Info-read-node-name-1 (string predicate code
)
1424 ;; First complete embedded file names.
1425 ((string-match "\\`([^)]*\\'" string
)
1426 (let ((file (substring string
1)))
1429 (let ((comp (try-completion file
'Info-read-node-name-2
1430 (cons Info-directory-list
1431 (mapcar 'car Info-suffix-list
)))))
1433 ((eq comp t
) (concat string
")"))
1434 (comp (concat "(" comp
)))))
1436 (all-completions file
'Info-read-node-name-2
1437 (cons Info-directory-list
1438 (mapcar 'car Info-suffix-list
))))
1440 ;; If a file name was given, then any node is fair game.
1441 ((string-match "\\`(" string
)
1443 ((eq code nil
) string
)
1446 ;; Otherwise use Info-read-node-completion-table.
1448 (try-completion string Info-read-node-completion-table predicate
))
1450 (all-completions string Info-read-node-completion-table predicate
))
1452 (test-completion string Info-read-node-completion-table predicate
))))
1454 ;; Arrange to highlight the proper letters in the completion list buffer.
1455 (put 'Info-read-node-name-1
'completion-base-size-function
1458 (defun Info-read-node-name (prompt &optional default
)
1459 (let* ((completion-ignore-case t
)
1460 (Info-read-node-completion-table (Info-build-node-completions))
1461 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1462 (if (equal nodename
"")
1464 (Info-read-node-name prompt
))
1467 (defun Info-build-node-completions ()
1468 (or Info-current-file-completions
1470 ;; Bind this in case the user sets it to nil.
1471 (case-fold-search t
)
1472 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1475 (if (marker-buffer Info-tag-table-marker
)
1476 (let ((marker Info-tag-table-marker
))
1477 (set-buffer (marker-buffer marker
))
1480 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1482 (cons (list (match-string-no-properties 2))
1485 (goto-char (point-min))
1486 ;; If the buffer begins with a node header, process that first.
1487 (if (Info-node-at-bob-matching node-regexp
)
1488 (setq compl
(list (match-string-no-properties 1))))
1489 ;; Now for the rest of the nodes.
1490 (while (search-forward "\n\^_" nil t
)
1492 (let ((beg (point)))
1494 (if (re-search-backward node-regexp beg t
)
1496 (cons (list (match-string-no-properties 1))
1498 (setq compl
(cons '("*") compl
))
1499 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1501 (defun Info-restore-point (hl)
1502 "If this node has been visited, restore the point value when we left."
1504 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1505 ;; Use string-equal, not equal, to ignore text props.
1506 (string-equal (nth 1 (car hl
)) Info-current-node
))
1508 (goto-char (nth 2 (car hl
)))
1509 (setq hl nil
)) ;terminate the while at next iter
1510 (setq hl
(cdr hl
)))))
1512 (defvar Info-search-history nil
1513 "The history list for `Info-search'.")
1515 (defvar Info-search-case-fold nil
1516 "The value of `case-fold-search' from previous `Info-search' command.")
1518 (defun Info-search (regexp &optional bound noerror count direction
)
1519 "Search for REGEXP, starting from point, and select node it's found in.
1520 If DIRECTION is `backward', search in the reverse direction."
1521 (interactive (list (read-string
1522 (if Info-search-history
1523 (format "Regexp search%s (default `%s'): "
1524 (if case-fold-search
"" " case-sensitively")
1525 (car Info-search-history
))
1526 (format "Regexp search%s: "
1527 (if case-fold-search
"" " case-sensitively")))
1528 nil
'Info-search-history
)))
1529 (when transient-mark-mode
1531 (when (equal regexp
"")
1532 (setq regexp
(car Info-search-history
)))
1534 (let (found beg-found give-up
1535 (backward (eq direction
'backward
))
1536 (onode Info-current-node
)
1537 (ofile Info-current-file
)
1539 (opoint-min (point-min))
1540 (opoint-max (point-max))
1541 (ostart (window-start))
1542 (osubfile Info-current-subfile
))
1543 (setq Info-search-case-fold case-fold-search
)
1548 ;; Hide Info file header for backward search
1549 (narrow-to-region (save-excursion
1550 (goto-char (point-min))
1551 (search-forward "\n\^_")
1554 (while (and (not give-up
)
1558 (isearch-range-invisible found beg-found
)
1559 (isearch-range-invisible beg-found found
))
1560 ;; Skip node header line
1561 (and (save-excursion (forward-line -
1)
1563 (forward-line (if backward -
1 1)))
1564 ;; Skip Tag Table node
1566 (and (search-backward "\^_" nil t
)
1567 (looking-at "\^_\nTag Table"))))))
1568 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1570 (re-search-backward regexp bound t
)
1571 (re-search-forward regexp bound t
))
1572 (setq found
(point) beg-found
(if backward
(match-end 0)
1573 (match-beginning 0)))
1574 (setq give-up t
))))))
1576 (when (and isearch-mode Info-isearch-search
1577 (not Info-isearch-initial-node
)
1579 (or give-up
(and found
(not (and (> found opoint-min
)
1580 (< found opoint-max
))))))
1581 (signal 'search-failed
(list regexp
"initial node")))
1583 ;; If no subfiles, give error now.
1585 (if (null Info-current-subfile
)
1586 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1588 (re-search-backward regexp
)
1589 (re-search-forward regexp
)))
1592 (if (and bound
(not found
))
1593 (signal 'search-failed
(list regexp
)))
1595 (unless (or found bound
)
1597 ;; Try other subfiles.
1600 (set-buffer (marker-buffer Info-tag-table-marker
))
1601 (goto-char (point-min))
1602 (search-forward "\n\^_\nIndirect:")
1604 (narrow-to-region (point)
1605 (progn (search-forward "\n\^_")
1607 (goto-char (point-min))
1608 ;; Find the subfile we just searched.
1609 (search-forward (concat "\n" osubfile
": "))
1611 (forward-line (if backward
0 1))
1612 (if backward
(forward-char -
1))
1613 ;; Make a list of all following subfiles.
1614 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1615 (while (not (if backward
(bobp) (eobp)))
1617 (re-search-backward "\\(^.*\\): [0-9]+$")
1618 (re-search-forward "\\(^.*\\): [0-9]+$"))
1619 (goto-char (+ (match-end 1) 2))
1620 (setq list
(cons (cons (+ (point-min)
1621 (read (current-buffer)))
1622 (match-string-no-properties 1))
1624 (goto-char (if backward
1625 (1- (match-beginning 0))
1626 (1+ (match-end 0)))))
1627 ;; Put in forward order
1628 (setq list
(nreverse list
))))
1630 (message "Searching subfile %s..." (cdr (car list
)))
1631 (Info-read-subfile (car (car list
)))
1633 ;; Hide Info file header for backward search
1634 (narrow-to-region (save-excursion
1635 (goto-char (point-min))
1636 (search-forward "\n\^_")
1639 (goto-char (point-max)))
1640 (setq list
(cdr list
))
1641 (setq give-up nil found nil
)
1642 (while (and (not give-up
)
1646 (isearch-range-invisible found beg-found
)
1647 (isearch-range-invisible beg-found found
))
1648 ;; Skip node header line
1649 (and (save-excursion (forward-line -
1)
1651 (forward-line (if backward -
1 1)))
1652 ;; Skip Tag Table node
1654 (and (search-backward "\^_" nil t
)
1655 (looking-at "\^_\nTag Table"))))))
1656 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1658 (re-search-backward regexp nil t
)
1659 (re-search-forward regexp nil t
))
1660 (setq found
(point) beg-found
(if backward
(match-end 0)
1661 (match-beginning 0)))
1669 (signal 'search-failed
(list regexp
))))
1671 (progn (Info-read-subfile osubfile
)
1674 (set-window-start (selected-window) ostart
)))))
1676 (if (and (string= osubfile Info-current-subfile
)
1677 (> found opoint-min
)
1678 (< found opoint-max
))
1679 ;; Search landed in the same node
1683 (save-match-data (Info-select-node)))
1685 ;; Use string-equal, not equal, to ignore text props.
1686 (or (and (string-equal onode Info-current-node
)
1687 (equal ofile Info-current-file
))
1688 (and isearch-mode isearch-wrapped
1689 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1690 (setq Info-history
(cons (list ofile onode opoint
)
1693 (defun Info-search-case-sensitively ()
1694 "Search for a regexp case-sensitively."
1696 (let ((case-fold-search nil
))
1697 (call-interactively 'Info-search
)))
1699 (defun Info-search-next ()
1700 "Search for next regexp from a previous `Info-search' command."
1702 (let ((case-fold-search Info-search-case-fold
))
1703 (if Info-search-history
1704 (Info-search (car Info-search-history
))
1705 (call-interactively 'Info-search
))))
1707 (defun Info-search-backward (regexp &optional bound noerror count
)
1708 "Search for REGEXP in the reverse direction."
1709 (interactive (list (read-string
1710 (if Info-search-history
1711 (format "Regexp search%s backward (default `%s'): "
1712 (if case-fold-search
"" " case-sensitively")
1713 (car Info-search-history
))
1714 (format "Regexp search%s backward: "
1715 (if case-fold-search
"" " case-sensitively")))
1716 nil
'Info-search-history
)))
1717 (Info-search regexp bound noerror count
'backward
))
1719 (defun Info-isearch-search ()
1720 (if Info-isearch-search
1721 (lambda (string &optional bound noerror count
)
1723 (Info-search (concat "\\b" (replace-regexp-in-string
1725 (replace-regexp-in-string
1726 "^\\W+\\|\\W+$" "" string
)) "\\b")
1728 (unless isearch-forward
'backward
))
1729 (Info-search (if isearch-regexp string
(regexp-quote string
))
1731 (unless isearch-forward
'backward
))
1733 (let ((isearch-search-fun-function nil
))
1734 (isearch-search-fun))))
1736 (defun Info-isearch-wrap ()
1737 (if Info-isearch-search
1738 (if Info-isearch-initial-node
1740 (if isearch-forward
(Info-top-node) (Info-final-node))
1741 (goto-char (if isearch-forward
(point-min) (point-max))))
1742 (setq Info-isearch-initial-node Info-current-node
)
1743 (setq isearch-wrapped nil
))
1744 (goto-char (if isearch-forward
(point-min) (point-max)))))
1746 (defun Info-isearch-push-state ()
1748 (Info-isearch-pop-state cmd
,Info-current-file
,Info-current-node
)))
1750 (defun Info-isearch-pop-state (cmd file node
)
1751 (or (and (string= Info-current-file file
)
1752 (string= Info-current-node node
))
1753 (progn (Info-find-node file node
) (sit-for 0))))
1755 (defun Info-isearch-start ()
1756 (setq Info-isearch-initial-node nil
))
1758 (defun Info-extract-pointer (name &optional errorname
)
1759 "Extract the value of the node-pointer named NAME.
1760 If there is none, use ERRORNAME in the error message;
1761 if ERRORNAME is nil, just return nil."
1762 ;; Bind this in case the user sets it to nil.
1763 (let ((case-fold-search t
))
1765 (goto-char (point-min))
1766 (let ((bound (point)))
1768 (cond ((re-search-backward
1769 (concat name
":" (Info-following-node-name-re)) bound t
)
1771 ((not (eq errorname t
))
1772 (error "Node has no %s"
1773 (capitalize (or errorname name
)))))))))
1775 (defun Info-following-node-name-re (&optional allowedchars
)
1776 "Return a regexp matching a node name.
1777 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1778 saying which chars may appear in the node name.
1779 Submatch 1 is the complete node name.
1780 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1781 Submatch 3 is the local part of the node name.
1782 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1783 (concat "[ \t]*" ;Skip leading space.
1784 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1785 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1786 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1787 "\\|\\)\\)")) ;Allow empty node names.
1789 ;;; For compatibility; other files have used this name.
1790 (defun Info-following-node-name ()
1791 (and (looking-at (Info-following-node-name-re))
1795 "Go to the next node of this node."
1797 (Info-goto-node (Info-extract-pointer "next")))
1800 "Go to the previous node of this node."
1802 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1804 (defun Info-up (&optional same-file
)
1805 "Go to the superior node of this node.
1806 If SAME-FILE is non-nil, do not move to a different Info file."
1808 (let ((old-node Info-current-node
)
1809 (old-file Info-current-file
)
1810 (node (Info-extract-pointer "up")) p
)
1811 (and (or same-file
(not (stringp Info-current-file
)))
1812 (string-match "^(" node
)
1813 (error "Up node is in another Info file"))
1814 (Info-goto-node node
)
1816 (goto-char (point-min))
1817 (if (and (search-forward "\n* Menu:" nil t
)
1819 (if (string-equal old-node
"Top")
1820 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
1821 (concat "\n\\* +\\(" (regexp-quote old-node
)
1822 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
1826 (Info-restore-point Info-history
))))
1828 (defun Info-history-back ()
1829 "Go back in the history to the last node visited."
1832 (error "This is the first Info node you looked at"))
1833 (let ((history-forward
1834 (cons (list Info-current-file Info-current-node
(point))
1835 Info-history-forward
))
1836 filename nodename opoint
)
1837 (setq filename
(car (car Info-history
)))
1838 (setq nodename
(car (cdr (car Info-history
))))
1839 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1840 (setq Info-history
(cdr Info-history
))
1841 (Info-find-node filename nodename
)
1842 (setq Info-history
(cdr Info-history
))
1843 (setq Info-history-forward history-forward
)
1844 (goto-char opoint
)))
1846 (defalias 'Info-last
'Info-history-back
)
1848 (defun Info-history-forward ()
1849 "Go forward in the history of visited nodes."
1851 (or Info-history-forward
1852 (error "This is the last Info node you looked at"))
1853 (let ((history-forward (cdr Info-history-forward
))
1854 filename nodename opoint
)
1855 (setq filename
(car (car Info-history-forward
)))
1856 (setq nodename
(car (cdr (car Info-history-forward
))))
1857 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
1858 (Info-find-node filename nodename
)
1859 (setq Info-history-forward history-forward
)
1860 (goto-char opoint
)))
1863 (defun Info-directory ()
1864 "Go to the Info directory node."
1866 (Info-find-node "dir" "top"))
1868 (defun Info-history ()
1869 "Go to a node with a menu of visited nodes."
1871 (let ((curr-file Info-current-file
)
1872 (curr-node Info-current-node
)
1874 (with-current-buffer (get-buffer-create " *info-history*")
1875 (let ((inhibit-read-only t
))
1877 (goto-char (point-min))
1878 (insert "\n\^_\nFile: history, Node: Top, Up: (dir)\n\n")
1879 (insert "Recently Visited Nodes\n**********************\n\n")
1880 (insert "* Menu:\n\n")
1881 (let ((hl (delete '("history" "Top") Info-history-list
)))
1883 (let ((file (nth 0 (car hl
)))
1884 (node (nth 1 (car hl
))))
1885 (if (and (string-equal file curr-file
)
1886 (string-equal node curr-node
))
1888 (insert "* " node
": (" (file-name-nondirectory file
)
1890 (setq hl
(cdr hl
))))))
1891 (Info-find-node "history" "Top")
1892 (goto-char (or p
(point-min)))))
1895 "Go to a node with table of contents of the current Info file.
1896 Table of contents is created from the tree structure of menus."
1898 (let ((curr-file (substring-no-properties Info-current-file
))
1899 (curr-node (substring-no-properties Info-current-node
))
1901 (with-current-buffer (get-buffer-create " *info-toc*")
1902 (let ((inhibit-read-only t
)
1903 (node-list (Info-build-toc curr-file
)))
1905 (goto-char (point-min))
1906 (insert "\n\^_\nFile: toc, Node: Top, Up: (dir)\n\n")
1907 (insert "Table of Contents\n*****************\n\n")
1908 (insert "*Note Top: (" curr-file
")Top.\n")
1910 (nth 2 (assoc "Top" node-list
)) ; get Top nodes
1911 node-list
0 curr-file
))
1913 (let ((Info-hide-note-references 'hide
)
1914 (Info-fontify-visited-nodes nil
))
1916 (setq Info-current-file
"toc" Info-current-node
"Top")
1917 (goto-char (point-min))
1918 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
1923 (goto-char (point-min))
1924 (if (setq p
(search-forward (concat "*Note " curr-node
":") nil t
))
1925 (setq p
(- p
(length curr-node
) 2))))
1926 (Info-find-node "toc" "Top")
1927 (goto-char (or p
(point-min)))))
1929 (defun Info-insert-toc (nodes node-list level curr-file
)
1930 "Insert table of contents with references to nodes."
1931 (let ((section "Top"))
1933 (let ((node (assoc (car nodes
) node-list
)))
1934 (unless (member (nth 1 node
) (list nil section
))
1935 (insert (setq section
(nth 1 node
)) "\n"))
1936 (insert (make-string level ?
\t))
1937 (insert "*Note " (car nodes
) ": (" curr-file
")" (car nodes
) ".\n")
1938 (Info-insert-toc (nth 2 node
) node-list
(1+ level
) curr-file
)
1939 (setq nodes
(cdr nodes
))))))
1941 (defun Info-build-toc (file)
1942 "Build table of contents from menus of Info FILE and its subfiles."
1944 (let* ((file (and (stringp file
) (Info-find-file file
)))
1945 (default-directory (or (and (stringp file
)
1946 (file-name-directory file
))
1948 (main-file (and (stringp file
) file
))
1949 (sections '(("Top" "Top")))
1951 (while (or main-file subfiles
)
1952 (or main-file
(message "Searching subfile %s..." (car subfiles
)))
1954 (info-insert-file-contents (or main-file
(car subfiles
)))
1955 (goto-char (point-min))
1956 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
1957 (search-forward "Node: " nil
'move
))
1958 (let ((nodename (substring-no-properties (Info-following-node-name)))
1959 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
1963 (when (and (not (Info-index-node nodename file
))
1964 (re-search-forward "^\\* Menu:" bound t
))
1967 (setq bound
(or (and (equal nodename
"Top")
1970 "^[ \t-]*The Detailed Node Listing" nil t
)))
1972 (while (< (point) bound
)
1975 ((looking-at "^\\* +[^:]+:")
1978 (let ((menu-node-name (substring-no-properties
1979 (Info-extract-menu-node-name))))
1980 (setq menu-items
(cons menu-node-name menu-items
))
1981 (if (equal nodename
"Top")
1983 (cons (list menu-node-name section
) sections
)))))
1984 ;; Other non-empty strings in the Top node are section names
1985 ((and (equal nodename
"Top")
1986 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
1987 (setq section
(match-string-no-properties 1))))
1989 (beginning-of-line)))
1990 (setq nodes
(cons (list nodename
1991 (cadr (assoc nodename sections
))
1992 (nreverse menu-items
))
1997 (goto-char (point-min))
1998 (if (search-forward "\n\^_\nIndirect:" nil t
)
1999 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2000 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2001 (setq subfiles
(cons (match-string-no-properties 1)
2003 (setq subfiles
(nreverse subfiles
)
2005 (setq subfiles
(cdr subfiles
))))
2009 (defun Info-follow-reference (footnotename &optional fork
)
2010 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2011 FOOTNOTENAME may be an abbreviation of the reference name.
2012 If FORK is non-nil (interactively with a prefix arg), show the node in
2013 a new info buffer. If FORK is a string, it is the name to use for the
2016 (let ((completion-ignore-case t
)
2017 (case-fold-search t
)
2018 completions default alt-default
(start-point (point)) str i bol eol
)
2020 ;; Store end and beginning of line.
2026 (goto-char (point-min))
2027 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2028 (setq str
(match-string-no-properties 1))
2029 ;; See if this one should be the default.
2031 (<= (match-beginning 0) start-point
)
2032 (<= start-point
(point))
2034 ;; See if this one should be the alternate default.
2035 (and (null alt-default
)
2036 (and (<= bol
(match-beginning 0))
2038 (setq alt-default t
))
2040 (while (setq i
(string-match "[ \n\t]+" str i
))
2041 (setq str
(concat (substring str
0 i
) " "
2042 (substring str
(match-end 0))))
2044 ;; Record as a completion and perhaps as default.
2045 (if (eq default t
) (setq default str
))
2046 (if (eq alt-default t
) (setq alt-default str
))
2047 ;; Don't add this string if it's a duplicate.
2048 (or (assoc-string str completions t
)
2049 (push str completions
))))
2050 ;; If no good default was found, try an alternate.
2052 (setq default alt-default
))
2053 ;; If only one cross-reference found, then make it default.
2054 (if (eq (length completions
) 1)
2055 (setq default
(car completions
)))
2057 (let ((input (completing-read (if default
2059 "Follow reference named: (default "
2061 "Follow reference named: ")
2062 completions nil t
)))
2063 (list (if (equal input
"")
2064 default input
) current-prefix-arg
))
2065 (error "No cross-references in this node"))))
2067 (unless footnotename
2068 (error "No reference was specified"))
2070 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2071 (case-fold-search t
))
2072 (while (setq i
(string-match " " str i
))
2073 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2076 ;; Move point to the beginning of reference if point is on reference
2077 (or (looking-at "\\*note[ \n\t]+")
2078 (and (looking-back "\\*note[ \n\t]+")
2079 (goto-char (match-beginning 0)))
2080 (if (and (save-excursion
2081 (goto-char (+ (point) 5)) ; skip a possible *note
2082 (re-search-backward "\\*note[ \n\t]+" nil t
)
2084 (<= (point) (match-end 0)))
2085 (goto-char (match-beginning 0))))
2086 ;; Go to the reference closest to point
2087 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2088 (+ (match-beginning 0) 5))))
2089 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2090 (+ (match-beginning 0) 5)))))
2091 (goto-char (cond ((and next-ref prev-ref
)
2092 (if (< (abs (- next-ref
(point)))
2093 (abs (- prev-ref
(point))))
2095 ((or next-ref prev-ref
))
2096 ((error "No cross-reference named %s" footnotename
))))
2097 (setq target
(Info-extract-menu-node-name t
))))
2098 (while (setq i
(string-match "[ \t\n]+" target i
))
2099 (setq target
(concat (substring target
0 i
) " "
2100 (substring target
(match-end 0))))
2102 (Info-goto-node target fork
)))
2104 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2105 ;; We allow newline because this is also used in Info-follow-reference,
2106 ;; where the xref name might be wrapped over two lines.
2107 "Regexp that matches a menu entry name upto but not including the colon.
2108 Because of ambiguities, this should be concatenated with something like
2109 `:' and `Info-following-node-name-re'.")
2111 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2112 (skip-chars-forward " \t\n")
2113 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2114 (Info-following-node-name-re
2116 (index-node "^,\t\n")
2117 (multi-line "^.,\t")
2121 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2124 (setq Info-point-loc
2125 (if (match-beginning 5)
2126 (string-to-number (match-string 5))
2127 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
2128 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2129 ;;; (setq Info-point-loc
2130 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2132 (replace-regexp-in-string
2134 (or (match-string 2)
2135 ;; If the node name is the menu entry name (using `entry::').
2136 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
2138 ;; No one calls this.
2139 ;;(defun Info-menu-item-sequence (list)
2141 ;; (Info-menu (car list))
2142 ;; (setq list (cdr list))))
2144 (defvar Info-complete-menu-buffer
)
2145 (defvar Info-complete-next-re nil
)
2146 (defvar Info-complete-nodes nil
)
2147 (defvar Info-complete-cache nil
)
2149 (defconst Info-node-spec-re
2150 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2151 "Regexp to match the text after a : until the terminating `.'.")
2153 (defun Info-complete-menu-item (string predicate action
)
2154 ;; This uses two dynamically bound variables:
2155 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2156 ;; is the menu of items we're trying to complete.
2157 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2158 ;; also look for menu items in subsequent nodes as long as those
2159 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2161 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2162 ;; also look for menu items in these nodes. This feature is currently
2163 ;; only used for completion in Info-index.
2165 ;; Note that `Info-complete-menu-buffer' could be current already,
2166 ;; so we want to save point.
2168 (set-buffer Info-complete-menu-buffer
)
2169 (let ((completion-ignore-case t
)
2170 (case-fold-search t
)
2171 (orignode Info-current-node
)
2173 (goto-char (point-min))
2174 (search-forward "\n* Menu:")
2175 (if (not (memq action
'(nil t
)))
2177 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
2178 (let ((pattern (concat "\n\\* +\\("
2179 (regexp-quote string
)
2180 Info-menu-entry-name-re
"\\):" Info-node-spec-re
))
2183 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2184 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2185 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2186 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2187 (let ((prev (nth 3 Info-complete-cache
)))
2188 (eq t
(compare-strings string
0 (length prev
)
2190 ;; We can reuse the previous list.
2191 (setq completions
(nth 4 Info-complete-cache
))
2192 ;; The cache can't be used.
2195 (while (re-search-forward pattern nil t
)
2196 (push (match-string-no-properties 1)
2198 ;; Check subsequent nodes if applicable.
2199 (or (and Info-complete-next-re
2200 (setq nextnode
(Info-extract-pointer "next" t
))
2201 (string-match Info-complete-next-re nextnode
))
2202 (and Info-complete-nodes
2203 (setq Info-complete-nodes
(cdr Info-complete-nodes
)
2204 nextnode
(car Info-complete-nodes
)))))
2205 (Info-goto-node nextnode
))
2206 ;; Go back to the start node (for the next completion).
2207 (unless (equal Info-current-node orignode
)
2208 (Info-goto-node orignode
))
2209 ;; Update the cache.
2210 (set (make-local-variable 'Info-complete-cache
)
2211 (list Info-current-file Info-current-node
2212 Info-complete-next-re string completions
2213 Info-complete-nodes
)))
2215 (all-completions string completions predicate
)
2216 (try-completion string completions predicate
)))))))
2219 (defun Info-menu (menu-item &optional fork
)
2220 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2221 The menu item should one of those listed in the current node's menu.
2222 Completion is allowed, and the default menu item is the one point is on.
2223 If FORK is non-nil (interactively with a prefix arg), show the node in
2224 a new info buffer. If FORK is a string, it is the name to use for the
2227 (let ((completions '())
2228 ;; If point is within a menu item, use that item as the default
2233 (case-fold-search t
))
2235 (goto-char (point-min))
2236 (if (not (search-forward "\n* menu:" nil t
))
2237 (error "No menu in this node"))
2243 (if (re-search-backward (concat "\n\\* +\\("
2244 Info-menu-entry-name-re
2246 (setq default
(match-string-no-properties 1))))))
2249 (setq item
(let ((completion-ignore-case t
)
2250 (Info-complete-menu-buffer (current-buffer)))
2251 (completing-read (if default
2252 (format "Menu item (default %s): "
2255 'Info-complete-menu-item nil t
)))
2256 ;; we rely on the fact that completing-read accepts an input
2257 ;; of "" even when the require-match argument is true and ""
2258 ;; is not a valid possibility
2259 (if (string= item
"")
2264 (list item current-prefix-arg
))))
2265 ;; there is a problem here in that if several menu items have the same
2266 ;; name you can only go to the node of the first with this command.
2267 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2269 (defun Info-extract-menu-item (menu-item)
2270 (setq menu-item
(regexp-quote menu-item
))
2271 (let ((case-fold-search t
))
2273 (let ((case-fold-search t
))
2274 (goto-char (point-min))
2275 (or (search-forward "\n* menu:" nil t
)
2276 (error "No menu in this node"))
2277 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2278 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2279 (error "No such item in menu"))
2282 (Info-extract-menu-node-name nil
(Info-index-node))))))
2284 ;; If COUNT is nil, use the last item in the menu.
2285 (defun Info-extract-menu-counting (count)
2286 (let ((case-fold-search t
))
2288 (let ((case-fold-search t
))
2289 (goto-char (point-min))
2290 (or (search-forward "\n* menu:" nil t
)
2291 (error "No menu in this node"))
2293 (or (search-forward "\n* " nil t count
)
2294 (error "Too few items in menu"))
2295 (while (search-forward "\n* " nil t
)
2297 (Info-extract-menu-node-name nil
(Info-index-node))))))
2299 (defun Info-nth-menu-item ()
2300 "Go to the node of the Nth menu item.
2301 N is the digit argument used to invoke this command."
2304 (Info-extract-menu-counting
2305 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2307 (defun Info-top-node ()
2308 "Go to the Top node of this file."
2310 (Info-goto-node "Top"))
2312 (defun Info-final-node ()
2313 "Go to the final node in this file."
2315 (Info-goto-node "Top")
2316 (let ((Info-history nil
)
2317 (case-fold-search t
))
2318 ;; Go to the last node in the menu of Top.
2319 (Info-goto-node (Info-extract-menu-counting nil
))
2320 ;; If the last node in the menu is not last in pointer structure,
2321 ;; move forward until we can't go any farther.
2322 (while (Info-forward-node t t
) nil
)
2323 ;; Then keep moving down to last subnode, unless we reach an index.
2324 (while (and (not (Info-index-node))
2325 (save-excursion (search-forward "\n* Menu:" nil t
)))
2326 (Info-goto-node (Info-extract-menu-counting nil
)))))
2328 (defun Info-forward-node (&optional not-down no-error
)
2329 "Go forward one node, considering all nodes as forming one sequence."
2331 (goto-char (point-min))
2333 (let ((case-fold-search t
))
2334 ;; three possibilities, in order of priority:
2335 ;; 1. next node is in a menu in this node (but not in an index)
2336 ;; 2. next node is next at same level
2337 ;; 3. next node is up and next
2338 (cond ((and (not not-down
)
2339 (save-excursion (search-forward "\n* menu:" nil t
))
2340 (not (Info-index-node)))
2341 (Info-goto-node (Info-extract-menu-counting 1))
2343 ((save-excursion (search-backward "next:" nil t
))
2346 ((and (save-excursion (search-backward "up:" nil t
))
2347 ;; Use string-equal, not equal, to ignore text props.
2348 (not (string-equal (downcase (Info-extract-pointer "up"))
2350 (let ((old-node Info-current-node
))
2352 (let (Info-history success
)
2354 (setq success
(Info-forward-node t no-error
))
2355 (or success
(Info-goto-node old-node
))))))
2357 (t (error "No pointer forward from this node")))))
2359 (defun Info-backward-node ()
2360 "Go backward one node, considering all nodes as forming one sequence."
2362 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2363 (upnode (Info-extract-pointer "up" t
))
2364 (case-fold-search t
))
2365 (cond ((and upnode
(string-match "(" upnode
))
2366 (error "First node in file"))
2367 ((and upnode
(or (null prevnode
)
2368 ;; Use string-equal, not equal,
2369 ;; to ignore text properties.
2370 (string-equal (downcase prevnode
)
2371 (downcase upnode
))))
2374 ;; If we move back at the same level,
2375 ;; go down to find the last subnode*.
2378 (while (and (not (Info-index-node))
2379 (save-excursion (search-forward "\n* Menu:" nil t
)))
2380 (Info-goto-node (Info-extract-menu-counting nil
)))))
2382 (error "No pointer backward from this node")))))
2385 "Exit Info by selecting some other buffer."
2388 (save-buffers-kill-emacs)
2391 (defun Info-next-menu-item ()
2392 "Go to the node of the next menu item."
2394 ;; Bind this in case the user sets it to nil.
2395 (let* ((case-fold-search t
)
2399 (search-forward "\n* menu:" nil t
)
2400 (and (search-forward "\n* " nil t
)
2401 (Info-extract-menu-node-name)))))
2402 (if node
(Info-goto-node node
)
2403 (error "No more items in menu"))))
2405 (defun Info-last-menu-item ()
2406 "Go to the node of the previous menu item."
2410 ;; Bind this in case the user sets it to nil.
2411 (let* ((case-fold-search t
)
2412 (beg (save-excursion
2413 (and (search-backward "\n* menu:" nil t
)
2415 (or (and beg
(search-backward "\n* " beg t
))
2416 (error "No previous items in menu")))
2417 (Info-goto-node (save-excursion
2418 (goto-char (match-end 0))
2419 (Info-extract-menu-node-name)))))
2421 (defmacro Info-no-error
(&rest body
)
2422 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2424 (defun Info-next-preorder ()
2425 "Go to the next subnode or the next node, or go up a level."
2427 (cond ((Info-no-error (Info-next-menu-item)))
2428 ((Info-no-error (Info-next)))
2429 ((Info-no-error (Info-up t
))
2430 ;; Since we have already gone thru all the items in this menu,
2431 ;; go up to the end of this node.
2432 (goto-char (point-max))
2433 ;; Since logically we are done with the node with that menu,
2435 (Info-next-preorder))
2437 (error "No more nodes"))))
2439 (defun Info-last-preorder ()
2440 "Go to the last node, popping up a level if there is none."
2442 (cond ((Info-no-error
2443 (Info-last-menu-item)
2444 ;; If we go down a menu item, go to the end of the node
2445 ;; so we can scroll back through it.
2446 (goto-char (point-max)))
2447 ;; Keep going down, as long as there are nested menu nodes.
2448 (while (Info-no-error
2449 (Info-last-menu-item)
2450 ;; If we go down a menu item, go to the end of the node
2451 ;; so we can scroll back through it.
2452 (goto-char (point-max))))
2454 ((and (Info-no-error (Info-extract-pointer "prev"))
2455 (not (equal (Info-extract-pointer "up")
2456 (Info-extract-pointer "prev"))))
2457 (Info-no-error (Info-prev))
2458 (goto-char (point-max))
2459 (while (Info-no-error
2460 (Info-last-menu-item)
2461 ;; If we go down a menu item, go to the end of the node
2462 ;; so we can scroll back through it.
2463 (goto-char (point-max))))
2465 ((Info-no-error (Info-up t
))
2466 (goto-char (point-min))
2467 (let ((case-fold-search t
))
2468 (or (search-forward "\n* Menu:" nil t
)
2469 (goto-char (point-max)))))
2470 (t (error "No previous nodes"))))
2472 (defun Info-scroll-up ()
2473 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2474 Once you scroll far enough in a node that its menu appears on the screen
2475 but after point, the next scroll moves into its first subnode, unless
2476 `Info-scroll-prefer-subnodes' is nil.
2478 When you scroll past the end of a node, that goes to the next node if
2479 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2480 if this node has no successor, it moves to the parent node's successor,
2481 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2482 the menu of a node, it moves to subnode indicated by the following menu
2483 item. (That case won't normally result from this command, but can happen
2487 (if (or (< (window-start) (point-min))
2488 (> (window-start) (point-max)))
2489 (set-window-start (selected-window) (point)))
2490 (let* ((case-fold-search t
)
2491 (virtual-end (save-excursion
2492 (goto-char (point-min))
2493 (if (and Info-scroll-prefer-subnodes
2494 (search-forward "\n* Menu:" nil t
))
2497 (if (or (< virtual-end
(window-start))
2498 (pos-visible-in-window-p virtual-end
))
2500 (Info-scroll-prefer-subnodes (Info-next-preorder))
2501 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2502 (t (Info-next-preorder)))
2505 (defun Info-scroll-down ()
2506 "Scroll one screenful back in Info, considering all nodes as one sequence.
2507 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2508 is non-nil, this goes to its last subnode. When you scroll past the
2509 beginning of a node, that goes to the previous node or back up to the
2512 (if (or (< (window-start) (point-min))
2513 (> (window-start) (point-max)))
2514 (set-window-start (selected-window) (point)))
2515 (let* ((case-fold-search t
)
2516 (current-point (point))
2518 (and Info-scroll-prefer-subnodes
2521 (setq current-point
(point))
2522 (goto-char (point-min))
2523 (search-forward "\n* Menu:"
2527 (pos-visible-in-window-p (point-min) nil t
))
2528 (Info-last-preorder)
2531 (defun Info-next-reference (&optional recur
)
2532 "Move cursor to the next cross-reference or menu item in the node."
2534 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2536 (case-fold-search t
))
2537 (or (eobp) (forward-char 1))
2538 (or (re-search-forward pat nil t
)
2540 (goto-char (point-min))
2541 (or (re-search-forward pat nil t
)
2544 (error "No cross references in this node")))))
2545 (goto-char (or (match-beginning 1) (match-beginning 0)))
2546 (if (looking-at "\\* Menu:")
2548 (error "No cross references in this node")
2549 (Info-next-reference t
)))))
2551 (defun Info-prev-reference (&optional recur
)
2552 "Move cursor to the previous cross-reference or menu item in the node."
2554 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2556 (case-fold-search t
))
2557 (or (re-search-backward pat nil t
)
2559 (goto-char (point-max))
2560 (or (re-search-backward pat nil t
)
2563 (error "No cross references in this node")))))
2564 (goto-char (or (match-beginning 1) (match-beginning 0)))
2565 (if (looking-at "\\* Menu:")
2567 (error "No cross references in this node")
2568 (Info-prev-reference t
)))))
2570 (defvar Info-index-nodes nil
2571 "Alist of cached index node names of visited Info files.
2572 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2574 (defun Info-index-nodes (&optional file
)
2575 "Return a list of names of all index nodes in Info FILE.
2576 If FILE is omitted, it defaults to the current Info file.
2577 First look in a list of cached index node names. Then scan Info
2578 file and its subfiles for nodes with the index cookie. Then try
2579 to find index nodes starting from the first node in the top level
2580 menu whose name contains the word \"Index\", plus any immediately
2581 following nodes whose names also contain the word \"Index\"."
2582 (or file
(setq file Info-current-file
))
2583 (or (assoc file Info-index-nodes
)
2584 ;; Skip virtual Info files
2585 (and (member file
'("dir" "history" "toc" "apropos"))
2586 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2587 (not (stringp file
))
2588 ;; Find nodes with index cookie
2589 (let* ((default-directory (or (and (stringp file
)
2590 (file-name-directory
2591 (setq file
(Info-find-file file
))))
2593 Info-history Info-history-list Info-fontify-maximum-menu-size
2594 (main-file file
) subfiles nodes node
)
2597 (while (or main-file subfiles
)
2599 (info-insert-file-contents (or main-file
(car subfiles
)))
2600 (goto-char (point-min))
2601 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2603 (re-search-backward "^\^_")
2604 (search-forward "Node: ")
2605 (setq nodes
(cons (Info-following-node-name) nodes
))))
2608 (goto-char (point-min))
2609 (if (search-forward "\n\^_\nIndirect:" nil t
)
2610 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2611 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2612 (setq subfiles
(cons (match-string-no-properties 1)
2614 (setq subfiles
(nreverse subfiles
)
2616 (setq subfiles
(cdr subfiles
)))))
2619 (setq nodes
(nreverse nodes
)
2620 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2622 ;; Find nodes with the word "Index" in the node name
2623 (let ((case-fold-search t
)
2624 Info-history Info-history-list Info-fontify-maximum-menu-size
2629 (Info-find-node file
"Top")
2630 (when (and (search-forward "\n* menu:" nil t
)
2631 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2632 (goto-char (match-beginning 1))
2633 (setq nodes
(list (Info-extract-menu-node-name)))
2634 (Info-goto-node (car nodes
))
2635 (while (and (setq node
(Info-extract-pointer "next" t
))
2636 (string-match "\\<Index\\>" node
))
2637 (setq nodes
(cons node nodes
))
2638 (Info-goto-node node
))))
2641 (setq nodes
(nreverse nodes
)
2642 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2644 ;; If file has no index nodes, still add it to the cache
2645 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2646 (cdr (assoc file Info-index-nodes
)))
2648 (defun Info-index-node (&optional node file
)
2649 "Return non-nil value if NODE is an index node.
2650 If NODE is nil, check the current Info node.
2651 If FILE is nil, check the current Info file."
2652 (if (or (and node
(not (equal node Info-current-node
)))
2653 (assoc (or file Info-current-file
) Info-index-nodes
))
2654 (member (or node Info-current-node
) (Info-index-nodes file
))
2655 ;; Don't search all index nodes if request is only for the current node
2656 ;; and file is not in the cache of index nodes
2659 (string-match "\\<Index\\>" (or node Info-current-node
"")))
2661 (goto-char (+ (or (save-excursion
2662 (search-backward "\n\^_" nil t
))
2664 (search-forward "\0\b[index\0\b]"
2666 (search-forward "\n\^_" nil t
))
2669 (defun Info-goto-index ()
2670 "Go to the first index node."
2671 (let ((node (car (Info-index-nodes))))
2672 (or node
(error "No index"))
2673 (Info-goto-node node
)))
2676 (defun Info-index (topic)
2677 "Look up a string TOPIC in the index for this file.
2678 If there are no exact matches to the specified topic, this chooses
2679 the first match which is a case-insensitive substring of a topic.
2680 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2681 Give a blank topic name to go to the Index node itself."
2684 (let ((Info-complete-menu-buffer (clone-buffer))
2685 (Info-complete-nodes (Info-index-nodes))
2686 (Info-history-list nil
))
2687 (if (equal Info-current-file
"dir")
2688 (error "The Info directory node has no index; use m to select a manual"))
2690 (with-current-buffer Info-complete-menu-buffer
2692 (completing-read "Index topic: " 'Info-complete-menu-item
))
2693 (kill-buffer Info-complete-menu-buffer
)))))
2694 (if (equal Info-current-file
"dir")
2695 (error "The Info directory node has no index; use m to select a manual"))
2696 (let ((orignode Info-current-node
)
2697 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2698 (regexp-quote topic
)))
2699 node
(nodes (Info-index-nodes))
2700 (ohist-list Info-history-list
)
2701 (case-fold-search t
))
2703 (or (equal topic
"")
2706 ;; We bind Info-history to nil for internal node-switches so
2707 ;; that we don't put junk in the history. In the first
2708 ;; Info-goto-index call, above, we do update the history
2709 ;; because that is what the user's previous node choice into it.
2714 (goto-char (point-min))
2715 (while (re-search-forward pattern nil t
)
2716 (push (list (match-string-no-properties 1)
2717 (match-string-no-properties 2)
2719 (string-to-number (concat "0"
2722 (setq nodes
(cdr nodes
) node
(car nodes
)))
2723 (Info-goto-node node
))
2726 (Info-goto-node orignode
)
2727 (error "No `%s' in index" topic
)))
2728 ;; Here it is a feature that assoc is case-sensitive.
2729 (while (setq found
(assoc topic matches
))
2730 (setq exact
(cons found exact
)
2731 matches
(delq found matches
)))
2732 (setq Info-history-list ohist-list
)
2733 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
2734 (Info-index-next 0)))))
2736 (defun Info-index-next (num)
2737 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
2739 (or Info-index-alternatives
2740 (error "No previous `i' command"))
2742 (setq num
(+ num
(length Info-index-alternatives
))))
2744 (setq Info-index-alternatives
2745 (nconc (cdr Info-index-alternatives
)
2746 (list (car Info-index-alternatives
)))
2748 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
2749 (if (> (nth 3 (car Info-index-alternatives
)) 0)
2750 (forward-line (1- (nth 3 (car Info-index-alternatives
))))
2751 (forward-line 3) ; don't search in headers
2752 (let ((name (car (car Info-index-alternatives
))))
2753 (Info-find-index-name name
)))
2754 (message "Found `%s' in %s. %s"
2755 (car (car Info-index-alternatives
))
2756 (nth 2 (car Info-index-alternatives
))
2757 (if (cdr Info-index-alternatives
)
2758 "(`,' tries to find next)"
2761 (defun Info-find-index-name (name)
2762 "Move point to the place within the current node where NAME is defined."
2763 (let ((case-fold-search t
))
2764 (if (or (re-search-forward (format
2765 "[a-zA-Z]+: %s\\( \\|$\\)"
2766 (regexp-quote name
)) nil t
)
2767 ;; Find a function definition with a return type.
2768 (re-search-forward (format
2769 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2770 (regexp-quote name
)) nil t
)
2771 (search-forward (format "`%s'" name
) nil t
)
2772 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
2774 (format "`%s'" (substring name
0 (match-beginning 1)))
2776 (search-forward name nil t
)
2777 ;; Try again without the " <1>" makeinfo can append
2778 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
2779 (Info-find-index-name (match-string 1 name
))))
2780 (progn (beginning-of-line) t
) ;; non-nil for recursive call
2781 (goto-char (point-min)))))
2784 (defun info-apropos (string)
2785 "Grovel indices of all known Info files on your system for STRING.
2786 Build a menu of the possible matches."
2787 (interactive "sIndex apropos: ")
2788 (unless (string= string
"")
2789 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2790 (regexp-quote string
)))
2791 (ohist Info-history
)
2792 (ohist-list Info-history-list
)
2793 (current-node Info-current-node
)
2794 (current-file Info-current-file
)
2795 manuals matches node nodes
)
2796 (let ((Info-fontify-maximum-menu-size nil
))
2798 (message "Searching indices...")
2799 (goto-char (point-min))
2800 (re-search-forward "\\* Menu: *\n" nil t
)
2801 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
2802 (add-to-list 'manuals
(match-string 1)))
2803 (dolist (manual manuals
)
2804 (message "Searching %s" manual
)
2805 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
2808 (Info-find-node manual
(car nodes
))
2811 (goto-char (point-min))
2812 (while (re-search-forward pattern nil t
)
2813 (add-to-list 'matches
2815 (match-string-no-properties 1)
2816 (match-string-no-properties 2)
2817 (match-string-no-properties 3))))
2818 (setq nodes
(cdr nodes
) node
(car nodes
)))
2819 (Info-goto-node node
)))
2821 (Info-goto-node (concat "(" current-file
")" current-node
))
2822 (setq Info-history ohist
2823 Info-history-list ohist-list
)
2824 (message "Searching indices...done")
2826 (message "No matches found")
2827 (with-current-buffer (get-buffer-create " *info-apropos*")
2829 (insert "\n\^_\nFile: apropos, Node: Index, Up: (dir)\n")
2830 (insert "* Menu: \nNodes whose indices contain \"" string
"\"\n\n")
2831 (dolist (entry matches
)
2833 (format "* %-38s (%s)%s.%s\n"
2834 (concat (nth 1 entry
) " [" (nth 0 entry
) "]:")
2838 (concat " (line " (nth 3 entry
) ")")
2840 (Info-find-node "apropos" "Index")
2841 (setq Info-complete-cache nil
)))))
2843 (defun Info-undefined ()
2844 "Make command be undefined in Info."
2849 "Enter the Info tutorial."
2851 (delete-other-windows)
2852 (Info-find-node "info"
2853 (if (< (window-height) 23)
2857 (defun Info-summary ()
2858 "Display a brief summary of all Info commands."
2860 (save-window-excursion
2861 (switch-to-buffer "*Help*")
2862 (setq buffer-read-only nil
)
2864 (insert (documentation 'Info-mode
))
2866 (goto-char (point-min))
2868 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
2869 (message (if flag
"Type Space to see more"
2870 "Type Space to return to Info"))
2871 (if (not (eq ?\s
(setq ch
(read-event))))
2872 (progn (setq unread-command-events
(list ch
)) nil
)
2875 (bury-buffer "*Help*")))
2877 (defun Info-get-token (pos start all
&optional errorstring
)
2878 "Return the token around POS.
2879 POS must be somewhere inside the token
2880 START is a regular expression which will match the
2881 beginning of the tokens delimited string
2882 ALL is a regular expression with a single
2883 parenthesized subpattern which is the token to be
2884 returned. E.g. '{\(.*\)}' would return any string
2885 enclosed in braces around POS.
2886 ERRORSTRING optional fourth argument, controls action on no match
2889 a string: signal an error, using that string."
2890 (let ((case-fold-search t
))
2893 ;; First look for a match for START that goes across POS.
2894 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2895 (not (looking-at start
)))
2897 ;; If we did not find one, search back for START
2898 ;; (this finds only matches that end at or before POS).
2899 (or (looking-at start
)
2902 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2904 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2905 (not (setq found
(and (<= (match-beginning 0) pos
)
2906 (> (match-end 0) pos
))))))
2907 (if (and found
(<= (match-beginning 0) pos
)
2908 (> (match-end 0) pos
))
2909 (match-string-no-properties 1)
2910 (cond ((null errorstring
)
2916 (error "No %s around position %d" errorstring pos
))))))))
2918 (defun Info-mouse-follow-nearest-node (click)
2919 "\\<Info-mode-map>Follow a node reference near point.
2920 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2921 At end of the node's text, moves to the next node, or up if none."
2923 (mouse-set-point click
)
2924 (and (not (Info-try-follow-nearest-node))
2925 (save-excursion (forward-line 1) (eobp))
2926 (Info-next-preorder)))
2928 (defun Info-follow-nearest-node (&optional fork
)
2929 "Follow a node reference near point.
2930 If point is on a reference, follow that reference. Otherwise,
2931 if point is in a menu item description, follow that menu item."
2933 (or (Info-try-follow-nearest-node fork
)
2934 (when (save-excursion
2935 (search-backward "\n* menu:" nil t
))
2938 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2939 (beginning-of-line 0))
2940 (when (looking-at "\\* +\\([^\t\n]*\\):")
2942 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
2944 (error "Point neither on reference nor in menu item description")))
2946 ;; Common subroutine.
2947 (defun Info-try-follow-nearest-node (&optional fork
)
2948 "Follow a node reference near point. Return non-nil if successful."
2951 ((Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
2953 (browse-url (browse-url-url-at-point)))
2954 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
2955 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
2956 (Info-follow-reference node fork
))
2957 ;; menu item: node name
2958 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2959 (Info-goto-node node fork
))
2960 ;; menu item: node name or index entry
2961 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2964 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
2965 (Info-goto-node node fork
))
2966 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2967 (Info-goto-node node fork
))
2968 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2969 (Info-goto-node node fork
))
2970 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2971 (Info-goto-node "Top" fork
))
2972 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2973 (Info-goto-node node fork
)))
2976 (defvar Info-mode-map nil
2977 "Keymap containing Info commands.")
2980 (setq Info-mode-map
(make-keymap))
2981 (suppress-keymap Info-mode-map
)
2982 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2983 (define-key Info-mode-map
" " 'Info-scroll-up
)
2984 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2985 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2986 (define-key Info-mode-map
[(shift tab
)] 'Info-prev-reference
)
2987 (define-key Info-mode-map
[backtab] 'Info-prev-reference)
2988 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2989 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2990 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2991 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2992 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2993 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2994 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2995 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2996 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2997 (define-key Info-mode-map "0" 'undefined)
2998 (define-key Info-mode-map "?" 'Info-summary)
2999 (define-key Info-mode-map "]" 'Info-forward-node)
3000 (define-key Info-mode-map "[" 'Info-backward-node)
3001 (define-key Info-mode-map "<" 'Info-top-node)
3002 (define-key Info-mode-map ">" 'Info-final-node)
3003 (define-key Info-mode-map "b" 'beginning-of-buffer)
3004 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
3005 (define-key Info-mode-map "d" 'Info-directory)
3006 (define-key Info-mode-map "e" 'Info-edit)
3007 (define-key Info-mode-map "f" 'Info-follow-reference)
3008 (define-key Info-mode-map "g" 'Info-goto-node)
3009 (define-key Info-mode-map "h" 'Info-help)
3010 (define-key Info-mode-map "i" 'Info-index)
3011 (define-key Info-mode-map "l" 'Info-history-back)
3012 (define-key Info-mode-map "L" 'Info-history)
3013 (define-key Info-mode-map "m" 'Info-menu)
3014 (define-key Info-mode-map "n" 'Info-next)
3015 (define-key Info-mode-map "p" 'Info-prev)
3016 (define-key Info-mode-map "q" 'Info-exit)
3017 (define-key Info-mode-map "r" 'Info-history-forward)
3018 (define-key Info-mode-map "s" 'Info-search)
3019 (define-key Info-mode-map "S" 'Info-search-case-sensitively)
3020 ;; For consistency with Rmail.
3021 (define-key Info-mode-map "\M-s" 'Info-search)
3022 (define-key Info-mode-map "\M-n" 'clone-buffer)
3023 (define-key Info-mode-map "t" 'Info-top-node)
3024 (define-key Info-mode-map "T" 'Info-toc)
3025 (define-key Info-mode-map "u" 'Info-up)
3026 ;; For consistency with dired-copy-filename-as-kill.
3027 (define-key Info-mode-map "w" 'Info-copy-current-node-name)
3028 (define-key Info-mode-map "," 'Info-index-next)
3029 (define-key Info-mode-map "\177" 'Info-scroll-down)
3030 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
3031 (define-key Info-mode-map [follow-link] 'mouse-face)
3034 (defun Info-check-pointer (item)
3035 "Non-nil if ITEM is present in this node."
3037 (Info-extract-pointer item)
3041 Info-mode-menu Info-mode-map
3042 "Menu for info files."
3044 ["Up" Info-up :active (Info-check-pointer "up")
3045 :help "Go up in the Info tree"]
3046 ["Next" Info-next :active (Info-check-pointer "next")
3047 :help "Go to the next node"]
3048 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3049 :help "Go to the previous node"]
3050 ["Backward" Info-backward-node
3051 :help "Go backward one node, considering all as a sequence"]
3052 ["Forward" Info-forward-node
3053 :help "Go forward one node, considering all as a sequence"]
3054 ["Beginning" beginning-of-buffer
3055 :help "Go to beginning of this node"]
3056 ["Top" Info-top-node
3057 :help "Go to top node of file"]
3058 ["Final Node" Info-final-node
3059 :help "Go to final node in this file"]
3060 ("Menu Item" ["You should never see this" report-emacs-bug t])
3061 ("Reference" ["You should never see this" report-emacs-bug t])
3062 ["Search..." Info-search
3063 :help "Search for regular expression in this Info file"]
3064 ["Search Case-Sensitively..." Info-search-case-sensitively
3065 :help "Search for regular expression case sensitively"]
3066 ["Search Next" Info-search-next
3067 :help "Search for another occurrence of regular expression"]
3068 ["Go to Node..." Info-goto-node
3069 :help "Go to a named node"]
3070 ["Back in history" Info-history-back :active Info-history
3071 :help "Go back in history to the last node you were at"]
3072 ["Forward in history" Info-history-forward :active Info-history-forward
3073 :help "Go forward in history"]
3074 ["History" Info-history :active Info-history-list
3075 :help "Go to menu of visited nodes"]
3076 ["Table of Contents" Info-toc
3077 :help "Go to table of contents"]
3079 ["Lookup a String..." Info-index
3080 :help "Look for a string in the index items"]
3081 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3082 :help "Look for another occurrence of previous item"]
3083 ["Lookup a string in all indices..." info-apropos
3084 :help "Look for a string in the indices of all manuals"])
3085 ["Edit" Info-edit :help "Edit contents of this node"
3086 :active Info-enable-edit]
3087 ["Copy Node Name" Info-copy-current-node-name
3088 :help "Copy the name of the current node into the kill ring"]
3089 ["Clone Info buffer" clone-buffer
3090 :help "Create a twin copy of the current Info buffer."]
3091 ["Exit" Info-exit :help "Stop reading Info"]))
3094 (defvar info-tool-bar-map
3095 (if (display-graphic-p)
3096 (let ((map (make-sparse-keymap)))
3097 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
3098 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
3099 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
3100 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
3101 (tool-bar-local-item-from-menu 'Info-history-back "back_arrow" map Info-mode-map)
3102 (tool-bar-local-item-from-menu 'Info-history-forward "fwd_arrow" map Info-mode-map)
3103 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3104 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3105 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
3106 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3109 (defvar Info-menu-last-node nil)
3110 ;; Last node the menu was created for.
3111 ;; Value is a list, (FILE-NAME NODE-NAME).
3113 (defun Info-menu-update ()
3114 "Update the Info menu for the current node."
3116 (if (or (not (eq major-mode 'Info-mode))
3117 (equal (list Info-current-file Info-current-node)
3118 Info-menu-last-node))
3120 ;; Update menu menu.
3121 (let* ((Info-complete-menu-buffer (current-buffer))
3122 (items (nreverse (condition-case nil
3123 (Info-complete-menu-item "" nil t)
3127 (while (and items (< number 9))
3128 (setq current (car items)
3131 (setq entries (cons `[,current
3132 (Info-menu ,current)
3133 :keys ,(format "%d" number)]
3136 (setq entries (cons ["Other..." Info-menu t] entries)))
3138 (setq entries (list ["No menu" nil nil] nil :active)))
3139 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3140 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3142 str i entries current
3144 (case-fold-search t))
3146 (goto-char (point-min))
3147 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3148 (setq str (match-string 1))
3150 (while (setq i (string-match "[ \n\t]+" str i))
3151 (setq str (concat (substring str 0 i) " "
3152 (substring str (match-end 0))))
3156 (while (and items (< number 9))
3157 (setq current (car items)
3160 (setq entries (cons `[,current
3161 (Info-follow-reference ,current)
3165 (setq entries (cons ["Other..." Info-follow-reference t]
3168 (setq entries (list ["No references" nil nil] nil :active)))
3169 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3170 ;; Update last seen node.
3171 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3172 ;; Try to avoid entering infinite beep mode in case of errors.
3176 (defun Info-copy-current-node-name (&optional arg)
3177 "Put the name of the current info node into the kill ring.
3178 The name of the info file is prepended to the node name in parentheses.
3179 With a zero prefix arg, put the name inside a function call to `info'."
3181 (unless Info-current-node
3182 (error "No current info node"))
3183 (let ((node (concat "(" (file-name-nondirectory
3184 (or (and (stringp Info-current-file)
3188 ")" Info-current-node)))
3189 (if (zerop (prefix-numeric-value arg))
3190 (setq node (concat "(info \"" node "\")")))
3192 (message "%s" node)))
3195 ;; Info mode is suitable only for specially formatted data.
3196 (put 'Info-mode 'mode-class 'special)
3197 (put 'Info-mode 'no-clone-indirect t)
3199 (defvar tool-bar-map)
3202 "Info mode provides commands for browsing through the Info documentation tree.
3203 Documentation in Info is divided into \"nodes\", each of which discusses
3204 one topic and contains references to other nodes which discuss related
3205 topics. Info has commands to follow the references and show you other nodes.
3208 \\[Info-help] Invoke the Info tutorial.
3209 \\[Info-exit] Quit Info: reselect previously selected buffer.
3211 Selecting other nodes:
3212 \\[Info-mouse-follow-nearest-node]
3213 Follow a node reference you click on.
3214 This works with menu items, cross references, and
3215 the \"next\", \"previous\" and \"up\", depending on where you click.
3216 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3217 \\[Info-next] Move to the \"next\" node of this node.
3218 \\[Info-prev] Move to the \"previous\" node of this node.
3219 \\[Info-up] Move \"up\" from this node.
3220 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3221 Picking a menu item causes another node to be selected.
3222 \\[Info-directory] Go to the Info directory node.
3223 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3224 \\[Info-history-back] Move back in history to the last node you were at.
3225 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3226 \\[Info-history] Go to menu of visited nodes.
3227 \\[Info-toc] Go to table of contents of the current Info file.
3228 \\[Info-top-node] Go to the Top node of this file.
3229 \\[Info-final-node] Go to the final node in this file.
3230 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3231 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3232 \\[Info-index] Look up a topic in this file's Index and move to that node.
3233 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3234 \\[info-apropos] Look for a string in the indices of all manuals.
3236 Moving within a node:
3237 \\[Info-scroll-up] Normally, scroll forward a full screen.
3238 Once you scroll far enough in a node that its menu appears on the
3239 screen but after point, the next scroll moves into its first
3240 subnode. When after all menu items (or if there is no menu),
3241 move up to the parent node.
3242 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3243 already visible, try to go to the previous menu entry, or up
3245 \\[beginning-of-buffer] Go to beginning of node.
3248 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
3249 \\[clone-buffer] Select a new cloned Info buffer in another window.
3250 \\[Info-edit] Edit contents of selected node.
3251 1 .. 9 Pick first ... ninth item in node's menu.
3252 Every third `*' is highlighted to help pick the right number.
3253 \\[Info-goto-node] Move to node specified by name.
3254 You may include a filename as well, as (FILENAME)NODENAME.
3255 \\[universal-argument] \\[info] Move to new Info file with completion.
3256 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>.
3257 \\[Info-search] Search through this Info file for specified regexp,
3258 and select the node in which the next occurrence is found.
3259 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3260 \\[Info-search-next] Search for another occurrence of regexp
3261 from a previous \\<Info-mode-map>\\[Info-search] command.
3262 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3263 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
3264 (kill-all-local-variables)
3265 (setq major-mode 'Info-mode)
3266 (setq mode-name "Info")
3268 (use-local-map Info-mode-map)
3269 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3270 (set-syntax-table text-mode-syntax-table)
3271 (setq local-abbrev-table text-mode-abbrev-table)
3272 (setq case-fold-search t)
3273 (setq buffer-read-only t)
3274 (make-local-variable 'Info-current-file)
3275 (make-local-variable 'Info-current-subfile)
3276 (make-local-variable 'Info-current-node)
3277 (make-local-variable 'Info-tag-table-marker)
3278 (setq Info-tag-table-marker (make-marker))
3279 (make-local-variable 'Info-tag-table-buffer)
3280 (setq Info-tag-table-buffer nil)
3281 (make-local-variable 'Info-history)
3282 (make-local-variable 'Info-history-forward)
3283 (make-local-variable 'Info-index-alternatives)
3284 (setq header-line-format
3285 (if Info-use-header-line
3286 '(:eval (get-text-property (point-min) 'header-line))
3287 nil)) ; so the header line isn't displayed
3288 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3289 ;; This is for the sake of the invisible text we use handling titles.
3290 (make-local-variable 'line-move-ignore-invisible)
3291 (setq line-move-ignore-invisible t)
3292 (make-local-variable 'desktop-save-buffer)
3293 (make-local-variable 'widen-automatically)
3294 (setq widen-automatically nil)
3295 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3296 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3297 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3298 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3299 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3300 (set (make-local-variable 'isearch-search-fun-function)
3301 'Info-isearch-search)
3302 (set (make-local-variable 'isearch-wrap-function)
3304 (set (make-local-variable 'isearch-push-state-function)
3305 'Info-isearch-push-state)
3306 (set (make-local-variable 'search-whitespace-regexp)
3307 Info-search-whitespace-regexp)
3308 (Info-set-mode-line)
3309 (run-mode-hooks 'Info-mode-hook))
3311 ;; When an Info buffer is killed, make sure the associated tags buffer
3313 (defun Info-kill-buffer ()
3314 (and (eq major-mode 'Info-mode)
3315 Info-tag-table-buffer
3316 (kill-buffer Info-tag-table-buffer)))
3318 (defun Info-clone-buffer-hook ()
3319 (when (bufferp Info-tag-table-buffer)
3320 (setq Info-tag-table-buffer
3321 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3322 (let ((m Info-tag-table-marker))
3324 (setq Info-tag-table-marker
3325 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3326 (with-current-buffer Info-tag-table-buffer
3327 (copy-marker (marker-position m)))
3330 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3331 (set-keymap-parent map text-mode-map)
3332 (define-key map "\C-c\C-c" 'Info-cease-edit)
3334 "Local keymap used within `e' command of Info.")
3336 ;; Info-edit mode is suitable only for specially formatted data.
3337 (put 'Info-edit-mode 'mode-class 'special)
3339 (defun Info-edit-mode ()
3340 "Major mode for editing the contents of an Info node.
3341 Like text mode with the addition of `Info-cease-edit'
3342 which returns to Info mode for browsing.
3344 (use-local-map Info-edit-map)
3345 (setq major-mode 'Info-edit-mode)
3346 (setq mode-name "Info Edit")
3347 (kill-local-variable 'mode-line-buffer-identification)
3348 (setq buffer-read-only nil)
3349 (force-mode-line-update)
3350 (buffer-enable-undo (current-buffer))
3351 (run-mode-hooks 'Info-edit-mode-hook))
3354 "Edit the contents of this Info node.
3355 Allowed only if variable `Info-enable-edit' is non-nil."
3357 (or Info-enable-edit
3358 (error "Editing info nodes is not enabled"))
3360 (message "%s" (substitute-command-keys
3361 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
3363 (defun Info-cease-edit ()
3364 "Finish editing Info node; switch back to Info proper."
3366 ;; Do this first, so nothing has changed if user C-g's at query.
3367 (and (buffer-modified-p)
3368 (y-or-n-p "Save the file? ")
3370 (use-local-map Info-mode-map)
3371 (setq major-mode 'Info-mode)
3372 (setq mode-name "Info")
3373 (Info-set-mode-line)
3374 (setq buffer-read-only t)
3375 (force-mode-line-update)
3376 (and (marker-position Info-tag-table-marker)
3378 (message "Tags may have changed. Use Info-tagify if necessary")))
3380 (defvar Info-file-list-for-emacs
3381 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
3382 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3383 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3384 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3385 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3386 ("copyright" . "autotype") ("executable" . "autotype")
3387 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3388 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3389 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3390 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3391 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3392 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3393 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3394 ("rfc2045" . "emacs-mime")
3395 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3396 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3397 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3398 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3399 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3400 ("mml" . "emacs-mime"))
3401 "List of Info files that describe Emacs commands.
3402 An element can be a file name, or a list of the form (PREFIX . FILE)
3403 where PREFIX is a name prefix and FILE is the file to look in.
3404 If the element is just a file name, the file name also serves as the prefix.")
3406 (defun Info-find-emacs-command-nodes (command)
3407 "Return a list of locations documenting COMMAND.
3408 The `info-file' property of COMMAND says which Info manual to search.
3409 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3410 defines heuristics for which Info manual to try.
3411 The locations are of the format used in `Info-history', i.e.
3412 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3413 in the first element of the returned list (which is treated specially in
3414 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3415 (let ((where '()) line-number
3416 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3417 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
3418 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
3419 (info-file "emacs")) ;default
3420 ;; Determine which info file this command is documented in.
3421 (if (get command 'info-file)
3422 (setq info-file (get command 'info-file))
3423 ;; If it doesn't say explicitly, test its name against
3424 ;; various prefixes that we know.
3425 (let ((file-list Info-file-list-for-emacs))
3427 (let* ((elt (car file-list))
3428 (name (if (consp elt)
3431 (file (if (consp elt) (cdr elt) elt))
3432 (case-fold-search nil)
3433 (regexp (concat "\\`" (regexp-quote name)
3435 (if (string-match regexp (symbol-name command))
3436 (setq info-file file file-list nil))
3437 (setq file-list (cdr file-list))))))
3438 (Info-find-node info-file "Top")
3439 (or (and (search-forward "\n* menu:" nil t)
3440 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3441 (error "Info file `%s' appears to lack an index" info-file))
3442 (goto-char (match-beginning 1))
3443 ;; Bind Info-history to nil, to prevent the index nodes from
3444 ;; getting into the node history.
3445 (let ((Info-history nil)
3446 (Info-history-list nil)
3447 node (nodes (Info-index-nodes)))
3448 (Info-goto-node (car nodes))
3451 (goto-char (point-min))
3452 (while (re-search-forward cmd-desc nil t)
3454 (cons (list Info-current-file
3455 (match-string-no-properties 2)
3458 (setq line-number (and (match-beginning 3)
3459 (string-to-number (match-string 3)))))
3460 (and (setq nodes (cdr nodes) node (car nodes))))
3461 (Info-goto-node node)))
3462 (if (and line-number where)
3463 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3467 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
3469 (defun Info-goto-emacs-command-node (command)
3470 "Go to the Info node in the Emacs manual for command COMMAND.
3471 The command is found by looking up in Emacs manual's indices
3472 or in another manual found via COMMAND's `info-file' property or
3473 the variable `Info-file-list-for-emacs'.
3474 COMMAND must be a symbol or string."
3475 (interactive "CFind documentation for command: ")
3476 ;; If command is given as a string, convert it to a symbol.
3477 (if (stringp command)
3478 (setq command (intern command)))
3479 (or (commandp command)
3480 (signal 'wrong-type-argument (list 'commandp command)))
3481 (let ((where (Info-find-emacs-command-nodes command)))
3483 (let ((num-matches (length where)))
3484 ;; Get Info running, and pop to it in another window.
3485 (save-window-excursion
3487 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3488 ;; Bind Info-history to nil, to prevent the last Index node
3489 ;; visited by Info-find-emacs-command-nodes from being
3490 ;; pushed onto the history.
3491 (let ((Info-history nil) (Info-history-list nil)
3492 (line-number (nth 2 (car where))))
3493 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3494 (if (and (integerp line-number) (> line-number 0))
3495 (forward-line (1- line-number))))
3496 (if (> num-matches 1)
3498 ;; (car where) will be pushed onto Info-history
3499 ;; when/if they go to another node. Put the other
3500 ;; nodes that were found on the history.
3501 (setq Info-history (nconc (cdr where) Info-history))
3502 (message "Found %d other entr%s. Use %s to see %s."
3504 (if (> num-matches 2) "ies" "y")
3505 (substitute-command-keys "\\[Info-history-back]")
3506 (if (> num-matches 2) "them" "it")))))
3507 (error "Couldn't find documentation for %s" command))))
3509 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
3511 (defun Info-goto-emacs-key-command-node (key)
3512 "Go to the node in the Emacs manual which describes the command bound to KEY.
3514 Interactively, if the binding is `execute-extended-command', a command is read.
3515 The command is found by looking up in Emacs manual's indices
3516 or in another manual found via COMMAND's `info-file' property or
3517 the variable `Info-file-list-for-emacs'."
3518 (interactive "kFind documentation for key: ")
3519 (let ((command (key-binding key)))
3520 (cond ((null command)
3521 (message "%s is undefined" (key-description key)))
3522 ((and (interactive-p)
3523 (eq command 'execute-extended-command))
3524 (Info-goto-emacs-command-node
3525 (read-command "Find documentation for command: ")))
3527 (Info-goto-emacs-command-node command)))))
3529 (defface info-title-1
3530 '((((type tty pc) (class color)) :foreground "green" :weight bold)
3531 (t :height 1.2 :inherit info-title-2))
3532 "Face for info titles at level 1."
3534 ;; backward-compatibility alias
3535 (put 'Info-title-1-face 'face-alias 'info-title-1)
3537 (defface info-title-2
3538 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
3539 (t :height 1.2 :inherit info-title-3))
3540 "Face for info titles at level 2."
3542 ;; backward-compatibility alias
3543 (put 'Info-title-2-face 'face-alias 'info-title-2)
3545 (defface info-title-3
3546 '((((type tty pc) (class color)) :weight bold)
3547 (t :height 1.2 :inherit info-title-4))
3548 "Face for info titles at level 3."
3550 ;; backward-compatibility alias
3551 (put 'Info-title-3-face 'face-alias 'info-title-3)
3553 (defface info-title-4
3554 '((((type tty pc) (class color)) :weight bold)
3555 (t :weight bold :inherit variable-pitch))
3556 "Face for info titles at level 4."
3558 ;; backward-compatibility alias
3559 (put 'Info-title-4-face 'face-alias 'info-title-4)
3561 (defface info-menu-header
3566 :inherit variable-pitch
3568 "Face for headers in Info menus."
3571 (defun Info-escape-percent (string)
3572 "Double all occurrences of `%' in STRING.
3574 Return a new string with all `%' characters replaced by `%%'.
3575 Preserve text properties."
3577 (end (length string))
3580 (while (and (< start end) (string-match "%" string start))
3581 (setq mb (match-beginning 0)
3583 m (substring string mb me)
3586 (cons (substring string start mb)
3589 (push (substring string start end) matches)
3590 (apply #'concat (nreverse matches)))))
3592 (defvar Info-next-link-keymap
3593 (let ((keymap (make-sparse-keymap)))
3594 (define-key keymap [header-line mouse-1] 'Info-next)
3595 (define-key keymap [header-line mouse-2] 'Info-next)
3596 (define-key keymap [header-line down-mouse-1] 'ignore)
3597 (define-key keymap [mouse-2] 'Info-next)
3598 (define-key keymap [follow-link] 'mouse-face)
3600 "Keymap to put on the Next link in the text or the header line.")
3602 (defvar Info-prev-link-keymap
3603 (let ((keymap (make-sparse-keymap)))
3604 (define-key keymap [header-line mouse-1] 'Info-prev)
3605 (define-key keymap [header-line mouse-2] 'Info-prev)
3606 (define-key keymap [header-line down-mouse-1] 'ignore)
3607 (define-key keymap [mouse-2] 'Info-prev)
3608 (define-key keymap [follow-link] 'mouse-face)
3610 "Keymap to put on the Prev link in the text or the header line.")
3613 (defvar Info-up-link-keymap
3614 (let ((keymap (make-sparse-keymap)))
3615 (define-key keymap [header-line mouse-1] 'Info-up)
3616 (define-key keymap [header-line mouse-2] 'Info-up)
3617 (define-key keymap [header-line down-mouse-1] 'ignore)
3618 (define-key keymap [mouse-2] 'Info-up)
3619 (define-key keymap [follow-link] 'mouse-face)
3621 "Keymap to put on the Up link in the text or the header line.")
3623 (defun Info-fontify-node ()
3626 (let* ((inhibit-read-only t)
3627 (case-fold-search t)
3629 (not-fontified-p ; the node hasn't already been fontified
3630 (not (let ((where (next-property-change (point-min))))
3631 (and where (not (= where (point-max)))))))
3632 (fontify-visited-p ; visited nodes need to be re-fontified
3633 (and Info-fontify-visited-nodes
3634 ;; Don't take time to refontify visited nodes in huge nodes
3635 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
3638 ;; Fontify header line
3639 (goto-char (point-min))
3640 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3641 (goto-char (match-end 0))
3642 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3643 (goto-char (match-end 0))
3644 (let* ((nbeg (match-beginning 2))
3645 (nend (match-end 2))
3646 (tbeg (match-beginning 1))
3647 (tag (match-string 1)))
3648 (if (string-equal tag "Node")
3649 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3650 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3651 (put-text-property tbeg nend 'mouse-face 'highlight)
3652 (put-text-property tbeg nend
3654 (concat "mouse-2: Go to node "
3655 (buffer-substring nbeg nend)))
3656 ;; Always set up the text property keymap.
3657 ;; It will either be used in the buffer
3658 ;; or copied in the header line.
3659 (put-text-property tbeg nend 'keymap
3661 ((equal tag "Prev") Info-prev-link-keymap)
3662 ((equal tag "Next") Info-next-link-keymap)
3663 ((equal tag "Up") Info-up-link-keymap))))))
3664 (when Info-use-header-line
3665 (goto-char (point-min))
3666 (let ((header-end (line-end-position))
3668 ;; If we find neither Next: nor Prev: link, show the entire
3669 ;; node header. Otherwise, don't show the File: and Node:
3670 ;; parts, to avoid wasting precious space on information that
3671 ;; is available in the mode line.
3672 (if (re-search-forward
3673 "\\(next\\|up\\|prev[ious]*\\): "
3676 (goto-char (match-beginning 1))
3677 (setq header (buffer-substring (point) header-end)))
3678 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3680 (concat "No next, prev or up links -- "
3681 (buffer-substring (point) header-end)))
3682 (setq header (buffer-substring (point) header-end))))
3683 (put-text-property (point-min) (1+ (point-min))
3684 'header-line (Info-escape-percent header))
3685 ;; Hide the part of the first line
3686 ;; that is in the header, if it is just part.
3688 ;; Hide the punctuation at the end, too.
3689 (skip-chars-backward " \t,")
3690 (put-text-property (point) header-end 'invisible t)))))
3693 (goto-char (point-min))
3694 (when not-fontified-p
3695 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
3697 (let* ((c (preceding-char))
3699 (cond ((= c ?*) 'info-title-1)
3700 ((= c ?=) 'info-title-2)
3701 ((= c ?-) 'info-title-3)
3702 (t 'info-title-4))))
3703 (put-text-property (match-beginning 1) (match-end 1)
3704 'font-lock-face face))
3705 ;; This is a serious problem for trying to handle multiple
3706 ;; frame types at once. We want this text to be invisible
3707 ;; on frames that can display the font above.
3708 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3709 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3710 '(invisible t front-sticky nil rear-nonsticky t)))))
3712 ;; Fontify cross references
3713 (goto-char (point-min))
3714 (when (or not-fontified-p fontify-visited-p)
3715 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3716 (let ((start (match-beginning 0))
3719 (when not-fontified-p
3720 (when Info-hide-note-references
3721 (when (not (eq Info-hide-note-references 'hide))
3722 ;; *Note is often used where *note should have been
3724 (skip-syntax-backward " ")
3726 (cond ((memq (char-before) '(nil ?\. ?! ??))
3728 ((memq (char-before) '(?\, ?\; ?\: ?-))
3730 ((memq (char-before) '(?\( ?\[ ?\{))
3731 ;; Check whether the paren is preceded by
3732 ;; an end of sentence
3733 (skip-syntax-backward " (")
3734 (if (memq (char-before) '(nil ?\. ?! ??))
3737 ((save-match-data (looking-at "\n\n"))
3740 (add-text-properties
3742 (or (save-match-data
3743 ;; Don't hide \n after *Note
3744 (let ((start1 (match-beginning 1)))
3745 (if (string-match "\n" (match-string 1))
3746 (+ start1 (match-beginning 0)))))
3749 `(display ,other-tag front-sticky nil rear-nonsticky t)
3750 '(invisible t front-sticky nil rear-nonsticky t))))
3751 (add-text-properties
3752 (match-beginning 2) (match-end 2)
3754 'help-echo (if (or (match-end 5)
3755 (not (equal (match-string 4) "")))
3756 (concat "mouse-2: go to " (or (match-string 5)
3758 "mouse-2: go to this node")
3759 'mouse-face 'highlight)))
3760 (when (or not-fontified-p fontify-visited-p)
3761 (setq rbeg (match-beginning 2)
3766 ;; Display visited nodes in a different face
3767 (if (and Info-fontify-visited-nodes
3769 (let* ((node (replace-regexp-in-string
3771 (replace-regexp-in-string
3773 (or (match-string 5)
3774 (and (not (equal (match-string 4) ""))
3776 (match-string 2)))))
3777 (file (file-name-nondirectory
3779 (hl Info-history-list)
3781 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3782 (setq file (file-name-nondirectory
3783 (match-string 1 node))
3784 node (if (equal (match-string 2 node) "")
3786 (match-string 2 node))))
3788 (if (and (string-equal node (nth 1 (car hl)))
3790 (file-name-nondirectory
3792 (setq res (car hl) hl nil)
3793 (setq hl (cdr hl))))
3794 res))) 'info-xref-visited 'info-xref))
3795 ;; For multiline ref, unfontify newline and surrounding whitespace
3799 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
3800 (remove-text-properties (match-beginning 0)
3802 '(font-lock-face t))))))
3803 (when not-fontified-p
3804 (when (memq Info-hide-note-references '(t hide))
3805 (add-text-properties (match-beginning 3) (match-end 3)
3806 '(invisible t front-sticky nil rear-nonsticky t))
3807 ;; Unhide the file name of the external reference in parens
3808 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
3809 (remove-text-properties (match-beginning 6) (match-end 6)
3810 '(invisible t front-sticky nil rear-nonsticky t)))
3811 ;; Unhide newline because hidden newlines cause too long lines
3813 (let ((beg3 (match-beginning 3))
3814 (end3 (match-end 3)))
3815 (if (and (string-match "\n[ \t]*" (match-string 3))
3816 (not (save-match-data
3818 (goto-char (1+ end3))
3819 (looking-at "[.)]*$")))))
3820 (remove-text-properties (+ beg3 (match-beginning 0))
3821 (+ beg3 (match-end 0))
3822 '(invisible t front-sticky nil rear-nonsticky t))))))
3823 (when (and Info-refill-paragraphs Info-hide-note-references)
3824 (push (set-marker (make-marker) start)
3825 paragraph-markers))))))
3827 ;; Refill paragraphs (experimental feature)
3828 (when (and not-fontified-p
3829 Info-refill-paragraphs
3831 (let ((fill-nobreak-invisible t)
3832 (fill-individual-varying-indent nil)
3833 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3834 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3835 (adaptive-fill-mode nil))
3836 (goto-char (point-max))
3837 (while paragraph-markers
3838 (let ((m (car paragraph-markers)))
3839 (setq paragraph-markers (cdr paragraph-markers))
3843 (let ((beg (point)))
3844 (when (zerop (forward-paragraph))
3845 (fill-individual-paragraphs beg (point) nil nil)
3847 (set-marker m nil)))))
3849 ;; Fontify menu items
3850 (goto-char (point-min))
3851 (when (and (or not-fontified-p fontify-visited-p)
3852 (search-forward "\n* Menu:" nil t)
3853 (not (Info-index-node))
3854 ;; Don't take time to annotate huge menus
3855 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3858 (while (re-search-forward
3859 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3860 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
3862 (when (match-beginning 1)
3863 (when not-fontified-p
3865 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3866 (put-text-property (match-beginning 0)
3867 (1+ (match-beginning 0))
3868 'font-lock-face 'info-menu-5)))
3869 (when not-fontified-p
3870 (add-text-properties
3871 (match-beginning 1) (match-end 1)
3873 'help-echo (if (and (match-end 3)
3874 (not (equal (match-string 3) "")))
3875 (concat "mouse-2: go to " (match-string 3))
3876 "mouse-2: go to this node")
3877 'mouse-face 'highlight)))
3878 (when (or not-fontified-p fontify-visited-p)
3879 (add-text-properties
3880 (match-beginning 1) (match-end 1)
3883 ;; Display visited menu items in a different face
3884 (if (and Info-fontify-visited-nodes
3886 (let ((node (if (equal (match-string 3) "")
3889 (file (file-name-nondirectory Info-current-file))
3890 (hl Info-history-list)
3892 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3893 (setq file (file-name-nondirectory
3894 (match-string 1 node))
3895 node (if (equal (match-string 2 node) "")
3897 (match-string 2 node))))
3899 (if (and (string-equal node (nth 1 (car hl)))
3901 (file-name-nondirectory
3903 (setq res (car hl) hl nil)
3904 (setq hl (cdr hl))))
3905 res))) 'info-xref-visited 'info-xref))))
3906 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3907 (put-text-property (match-beginning 2) (1- (match-end 6))
3909 ;; Unhide the file name in parens
3910 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3911 (remove-text-properties (match-beginning 4) (match-end 4)
3913 ;; We need a stretchable space like :align-to but with
3915 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3916 (if (>= 22 (- (match-end 1)
3917 (match-beginning 0)))
3918 '(space :align-to 24)
3920 (setq cont (looking-at "."))
3921 (while (and (= (forward-line 1) 0)
3922 (looking-at "\\([ \t]+\\)[^*\n]"))
3923 (put-text-property (match-beginning 1) (1- (match-end 1))
3925 (put-text-property (1- (match-end 1)) (match-end 1)
3928 '(space :align-to 26)
3929 '(space :align-to 24)))
3932 ;; Fontify menu headers
3933 ;; Add the face `info-menu-header' to any header before a menu entry
3934 (goto-char (point-min))
3935 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3936 (put-text-property (match-beginning 0) (match-end 0)
3937 'font-lock-face 'info-menu-header)
3938 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3939 (put-text-property (match-beginning 1) (match-end 1)
3940 'font-lock-face 'info-menu-header)))
3942 ;; Hide index line numbers
3943 (goto-char (point-min))
3944 (when (and not-fontified-p (Info-index-node))
3945 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3946 (put-text-property (match-beginning 0) (match-end 0)
3949 ;; Fontify http and ftp references
3950 (goto-char (point-min))
3951 (when not-fontified-p
3952 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3953 (add-text-properties (match-beginning 0) (match-end 0)
3954 '(font-lock-face info-xref
3955 mouse-face highlight
3956 help-echo "mouse-2: go to this URL"))))
3958 (set-buffer-modified-p nil))))
3960 ;;; Speedbar support:
3961 ;; These functions permit speedbar to display the "tags" in the
3962 ;; current info node.
3963 (eval-when-compile (require 'speedbar))
3965 (defvar Info-speedbar-key-map nil
3966 "Keymap used when in the info display mode.")
3968 (defun Info-install-speedbar-variables ()
3969 "Install those variables used by speedbar to enhance Info."
3970 (if Info-speedbar-key-map
3972 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3974 ;; Basic tree features
3975 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3976 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3977 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3978 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3981 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3982 Info-speedbar-key-map
3983 Info-speedbar-hierarchy-buttons)))
3985 (defvar Info-speedbar-menu-items
3986 '(["Browse Node" speedbar-edit-line t]
3987 ["Expand Node" speedbar-expand-line
3988 (save-excursion (beginning-of-line)
3989 (looking-at "[0-9]+: *.\\+. "))]
3990 ["Contract Node" speedbar-contract-line
3991 (save-excursion (beginning-of-line)
3992 (looking-at "[0-9]+: *.-. "))]
3994 "Additional menu-items to add to speedbar frame.")
3996 ;; Make sure our special speedbar major mode is loaded
3997 (if (featurep 'speedbar)
3998 (Info-install-speedbar-variables)
3999 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4001 ;;; Info hierarchy display method
4003 (defun Info-speedbar-browser ()
4004 "Initialize speedbar to display an info node browser.
4005 This will add a speedbar major display mode."
4008 ;; Make sure that speedbar is active
4009 (speedbar-frame-mode 1)
4010 ;; Now, throw us into Info mode on speedbar.
4011 (speedbar-change-initial-expansion-list "Info")
4014 (eval-when-compile (defvar speedbar-attached-frame))
4016 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4017 "Display an Info directory hierarchy in speedbar.
4018 DIRECTORY is the current directory in the attached frame.
4019 DEPTH is the current indentation depth.
4020 NODE is an optional argument that is used to represent the
4021 specific node to expand."
4023 (save-excursion (goto-char (point-min))
4024 (let ((case-fold-search t))
4025 (looking-at "Info Nodes:"))))
4026 ;; Update our "current node" maybe?
4028 ;; We cannot use the generic list code, that depends on all leaves
4029 ;; being known at creation time.
4031 (speedbar-with-writable (insert "Info Nodes:\n")))
4032 (let ((completions nil)
4033 (cf (selected-frame)))
4034 (select-frame speedbar-attached-frame)
4035 (save-window-excursion
4037 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4040 (speedbar-with-writable
4041 (dolist (completion completions)
4042 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4045 'Info-speedbar-goto-node
4051 (defun Info-speedbar-goto-node (text node indent)
4052 "When user clicks on TEXT, go to an info NODE.
4053 The INDENT level is ignored."
4054 (select-frame speedbar-attached-frame)
4055 (let* ((buff (or (get-buffer "*info*")
4056 (progn (info) (get-buffer "*info*"))))
4057 (bwin (get-buffer-window buff 0)))
4060 (select-window bwin)
4061 (raise-frame (window-frame bwin)))
4062 (if speedbar-power-click
4063 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4064 (select-frame speedbar-attached-frame)
4065 (switch-to-buffer buff)))
4066 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4067 (error "Invalid node %s" node)
4068 (Info-find-node (match-string 1 node) (match-string 2 node))
4069 ;; If we do a find-node, and we were in info mode, restore
4070 ;; the old default method. Once we are in info mode, it makes
4071 ;; sense to return to whatever method the user was using before.
4072 (if (string= speedbar-initial-expansion-list-name "Info")
4073 (speedbar-change-initial-expansion-list
4074 speedbar-previously-used-expansion-list-name)))))
4076 (defun Info-speedbar-expand-node (text token indent)
4077 "Expand the node the user clicked on.
4078 TEXT is the text of the button we clicked on, a + or - item.
4079 TOKEN is data related to this node (NAME . FILE).
4080 INDENT is the current indentation depth."
4081 (cond ((string-match "+" text) ;we have to expand this file
4082 (speedbar-change-expand-button-char ?-)
4083 (if (speedbar-with-writable
4085 (end-of-line) (forward-char 1)
4086 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4087 (speedbar-change-expand-button-char ?-)
4088 (speedbar-change-expand-button-char ??)))
4089 ((string-match "-" text) ;we have to contract this node
4090 (speedbar-change-expand-button-char ?+)
4091 (speedbar-delete-subblock indent))
4092 (t (error "Ooops... not sure what to do")))
4093 (speedbar-center-buffer-smartly))
4095 (defun Info-speedbar-fetch-file-nodes (nodespec)
4096 "Fetch the subnodes from the info NODESPEC.
4097 NODESPEC is a string of the form: (file)node.
4098 Optional THISFILE represends the filename of"
4100 ;; Set up a buffer we can use to fake-out Info.
4101 (set-buffer (get-buffer-create "*info-browse-tmp*"))
4102 (if (not (equal major-mode 'Info-mode))
4104 ;; Get the node into this buffer
4105 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4106 (error "Invalid node specification %s" nodespec)
4107 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4108 ;; Scan the created buffer
4109 (goto-char (point-min))
4110 (let ((completions nil)
4111 (case-fold-search t)
4112 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4113 (match-string 1 nodespec))))
4114 ;; Always skip the first one...
4115 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4116 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4117 (let ((name (match-string 1)))
4119 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4121 (if (looking-at " *\\(([^)]+)\\)\\.")
4122 (concat (match-string 1) "Top")
4123 (concat "(" thisfile ")"
4124 (if (looking-at " \\([^.]+\\).")
4128 (nreverse completions))))
4130 ;;; Info mode node listing
4131 ;; FIXME: Seems not to be used. -stef
4132 (defun Info-speedbar-buttons (buffer)
4133 "Create a speedbar display to help navigation in an Info file.
4134 BUFFER is the buffer speedbar is requesting buttons for."
4135 (if (save-excursion (goto-char (point-min))
4136 (let ((case-fold-search t))
4137 (not (looking-at "Info Nodes:"))))
4139 (Info-speedbar-hierarchy-buttons nil 0)
4142 (dolist (mess '("^First node in file$"
4143 "^No `.*' in index$"
4144 "^No cross-reference named"
4145 "^No cross.references in this node$"
4146 "^No current info node$"
4147 "^No menu in this node$"
4148 "^No more items in menu$"
4150 "^No pointer \\(?:forward\\|backward\\) from this node$"
4151 "^No previous `i' command$"
4152 "^No previous items in menu$"
4153 "^No previous nodes$"
4154 "^No such item in menu$"
4155 "^No such node or anchor"
4157 "^Point neither on reference nor in menu item description$"
4158 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4160 (add-to-list 'debug-ignored-errors mess))
4162 ;;;; Desktop support
4164 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4165 "Auxiliary information to be saved in desktop file."
4166 (if (not (member Info-current-file '("apropos" "history" "toc")))
4167 (list Info-current-file Info-current-node)))
4170 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4172 desktop-buffer-misc)
4173 "Restore an info buffer specified in a desktop file."
4174 (let ((first (nth 0 desktop-buffer-misc))
4175 (second (nth 1 desktop-buffer-misc)))
4176 (when (and first second)
4177 (when desktop-buffer-name
4178 (set-buffer (get-buffer-create desktop-buffer-name))
4180 (Info-find-node first second)
4185 ;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4186 ;;; info.el ends here