1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
4 ;; 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.
32 (eval-when-compile (require 'jka-compr
))
40 (defvar Info-history nil
41 "List of info nodes user has visited.
42 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
44 (defcustom Info-enable-edit nil
45 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
46 This is convenient if you want to write info files by hand.
47 However, we recommend that you not do this.
48 It is better to write a Texinfo file and generate the Info file from that,
49 because that gives you a printed manual as well."
53 (defvar Info-enable-active-nodes nil
54 "Non-nil allows Info to execute Lisp code associated with nodes.
55 The Lisp code is executed when the node is selected.")
56 (put 'Info-enable-active-nodes
'risky-local-variable t
)
59 '((((class color
) (background light
)) (:foreground
"brown" :weight bold
:slant italic
))
60 (((class color
) (background dark
)) (:foreground
"white" :weight bold
:slant italic
))
61 (t (:weight bold
:slant italic
)))
62 "Face for Info node names."
66 '((((class color
)) (:foreground
"red1"))
68 "Face for every third `*' in an Info menu."
72 '((((class color
) (background light
)) (:foreground
"magenta4" :weight bold
))
73 (((class color
) (background dark
)) (:foreground
"cyan" :weight bold
))
75 "Face for Info cross-references."
78 (defcustom Info-fontify-maximum-menu-size
100000
79 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
83 (defcustom Info-use-header-line t
84 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
85 A header-line does not scroll with the rest of the buffer."
89 (defface info-header-xref
90 '((t (:inherit info-xref
)))
91 "Face for Info cross-references in a node header."
94 (defface info-header-node
95 '((t (:inherit info-node
)))
96 "Face for Info nodes in a node header."
99 (defvar Info-directory-list nil
100 "List of directories to search for Info documentation files.
101 If nil, meaning not yet initialized, Info uses the environment
102 variable INFOPATH to initialize it, or `Info-default-directory-list'
103 if there is no INFOPATH variable in the environment.
105 When `Info-directory-list' is initialized from the value of
106 `Info-default-directory-list', and Emacs is installed in one of the
107 standard directories, the directory of Info files that come with Emacs
108 is put last (so that local Info files override standard ones).
110 When `Info-directory-list' is initialized from the value of
111 `Info-default-directory-list', and Emacs is not installed in one
112 of the standard directories, the first element of the resulting
113 list is the directory where Emacs installs the Info files that
114 come with it. This is so that Emacs's own manual, which suits the
115 version of Emacs you are using, will always be found first. This
116 is useful when you install an experimental version of Emacs without
117 removing the standard installation.
119 If you want to override the order of directories in
120 `Info-default-directory-list', set INFOPATH in the environment.
122 If you run the Emacs executable from the `src' directory in the Emacs
123 source tree, and INFOPATH is not defined, the `info' directory in the
124 source tree is used as the first element of `Info-directory-list', in
125 place of the installation Info directory. This is useful when you run
126 a version of Emacs without installing it.")
128 (defcustom Info-additional-directory-list nil
129 "List of additional directories to search for Info documentation files.
130 These directories are searched after those in `Info-directory-list'."
131 :type
'(repeat directory
)
134 (defcustom Info-scroll-prefer-subnodes t
135 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
136 If this is non-nil, and you scroll far enough in a node that its menu
137 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
138 moves to a subnode indicated by the following menu item. This means
139 that you visit a subnode before getting to the end of the menu.
141 Setting this option to nil results in behavior similar to the stand-alone
142 Info reader program, which visits the first subnode from the menu only
143 when you hit the end of the current node."
147 (defcustom Info-hide-note-references t
148 "*If non-nil, hide the tag and section reference in *note and * menu items.
149 Also replaces the \"*note\" text with \"see\".
150 If value is a number, the reference section is still shown."
152 :type
'(choice (const :tag
"Replace tag and hide reference" t
)
153 (const :tag
"Replace only tag" tag
)
154 (const :tag
"No reformatting" nil
))
157 (defcustom Info-mode-hook
'(turn-on-font-lock)
158 "Hooks run when `info-mode' is called."
162 (defvar Info-current-file nil
163 "Info file that Info is now looking at, or nil.
164 This is the name that was specified in Info, not the actual file name.
165 It doesn't contain directory names or file name extensions added by Info.
166 Can also be t when using `Info-on-current-buffer'.")
168 (defvar Info-current-subfile nil
169 "Info subfile that is actually in the *info* buffer now.
170 nil if current info file is not split into subfiles.")
172 (defvar Info-current-node nil
173 "Name of node that Info is now looking at, or nil.")
175 (defvar Info-tag-table-marker nil
176 "Marker pointing at beginning of current Info file's tag table.
177 Marker points nowhere if file has no tag table.")
179 (defvar Info-tag-table-buffer nil
180 "Buffer used for indirect tag tables.")
182 (defvar Info-current-file-completions nil
183 "Cached completion list for current Info file.")
185 (defvar Info-index-alternatives nil
186 "List of possible matches for last `Info-index' command.")
188 (defvar Info-standalone nil
189 "Non-nil if Emacs was started solely as an Info browser.")
191 (defvar Info-suffix-list
192 ;; The MS-DOS list should work both when long file names are
193 ;; supported (Windows 9X), and when only 8+3 file names are available.
194 (if (eq system-type
'ms-dos
)
195 '( (".gz" .
"gunzip")
197 (".bz2" .
("bzip2" "-dc"))
200 (".info.Z" .
"gunzip")
201 (".info.gz" .
"gunzip")
202 ("-info.Z" .
"gunzip")
203 ("-info.gz" .
"gunzip")
204 ("/index.gz".
"gunzip")
205 ("/index.z" .
"gunzip")
211 '( (".info.Z".
"uncompress")
212 (".info.Y".
"unyabba")
213 (".info.gz".
"gunzip")
214 (".info.z".
"gunzip")
215 (".info.bz2" .
("bzip2" "-dc"))
217 ("-info.Z".
"uncompress")
218 ("-info.Y".
"unyabba")
219 ("-info.gz".
"gunzip")
220 ("-info.bz2" .
("bzip2" "-dc"))
221 ("-info.z".
"gunzip")
223 ("/index.Z".
"uncompress")
224 ("/index.Y".
"unyabba")
225 ("/index.gz".
"gunzip")
226 ("/index.z".
"gunzip")
227 ("/index.bz2".
("bzip2" "-dc"))
233 (".bz2" .
("bzip2" "-dc"))
235 "List of file name suffixes and associated decoding commands.
236 Each entry should be (SUFFIX . STRING); the file is given to
237 the command as standard input.
239 STRING may be a list of strings. In that case, the first element is
240 the command name, and the rest are arguments to that command.
242 If STRING is nil, no decoding is done.
243 Because the SUFFIXes are tried in order, the empty string should
244 be last in the list.")
246 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
247 ;; First, on MS-DOS with no long file names support, delete some of
248 ;; the extension in FILENAME to make room.
249 (defun info-insert-file-contents-1 (filename suffix lfn
)
250 (if lfn
; long file names are supported
251 (concat filename suffix
)
252 (let* ((sans-exts (file-name-sans-extension filename
))
253 ;; How long is the extension in FILENAME (not counting the dot).
254 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
256 ;; SUFFIX starts with a dot. If FILENAME already has one,
257 ;; get rid of the one in SUFFIX (unless suffix is empty).
258 (or (and (<= ext-len
0)
259 (not (eq (aref filename
(1- (length filename
))) ?.
)))
260 (= (length suffix
) 0)
261 (setq suffix
(substring suffix
1)))
262 ;; How many chars of that extension should we keep?
263 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
264 ;; Get rid of the rest of the extension, and add SUFFIX.
265 (concat (substring filename
0 (- (length filename
)
266 (- ext-len ext-left
)))
269 (defun info-file-exists-p (filename)
270 (and (file-exists-p filename
)
271 (not (file-directory-p filename
))))
273 (defun info-insert-file-contents (filename &optional visit
)
274 "Insert the contents of an info file in the current buffer.
275 Do the right thing if the file has been compressed or zipped."
276 (let* ((tail Info-suffix-list
)
277 (lfn (or (not (fboundp 'msdos-long-file-names
))
278 (msdos-long-file-names)))
279 (check-short (and (fboundp 'msdos-long-file-names
)
281 fullname decoder done
)
282 (if (info-file-exists-p filename
)
283 ;; FILENAME exists--see if that name contains a suffix.
284 ;; If so, set DECODE accordingly.
288 (concat (regexp-quote (car (car tail
))) "$")
290 (setq tail
(cdr tail
)))
291 (setq fullname filename
292 decoder
(cdr (car tail
))))
293 ;; Try adding suffixes to FILENAME and see if we can find something.
294 (while (and tail
(not done
))
295 (setq fullname
(info-insert-file-contents-1 filename
296 (car (car tail
)) lfn
))
297 (if (info-file-exists-p fullname
)
299 ;; If we found a file with a suffix, set DECODER
300 ;; according to the suffix.
301 decoder
(cdr (car tail
)))
302 ;; When the MS-DOS port runs on Windows, we need to check
303 ;; the short variant of a long file name as well.
305 (setq fullname
(info-insert-file-contents-1 filename
306 (car (car tail
)) nil
))
307 (if (info-file-exists-p fullname
)
309 decoder
(cdr (car tail
))))))
310 (setq tail
(cdr tail
)))
312 (error "Can't find %s or any compressed version of it" filename
)))
313 ;; check for conflict with jka-compr
314 (if (and (featurep 'jka-compr
)
315 (jka-compr-installed-p)
316 (jka-compr-get-compression-info fullname
))
320 (insert-file-contents-literally fullname visit
)
321 (let ((buffer-read-only nil
)
322 (coding-system-for-write 'no-conversion
)
323 (default-directory (or (file-name-directory fullname
)
326 (setq decoder
(list decoder
)))
327 (apply 'call-process-region
(point-min) (point-max)
328 (car decoder
) t t nil
(cdr decoder
))))
329 (insert-file-contents fullname visit
))))
331 (defun info-initialize ()
332 "Initialize `Info-directory-list', if that hasn't been done yet."
333 (unless Info-directory-list
334 (let ((path (getenv "INFOPATH"))
335 (source (expand-file-name "info/" source-directory
))
336 (sibling (if installation-directory
337 (expand-file-name "info/" installation-directory
)
338 (if invocation-directory
339 (let ((infodir (expand-file-name
341 invocation-directory
)))
342 (if (file-exists-p infodir
)
344 (setq infodir
(expand-file-name
346 invocation-directory
))
347 (and (file-exists-p infodir
)
350 (setq Info-directory-list
351 (prune-directory-list
353 (split-string path
(regexp-quote path-separator
))
354 (if (and sibling
(file-exists-p sibling
))
355 ;; Uninstalled, Emacs builddir != srcdir.
356 (setq alternative sibling
)
357 ;; Uninstalled, builddir == srcdir
358 (setq alternative source
))
359 (if (or (member alternative Info-default-directory-list
)
360 ;; On DOS/NT, we use movable executables always,
361 ;; and we must always find the Info dir at run time.
362 (if (memq system-type
'(ms-dos windows-nt
))
364 ;; Use invocation-directory for Info
365 ;; only if we used it for exec-directory also.
366 (not (string= exec-directory
367 (expand-file-name "lib-src/"
368 installation-directory
))))
369 (not (file-exists-p alternative
)))
370 Info-default-directory-list
371 ;; `alternative' contains the Info files that came with this
372 ;; version, so we should look there first. `Info-insert-dir'
373 ;; currently expects to find `alternative' first on the list.
375 (reverse (cdr (reverse Info-default-directory-list
)))))))))))
378 (defun info-other-window (&optional file
)
379 "Like `info' but show the Info buffer in another window."
380 (interactive (if current-prefix-arg
381 (list (read-file-name "Info file name: " nil nil t
))))
382 (let (same-window-buffer-names)
385 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
388 (defun info (&optional file
)
389 "Enter Info, the documentation browser.
390 Optional argument FILE specifies the file to examine;
391 the default is the top-level directory of Info.
392 Called from a program, FILE may specify an Info node of the form
393 `(FILENAME)NODENAME'.
395 In interactive use, a prefix argument directs this command
396 to read a file name from the minibuffer.
398 The search path for Info files is in the variable `Info-directory-list'.
399 The top-level Info directory is made by combining all the files named `dir'
400 in all the directories in that path."
401 (interactive (if current-prefix-arg
402 (list (read-file-name "Info file name: " nil nil t
))))
405 (pop-to-buffer "*info*")
406 ;; If argument already contains parentheses, don't add another set
407 ;; since the argument will then be parsed improperly. This also
408 ;; has the added benefit of allowing node names to be included
409 ;; following the parenthesized filename.
410 (if (and (stringp file
) (string-match "(.*)" file
))
411 (Info-goto-node file
)
412 (Info-goto-node (concat "(" file
")"))))
413 (if (get-buffer "*info*")
414 (pop-to-buffer "*info*")
418 (defun info-emacs-manual ()
419 "Display the Emacs manual in Info mode."
424 (defun info-standalone ()
425 "Run Emacs as a standalone Info reader.
426 Usage: emacs -f info-standalone [filename]
427 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
428 (setq Info-standalone t
)
429 (if (and command-line-args-left
430 (not (string-match "^-" (car command-line-args-left
))))
433 (info (car command-line-args-left
))
434 (setq command-line-args-left
(cdr command-line-args-left
)))
435 (error (send-string-to-terminal
436 (format "%s\n" (if (eq (car-safe err
) 'error
)
438 (save-buffers-kill-emacs)))
441 ;; See if the accessible portion of the buffer begins with a node
442 ;; delimiter, and the node header line which follows matches REGEXP.
443 ;; Typically, this test will be followed by a loop that examines the
444 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
445 ;; to have the overhead of this special test inside the loop.
447 ;; This function changes match-data, but supposedly the caller might
448 ;; want to use the results of re-search-backward.
450 ;; The return value is the value of point at the beginning of matching
451 ;; REGEXP, if the function succeeds, nil otherwise.
452 (defun Info-node-at-bob-matching (regexp)
453 (and (bobp) ; are we at beginning of buffer?
454 (looking-at "\^_") ; does it begin with node delimiter?
458 (forward-line 1) ; does the line after delimiter match REGEXP?
459 (re-search-backward regexp beg t
))))
461 (defun Info-find-node (filename nodename
&optional no-going-back
)
462 "Go to an info node specified as separate FILENAME and NODENAME.
463 NO-GOING-BACK is non-nil if recovering from an error in this function;
464 it says do not attempt further (recursive) error recovery."
466 ;; Convert filename to lower case if not found as specified.
468 (if (stringp filename
)
469 (let (temp temp-downcase found
)
470 (setq filename
(substitute-in-file-name filename
))
471 (if (string= (downcase filename
) "dir")
473 (let ((dirs (if (string-match "^\\./" filename
)
474 ;; If specified name starts with `./'
475 ;; then just try current directory.
477 (if (file-name-absolute-p filename
)
478 ;; No point in searching for an
479 ;; absolute file name
481 (if Info-additional-directory-list
482 (append Info-directory-list
483 Info-additional-directory-list
)
484 Info-directory-list
)))))
485 ;; Search the directory list for file FILENAME.
486 (while (and dirs
(not found
))
487 (setq temp
(expand-file-name filename
(car dirs
)))
489 (expand-file-name (downcase filename
) (car dirs
)))
490 ;; Try several variants of specified name.
491 (let ((suffix-list Info-suffix-list
)
492 (lfn (or (not (fboundp 'msdos-long-file-names
))
493 (msdos-long-file-names))))
494 (while (and suffix-list
(not found
))
495 (cond ((info-file-exists-p
496 (info-insert-file-contents-1
497 temp
(car (car suffix-list
)) lfn
))
500 (info-insert-file-contents-1
501 temp-downcase
(car (car suffix-list
)) lfn
))
502 (setq found temp-downcase
))
503 ((and (fboundp 'msdos-long-file-names
)
506 (info-insert-file-contents-1
507 temp
(car (car suffix-list
)) nil
)))
509 (setq suffix-list
(cdr suffix-list
))))
510 (setq dirs
(cdr dirs
)))))
512 (setq filename found
)
513 (error "Info file %s does not exist" filename
))))
514 ;; Record the node we are leaving.
515 (if (and Info-current-file
(not no-going-back
))
517 (cons (list Info-current-file Info-current-node
(point))
519 ;; Go into info buffer.
520 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
521 (Info-find-node-2 filename nodename no-going-back
))
523 (defun Info-on-current-buffer (&optional nodename
)
524 "Use the `Info-mode' to browse the current info buffer.
525 If a prefix arg is provided, it queries for the NODENAME which
526 else defaults to \"Top\"."
528 (list (if current-prefix-arg
529 (completing-read "Node name: " (Info-build-node-completions)
531 (unless nodename
(setq nodename
"Top"))
534 (set (make-local-variable 'Info-current-file
) t
)
535 (Info-find-node-2 nil nodename
))
537 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
538 ;; but at least it keeps this routine (which is only for the benefit of
539 ;; makeinfo-buffer) out of the way of normal operations.
541 (defun Info-revert-find-node (filename nodename
)
542 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
543 When *info* is already displaying FILENAME and NODENAME, the window position
544 is preserved, if possible."
545 (pop-to-buffer "*info*")
546 (let ((old-filename Info-current-file
)
547 (old-nodename Info-current-node
)
548 (pcolumn (current-column))
549 (pline (count-lines (point-min) (line-beginning-position)))
550 (wline (count-lines (point-min) (window-start)))
551 (old-history Info-history
)
552 (new-history (and Info-current-file
553 (list Info-current-file Info-current-node
(point)))))
554 (kill-buffer (current-buffer))
555 (Info-find-node filename nodename
)
556 (setq Info-history old-history
)
557 (if (and (equal old-filename Info-current-file
)
558 (equal old-nodename Info-current-node
))
560 ;; note goto-line is no good, we want to measure from point-min
561 (beginning-of-buffer)
563 (set-window-start (selected-window) (point))
564 (beginning-of-buffer)
566 (move-to-column pcolumn
))
567 ;; only add to the history when coming from a different file+node
569 (setq Info-history
(cons new-history Info-history
))))))
571 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
572 "Find a node in a tag table.
573 MARKER specifies the buffer and position to start searching at.
574 REGEXP is a regular expression matching nodes or references. Its first
575 group should match `Node:' or `Ref:'.
576 CASE-FOLD t means search for a case-insensitive match.
577 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
578 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
579 where the match was found, and MODE is `major-mode' of the buffer in
580 which the match was found."
581 (let ((case-fold-search case-fold
)
582 found-mode guesspos found-anchor
)
584 (set-buffer (marker-buffer marker
))
589 (when (re-search-forward regexp nil t
)
590 (list (string-equal "Ref:" (match-string 1))
591 (+ (point-min) (read (current-buffer)))
594 (defun Info-find-in-tag-table (marker regexp
)
595 "Find a node in a tag table.
596 MARKER specifies the buffer and position to start searching at.
597 REGEXP is a regular expression matching nodes or references. Its first
598 group should match `Node:' or `Ref:'.
599 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
600 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
601 where the match was found, and MODE is `major-mode' of the buffer in
602 which the match was found.
603 This function tries to find a case-sensitive match first, then a
604 case-insensitive match is tried."
605 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
606 (when (null (car result
))
607 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
610 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
611 "Find a node or anchor in the current buffer.
612 REGEXP is a regular expression matching nodes or references. Its first
613 group should match `Node:' or `Ref:'.
614 CASE-FOLD t means search for a case-insensitive match.
615 Value is the position at which a match was found, or nil if not found."
616 (let ((case-fold-search case-fold
)
619 (when (Info-node-at-bob-matching regexp
)
620 (setq found
(point)))
621 (while (and (not found
)
622 (search-forward "\n\^_" nil t
))
626 (when (re-search-backward regexp beg t
)
628 (setq found
(point)))))
631 (defun Info-find-node-in-buffer (regexp)
632 "Find a node or anchor in the current buffer.
633 REGEXP is a regular expression matching nodes or references. Its first
634 group should match `Node:' or `Ref:'.
635 Value is the position at which a match was found, or nil if not found.
636 This function looks for a case-sensitive match first. If none is found,
637 a case-insensitive match is tried."
638 (or (Info-find-node-in-buffer-1 regexp nil
)
639 (Info-find-node-in-buffer-1 regexp t
)))
641 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
642 (buffer-disable-undo (current-buffer))
643 (or (eq major-mode
'Info-mode
)
646 (setq Info-current-node nil
)
648 (let ((case-fold-search t
)
650 ;; Switch files if necessary
652 (equal Info-current-file filename
)
653 (let ((buffer-read-only nil
))
654 (setq Info-current-file nil
655 Info-current-subfile nil
656 Info-current-file-completions nil
657 buffer-file-name nil
)
661 (info-insert-file-contents filename nil
)
662 (setq default-directory
(file-name-directory filename
)))
663 (set-buffer-modified-p nil
)
664 ;; See whether file has a tag table. Record the location if yes.
665 (goto-char (point-max))
667 ;; Use string-equal, not equal, to ignore text props.
668 (if (not (or (string-equal nodename
"*")
670 (search-forward "\^_\nEnd tag table\n" nil t
))))
672 ;; We have a tag table. Find its beginning.
673 ;; Is this an indirect file?
674 (search-backward "\nTag table:\n")
678 (looking-at "(Indirect)\n"))
679 ;; It is indirect. Copy it to another buffer
680 ;; and record that the tag table is in that buffer.
681 (let ((buf (current-buffer))
683 (or Info-tag-table-buffer
684 (generate-new-buffer " *info tag table*"))))
685 (setq Info-tag-table-buffer tagbuf
)
688 (buffer-disable-undo (current-buffer))
689 (setq case-fold-search t
)
691 (insert-buffer-substring buf
))
692 (set-marker Info-tag-table-marker
693 (match-end 0) tagbuf
))
694 (set-marker Info-tag-table-marker pos
)))
695 (set-marker Info-tag-table-marker nil
))
696 (setq Info-current-file
697 (if (eq filename t
) "dir" filename
))))
698 ;; Use string-equal, not equal, to ignore text props.
699 (if (string-equal nodename
"*")
700 (progn (setq Info-current-node nodename
)
701 (Info-set-mode-line))
704 ;; 1. Anchor found in tag table
705 ;; 2. Anchor *not* in tag table
707 ;; 3. Node found in tag table
708 ;; 4. Node *not* found in tag table, but found in file
709 ;; 5. Node *not* in tag table, and *not* in file
711 ;; *Or* the same, but in an indirect subfile.
713 ;; Search file for a suitable node.
714 (let ((guesspos (point-min))
715 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
716 (if (stringp nodename
)
717 (regexp-quote nodename
)
724 ;; First, search a tag table, if any
725 (when (marker-position Info-tag-table-marker
)
726 (let* ((m Info-tag-table-marker
)
727 (found (Info-find-in-tag-table m regexp
)))
730 ;; FOUND is (ANCHOR POS MODE).
731 (setq guesspos
(nth 1 found
))
733 ;; If this is an indirect file, determine which
734 ;; file really holds this node and read it in.
735 (unless (eq (nth 2 found
) 'Info-mode
)
736 ;; Note that the current buffer must be the
737 ;; *info* buffer on entry to
738 ;; Info-read-subfile. Thus the hackery above.
739 (setq guesspos
(Info-read-subfile guesspos
)))
743 (goto-char (setq anchorpos guesspos
))
746 ;; Else we may have a node, which we search for:
747 (goto-char (max (point-min)
748 (- (byte-to-position guesspos
) 1000)))
750 ;; Now search from our advised position (or from beg of
751 ;; buffer) to find the actual node. First, check
752 ;; whether the node is right where we are, in case the
753 ;; buffer begins with a node.
754 (let ((pos (Info-find-node-in-buffer regexp
)))
758 (error "No such anchor in tag table or node in tag table or file: %s"
762 (goto-char (or anchorpos
(point-min))))))
763 ;; If we did not finish finding the specified node,
764 ;; go back to the previous one.
765 (or Info-current-node no-going-back
(null Info-history
)
766 (let ((hist (car Info-history
)))
767 (setq Info-history
(cdr Info-history
))
768 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
769 (goto-char (nth 2 hist
))))))
771 ;; Cache the contents of the (virtual) dir file, once we have merged
772 ;; it for the first time, so we can save time subsequently.
773 (defvar Info-dir-contents nil
)
775 ;; Cache for the directory we decided to use for the default-directory
776 ;; of the merged dir text.
777 (defvar Info-dir-contents-directory nil
)
779 ;; Record the file attributes of all the files from which we
780 ;; constructed Info-dir-contents.
781 (defvar Info-dir-file-attributes nil
)
783 (defvar Info-dir-file-name nil
)
785 ;; Construct the Info directory node by merging the files named `dir'
786 ;; from various directories. Set the *info* buffer's
787 ;; default-directory to the first directory we actually get any text
789 (defun Info-insert-dir ()
790 (if (and Info-dir-contents Info-dir-file-attributes
791 ;; Verify that none of the files we used has changed
794 (mapcar (lambda (elt)
795 (let ((curr (file-attributes
797 (file-truename (car elt
)))))
799 ;; Don't compare the access time.
800 (if curr
(setcar (nthcdr 4 curr
) 0))
801 (setcar (nthcdr 4 (cdr elt
)) 0)
802 (equal (cdr elt
) curr
)))
803 Info-dir-file-attributes
))))
805 (insert Info-dir-contents
)
806 (goto-char (point-min)))
807 (let ((dirs (if Info-additional-directory-list
808 (append Info-directory-list
809 Info-additional-directory-list
)
810 Info-directory-list
))
812 ;; Bind this in case the user sets it to nil.
814 ;; This is set non-nil if we find a problem in some input files.
816 buffers buffer others nodes dirs-done
)
818 ;; Search the directory list for the directory file.
820 (let ((truename (file-truename (expand-file-name (car dirs
)))))
821 (or (member truename dirs-done
)
822 (member (directory-file-name truename
) dirs-done
)
823 ;; Try several variants of specified name.
824 ;; Try upcasing, appending `.info', or both.
828 (progn (setq file
(expand-file-name "dir" truename
))
829 (file-attributes file
))
830 (progn (setq file
(expand-file-name "DIR" truename
))
831 (file-attributes file
))
832 (progn (setq file
(expand-file-name "dir.info" truename
))
833 (file-attributes file
))
834 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
835 (file-attributes file
)))))
838 (cons (directory-file-name truename
)
843 (message "Composing main Info directory..."))
844 (set-buffer (generate-new-buffer " info dir"))
847 (insert-file-contents file
)
848 (set (make-local-variable 'Info-dir-file-name
)
850 (push (current-buffer) buffers
)
851 (push (cons file attrs
) dir-file-attrs
))
852 (error (kill-buffer (current-buffer))))))))
854 (set (make-local-variable 'Info-dir-contents-directory
)
855 (file-name-as-directory (car dirs
))))
856 (setq dirs
(cdr dirs
))))
859 (error "Can't find the Info directory node"))
861 ;; Distinguish the dir file that comes with Emacs from all the
862 ;; others. Yes, that is really what this is supposed to do.
863 ;; The definition of `Info-directory-list' puts it first on that
864 ;; list and so last in `buffers' at this point.
865 (setq buffer
(car (last buffers
))
866 others
(delq buffer buffers
))
868 ;; Insert the entire original dir file as a start; note that we've
869 ;; already saved its default directory to use as the default
870 ;; directory for the whole concatenation.
871 (insert-buffer buffer
)
873 ;; Look at each of the other buffers one by one.
874 (dolist (other others
)
875 (let (this-buffer-nodes)
876 ;; In each, find all the menus.
877 (with-current-buffer other
878 (goto-char (point-min))
879 ;; Find each menu, and add an elt to NODES for it.
880 (while (re-search-forward "^\\* Menu:" nil t
)
881 (while (and (zerop (forward-line 1)) (eolp)))
884 (re-search-backward "^\^_")
885 (search-forward "Node: ")
886 (setq nodename
(Info-following-node-name))
887 (search-forward "\n\^_" nil
'move
)
890 (push (list nodename other beg end
) this-buffer-nodes
)))
891 (if (assoc-ignore-case "top" this-buffer-nodes
)
892 (setq nodes
(nconc this-buffer-nodes nodes
))
894 (message "No `top' node in %s" Info-dir-file-name
)))))
895 ;; Add to the main menu a menu item for each other node.
896 (re-search-forward "^\\* Menu:")
898 (let ((menu-items '("top"))
899 (end (save-excursion (search-forward "\^_" nil t
) (point))))
901 (let ((nodename (car node
)))
903 (or (member (downcase nodename
) menu-items
)
904 (re-search-forward (concat "^\\* +"
905 (regexp-quote nodename
)
909 (insert "* " nodename
"::" "\n")
910 (push nodename menu-items
)))))))
911 ;; Now take each node of each of the other buffers
912 ;; and merge it into the main buffer.
914 (let ((case-fold-search t
)
915 (nodename (car node
)))
916 (goto-char (point-min))
917 ;; Find the like-named node in the main buffer.
918 (if (re-search-forward (concat "^\^_.*\n.*Node: "
919 (regexp-quote nodename
)
923 (search-forward "\n\^_" nil
'move
)
926 ;; If none exists, add one.
927 (goto-char (point-max))
928 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
929 ;; Merge the text from the other buffer's menu
930 ;; into the menu in the like-named node in the main buffer.
931 (apply 'insert-buffer-substring
(cdr node
))))
932 (Info-dir-remove-duplicates)
933 ;; Kill all the buffers we just made.
934 (mapc 'kill-buffer buffers
)
935 (goto-char (point-min))
937 (message "Composing main Info directory...problems encountered, see `*Messages*'")
938 (message "Composing main Info directory...done"))
939 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
940 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
941 (setq default-directory Info-dir-contents-directory
))
943 (defvar Info-streamline-headings
944 '(("Emacs" .
"Emacs")
945 ("Programming" .
"Programming")
946 ("Libraries" .
"Libraries")
947 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
948 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
950 (defun Info-dir-remove-duplicates ()
952 (goto-char (point-min))
953 ;; Remove duplicate headings in the same menu.
954 (while (search-forward "\n* Menu:" nil t
)
955 (setq limit
(save-excursion (search-forward "\n\x1f" nil t
)))
956 ;; Look for the next heading to unify.
957 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
958 (let ((name (match-string 1))
959 (start (match-beginning 0))
961 ;; Check whether this heading should be streamlined.
963 (dolist (x Info-streamline-headings
)
964 (when (string-match (car x
) name
)
967 (if re
(replace-match name t t nil
1))
968 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
970 (or limit
(point-max))))
971 ;; Look for other headings of the same category and merge them.
973 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
974 (when (if re
(save-match-data (string-match re
(match-string 1)))
975 (equal name
(match-string 1)))
977 ;; Delete redundant heading.
978 (delete-region (match-beginning 0) (point))
979 ;; Push the entries onto `text'.
981 (delete-and-extract-region
983 (if (re-search-forward "^[^* \n\t]" nil t
)
985 (or limit
(point-max)))) entries
))))
986 ;; Insert the entries just found.
987 (while (= (line-beginning-position 0) (1- (point)))
989 (dolist (entry (nreverse entries
))
991 (while (= (line-beginning-position 0) (1- (point)))
992 (delete-region (1- (point)) (point))))
994 ;; Now remove duplicate entries under the same heading.
998 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1000 (let ((x (match-string 1)))
1001 (if (member-ignore-case x seen
)
1002 (delete-region (match-beginning 0)
1003 (progn (re-search-forward "^[^ \t]" nil t
)
1004 (match-beginning 0)))
1005 (push x seen
))))))))))
1007 ;; Note that on entry to this function the current-buffer must be the
1008 ;; *info* buffer; not the info tags buffer.
1009 (defun Info-read-subfile (nodepos)
1010 ;; NODEPOS is either a position (in the Info file as a whole,
1011 ;; not relative to a subfile) or the name of a subfile.
1014 (if (numberp nodepos
)
1016 (set-buffer (marker-buffer Info-tag-table-marker
))
1017 (goto-char (point-min))
1018 (or (looking-at "\^_")
1019 (search-forward "\n\^_"))
1022 (while (not (looking-at "\^_"))
1025 thisfilepos thisfilename
)
1026 (search-forward ": ")
1027 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1028 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1029 ;; read in version 19 stops at the end of number.
1030 ;; Advance to the next line.
1032 (if (> thisfilepos nodepos
)
1034 (setq lastfilename thisfilename
)
1035 (setq lastfilepos thisfilepos
))
1036 (forward-line 1)))))
1037 (setq lastfilename nodepos
)
1038 (setq lastfilepos
0))
1039 ;; Assume previous buffer is in Info-mode.
1040 ;; (set-buffer (get-buffer "*info*"))
1041 (or (equal Info-current-subfile lastfilename
)
1042 (let ((buffer-read-only nil
))
1043 (setq buffer-file-name nil
)
1046 (info-insert-file-contents lastfilename
)
1047 (set-buffer-modified-p nil
)
1048 (setq Info-current-subfile lastfilename
)))
1049 ;; Widen in case we are in the same subfile as before.
1051 (goto-char (point-min))
1052 (if (looking-at "\^_")
1054 (search-forward "\n\^_"))
1055 (if (numberp nodepos
)
1056 (+ (- nodepos lastfilepos
) (point)))))
1058 (defvar Info-header-line nil
1059 "If the info node header is hidden, the text of the header.")
1060 (put 'Info-header-line
'risky-local-variable t
)
1062 (defun Info-select-node ()
1063 "Select the info node that point is in.
1064 Bind this in case the user sets it to nil."
1065 (let ((case-fold-search t
))
1067 ;; Find beginning of node.
1068 (if (search-backward "\n\^_" nil
'move
)
1070 (if (looking-at "\^_")
1072 (signal 'search-failed
(list "\n\^_"))))
1073 ;; Get nodename spelled as it is in the node.
1074 (re-search-forward "Node:[ \t]*")
1075 (setq Info-current-node
1076 (buffer-substring-no-properties (point)
1078 (skip-chars-forward "^,\t\n")
1080 (Info-set-mode-line)
1081 ;; Find the end of it, and narrow.
1083 (let (active-expression)
1084 ;; Narrow to the node contents
1085 (narrow-to-region (point)
1086 (if (re-search-forward "\n[\^_\f]" nil t
)
1089 (if (looking-at "[\n\^_\f]*execute: ")
1091 (goto-char (match-end 0))
1092 (setq active-expression
1093 (read (current-buffer))))))
1095 (if Info-enable-active-nodes
(eval active-expression
))
1097 (setq Info-header-line
(get-text-property (point-min) 'header-line
))
1098 (run-hooks 'Info-selection-hook
)))))
1100 (defun Info-set-mode-line ()
1101 (setq mode-line-buffer-identification
1102 (nconc (propertized-buffer-identification "%b")
1105 (file-name-nondirectory
1106 (if (stringp Info-current-file
)
1108 (or buffer-file-name
"")))
1110 (or Info-current-node
""))))))
1112 ;; Go to an info node specified with a filename-and-nodename string
1113 ;; of the sort that is found in pointers in nodes.
1115 (defun Info-goto-node (nodename &optional fork
)
1116 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1117 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1118 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1120 Completion is available, but only for node names in the current Info file.
1121 If FORK is non-nil (interactively with a prefix arg), show the node in
1123 If FORK is a string, it is the name to use for the new buffer."
1124 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1128 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1130 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1132 (setq filename
(if (= (match-beginning 1) (match-end 1))
1134 (substring nodename
(match-beginning 2) (match-end 2)))
1135 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
1136 (let ((trim (string-match "\\s *\\'" filename
)))
1137 (if trim
(setq filename
(substring filename
0 trim
))))
1138 (let ((trim (string-match "\\s *\\'" nodename
)))
1139 (if trim
(setq nodename
(substring nodename
0 trim
))))
1140 (if transient-mark-mode
(deactivate-mark))
1141 (Info-find-node (if (equal filename
"") nil filename
)
1142 (if (equal nodename
"") "Top" nodename
))))
1144 (defvar Info-read-node-completion-table
)
1146 ;; This function is used as the "completion table" while reading a node name.
1147 ;; It does completion using the alist in Info-read-node-completion-table
1148 ;; unless STRING starts with an open-paren.
1149 (defun Info-read-node-name-1 (string predicate code
)
1151 ;; First complete embedded file names.
1152 ((string-match "\\`([^)]*\\'" string
)
1153 (let ((file (substring string
1)))
1156 (let ((comp (try-completion file
'locate-file-completion
1157 (cons Info-directory-list
1158 (mapcar 'car Info-suffix-list
)))))
1160 ((eq comp t
) (concat string
")"))
1161 (comp (concat "(" comp
)))))
1162 ((eq code t
) (all-completions file
'locate-file-completion
1163 (cons Info-directory-list
1164 (mapcar 'car Info-suffix-list
))))
1166 ;; If a file name was given, then any node is fair game.
1167 ((string-match "\\`(" string
)
1169 ((eq code nil
) string
)
1172 ;; Otherwise use Info-read-node-completion-table.
1174 (try-completion string Info-read-node-completion-table predicate
))
1176 (all-completions string Info-read-node-completion-table predicate
))
1178 (test-completion string Info-read-node-completion-table predicate
))))
1180 (defun Info-read-node-name (prompt &optional default
)
1181 (let* ((completion-ignore-case t
)
1182 (Info-read-node-completion-table (Info-build-node-completions))
1183 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1184 (if (equal nodename
"")
1186 (Info-read-node-name prompt
))
1189 (defun Info-build-node-completions ()
1190 (or Info-current-file-completions
1192 ;; Bind this in case the user sets it to nil.
1193 (case-fold-search t
)
1194 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1197 (if (marker-buffer Info-tag-table-marker
)
1198 (let ((marker Info-tag-table-marker
))
1199 (set-buffer (marker-buffer marker
))
1202 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1204 (cons (list (match-string-no-properties 2))
1207 (goto-char (point-min))
1208 ;; If the buffer begins with a node header, process that first.
1209 (if (Info-node-at-bob-matching node-regexp
)
1210 (setq compl
(list (match-string-no-properties 1))))
1211 ;; Now for the rest of the nodes.
1212 (while (search-forward "\n\^_" nil t
)
1214 (let ((beg (point)))
1216 (if (re-search-backward node-regexp beg t
)
1218 (cons (list (match-string-no-properties 1))
1220 (setq compl
(cons '("*") compl
))
1221 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1223 (defun Info-restore-point (hl)
1224 "If this node has been visited, restore the point value when we left."
1226 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1227 ;; Use string-equal, not equal, to ignore text props.
1228 (string-equal (nth 1 (car hl
)) Info-current-node
))
1230 (goto-char (nth 2 (car hl
)))
1231 (setq hl nil
)) ;terminate the while at next iter
1232 (setq hl
(cdr hl
)))))
1234 (defvar Info-search-history nil
1235 "The history list for `Info-search'.")
1237 (defun Info-search (regexp)
1238 "Search for REGEXP, starting from point, and select node it's found in."
1239 (interactive (list (read-string
1240 (if Info-search-history
1241 (format "Regexp search (default `%s'): "
1242 (car Info-search-history
))
1244 nil
'Info-search-history
)))
1245 (when transient-mark-mode
1247 (when (equal regexp
"")
1248 (setq regexp
(car Info-search-history
)))
1250 (let ((found ()) current
1251 (onode Info-current-node
)
1252 (ofile Info-current-file
)
1254 (ostart (window-start))
1255 (osubfile Info-current-subfile
))
1259 (if (null Info-current-subfile
)
1260 (progn (re-search-forward regexp
) (setq found
(point)))
1262 (progn (re-search-forward regexp
) (setq found
(point)))
1263 (search-failed nil
)))))
1264 (if (not found
) ;can only happen in subfile case -- else would have erred
1268 (set-buffer (marker-buffer Info-tag-table-marker
))
1269 (goto-char (point-min))
1270 (search-forward "\n\^_\nIndirect:")
1272 (narrow-to-region (point)
1273 (progn (search-forward "\n\^_")
1275 (goto-char (point-min))
1276 ;; Find the subfile we just searched.
1277 (search-forward (concat "\n" osubfile
": "))
1280 ;; Make a list of all following subfiles.
1281 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1283 (re-search-forward "\\(^.*\\): [0-9]+$")
1284 (goto-char (+ (match-end 1) 2))
1285 (setq list
(cons (cons (+ (point-min)
1286 (read (current-buffer)))
1287 (match-string-no-properties 1))
1289 (goto-char (1+ (match-end 0))))
1290 ;; Put in forward order
1291 (setq list
(nreverse list
))))
1293 (message "Searching subfile %s..." (cdr (car list
)))
1294 (Info-read-subfile (car (car list
)))
1295 (setq list
(cdr list
))
1296 (if (re-search-forward regexp nil t
)
1297 (setq found
(point) list
())))
1300 (signal 'search-failed
(list regexp
))))
1302 (progn (Info-read-subfile osubfile
)
1305 (set-window-start (selected-window) ostart
)))))
1309 ;; Use string-equal, not equal, to ignore text props.
1310 (or (and (string-equal onode Info-current-node
)
1311 (equal ofile Info-current-file
))
1312 (setq Info-history
(cons (list ofile onode opoint
)
1315 (defun Info-extract-pointer (name &optional errorname
)
1316 "Extract the value of the node-pointer named NAME.
1317 If there is none, use ERRORNAME in the error message;
1318 if ERRORNAME is nil, just return nil.
1319 Bind this in case the user sets it to nil."
1320 (let ((case-fold-search t
))
1323 (goto-char (point-min))
1324 (let ((bound (point)))
1326 (cond ((re-search-backward (concat name
":") bound t
)
1327 (goto-char (match-end 0))
1328 (Info-following-node-name))
1329 ((not (eq errorname t
))
1330 (error "Node has no %s"
1331 (capitalize (or errorname name
))))))))))
1333 (defun Info-following-node-name (&optional allowedchars
)
1334 "Return the node name in the buffer following point.
1335 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1336 saying which chars may appear in the node name."
1337 (skip-chars-forward " \t")
1338 (buffer-substring-no-properties
1341 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
1342 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
1343 (if (looking-at "(")
1344 (skip-chars-forward "^)")))
1345 (skip-chars-backward " ")
1349 "Go to the next node of this node."
1351 (Info-goto-node (Info-extract-pointer "next")))
1354 "Go to the previous node of this node."
1356 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1358 (defun Info-up (&optional same-file
)
1359 "Go to the superior node of this node.
1360 If SAME-FILE is non-nil, do not move to a different Info file."
1362 (let ((node (Info-extract-pointer "up")))
1363 (and (or same-file
(not (stringp Info-current-file
)))
1364 (string-match "^(" node
)
1365 (error "Up node is in another Info file"))
1366 (Info-goto-node node
))
1367 (Info-restore-point Info-history
))
1370 "Go back to the last node visited."
1373 (error "This is the first Info node you looked at"))
1374 (let (filename nodename opoint
)
1375 (setq filename
(car (car Info-history
)))
1376 (setq nodename
(car (cdr (car Info-history
))))
1377 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1378 (setq Info-history
(cdr Info-history
))
1379 (Info-find-node filename nodename
)
1380 (setq Info-history
(cdr Info-history
))
1381 (goto-char opoint
)))
1384 (defun Info-directory ()
1385 "Go to the Info directory node."
1387 (Info-find-node "dir" "top"))
1389 (defun Info-follow-reference (footnotename)
1390 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1391 FOOTNOTENAME may be an abbreviation of the reference name."
1393 (let ((completion-ignore-case t
)
1394 (case-fold-search t
)
1395 completions default alt-default
(start-point (point)) str i bol eol
)
1397 ;; Store end and beginning of line.
1403 (goto-char (point-min))
1404 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1405 (setq str
(buffer-substring-no-properties
1408 ;; See if this one should be the default.
1410 (<= (match-beginning 0) start-point
)
1411 (<= start-point
(point))
1413 ;; See if this one should be the alternate default.
1414 (and (null alt-default
)
1415 (and (<= bol
(match-beginning 0))
1417 (setq alt-default t
))
1419 (while (setq i
(string-match "[ \n\t]+" str i
))
1420 (setq str
(concat (substring str
0 i
) " "
1421 (substring str
(match-end 0))))
1423 ;; Record as a completion and perhaps as default.
1424 (if (eq default t
) (setq default str
))
1425 (if (eq alt-default t
) (setq alt-default str
))
1426 ;; Don't add this string if it's a duplicate.
1427 ;; We use a loop instead of "(assoc str completions)" because
1428 ;; we want to do a case-insensitive compare.
1429 (let ((tail completions
)
1430 (tem (downcase str
)))
1432 (not (string-equal tem
(downcase (car (car tail
))))))
1433 (setq tail
(cdr tail
)))
1436 (cons (cons str nil
)
1438 ;; If no good default was found, try an alternate.
1440 (setq default alt-default
))
1441 ;; If only one cross-reference found, then make it default.
1442 (if (eq (length completions
) 1)
1443 (setq default
(car (car completions
))))
1445 (let ((input (completing-read (if default
1447 "Follow reference named: (default "
1449 "Follow reference named: ")
1450 completions nil t
)))
1451 (list (if (equal input
"")
1453 (error "No cross-references in this node"))))
1455 (unless footnotename
1456 (error "No reference was specified"))
1458 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
)))
1459 (case-fold-search t
))
1460 (while (setq i
(string-match " " str i
))
1461 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1464 (goto-char (point-min))
1465 (or (re-search-forward str nil t
)
1466 (error "No cross-reference named %s" footnotename
))
1467 (goto-char (+ (match-beginning 0) 5))
1469 (Info-extract-menu-node-name "Bad format cross reference" t
)))
1470 (while (setq i
(string-match "[ \t\n]+" target i
))
1471 (setq target
(concat (substring target
0 i
) " "
1472 (substring target
(match-end 0))))
1474 (Info-goto-node target
)))
1476 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
1477 (skip-chars-forward " \t\n")
1480 (skip-chars-forward "^:")
1483 (if (looking-at ":")
1484 (buffer-substring-no-properties beg
(1- (point)))
1485 (skip-chars-forward " \t\n")
1486 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
1487 (replace-regexp-in-string "[ \n]+" " " str
)))
1489 ;; No one calls this.
1490 ;;(defun Info-menu-item-sequence (list)
1492 ;; (Info-menu (car list))
1493 ;; (setq list (cdr list))))
1495 (defvar Info-complete-menu-buffer
)
1496 (defvar Info-complete-next-re nil
)
1497 (defvar Info-complete-cache nil
)
1499 (defun Info-complete-menu-item (string predicate action
)
1500 ;; This uses two dynamically bound variables:
1501 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1502 ;; is the menu of items we're trying to complete.
1503 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1504 ;; also look for menu items in subsequent nodes as long as those
1505 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1506 ;; only used for completion in Info-index.
1508 (set-buffer Info-complete-menu-buffer
)
1509 (let ((completion-ignore-case t
)
1510 (case-fold-search t
)
1511 (orignode Info-current-node
)
1513 (goto-char (point-min))
1514 (search-forward "\n* Menu:")
1515 (if (not (memq action
'(nil t
)))
1517 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
1518 (let ((pattern (concat "\n\\* +\\("
1519 (regexp-quote string
)
1523 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
1524 (equal (nth 1 Info-complete-cache
) Info-current-node
)
1525 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
1526 (let ((prev (nth 3 Info-complete-cache
)))
1527 (eq t
(compare-strings string
0 (length prev
)
1529 ;; We can reuse the previous list.
1530 (setq completions
(nth 4 Info-complete-cache
))
1531 ;; The cache can't be used.
1534 (while (re-search-forward pattern nil t
)
1535 (push (match-string-no-properties 1)
1537 ;; Check subsequent nodes if applicable.
1538 (and Info-complete-next-re
1539 (setq nextnode
(Info-extract-pointer "next" t
))
1540 (string-match Info-complete-next-re nextnode
)))
1541 (Info-goto-node nextnode
))
1542 ;; Go back to the start node (for the next completion).
1543 (unless (equal Info-current-node orignode
)
1544 (Info-goto-node orignode
))
1545 ;; Update the cache.
1546 (set (make-local-variable 'Info-complete-cache
)
1547 (list Info-current-file Info-current-node
1548 Info-complete-next-re string completions
)))
1550 (all-completions string completions predicate
)
1551 (try-completion string completions predicate
)))))))
1554 (defun Info-menu (menu-item &optional fork
)
1555 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1556 The menu item should one of those listed in the current node's menu.
1557 Completion is allowed, and the default menu item is the one point is on.
1558 If FORK is non-nil (interactively with a prefix arg), show the node in
1559 a new info buffer. If FORK is a string, it is the name to use for the
1562 (let ((completions '())
1563 ;; If point is within a menu item, use that item as the default
1568 (case-fold-search t
))
1570 (goto-char (point-min))
1571 (if (not (search-forward "\n* menu:" nil t
))
1572 (error "No menu in this node"))
1578 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t
)
1579 (setq default
(match-string-no-properties 1))))))
1582 (setq item
(let ((completion-ignore-case t
)
1583 (Info-complete-menu-buffer (current-buffer)))
1584 (completing-read (if default
1585 (format "Menu item (default %s): "
1588 'Info-complete-menu-item nil t
)))
1589 ;; we rely on the fact that completing-read accepts an input
1590 ;; of "" even when the require-match argument is true and ""
1591 ;; is not a valid possibility
1592 (if (string= item
"")
1597 (list item current-prefix-arg
))))
1598 ;; there is a problem here in that if several menu items have the same
1599 ;; name you can only go to the node of the first with this command.
1600 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
1602 (defun Info-extract-menu-item (menu-item)
1603 (setq menu-item
(regexp-quote menu-item
))
1604 (let ((case-fold-search t
))
1606 (let ((case-fold-search t
))
1607 (goto-char (point-min))
1608 (or (search-forward "\n* menu:" nil t
)
1609 (error "No menu in this node"))
1610 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1611 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1612 (error "No such item in menu"))
1615 (Info-extract-menu-node-name)))))
1617 ;; If COUNT is nil, use the last item in the menu.
1618 (defun Info-extract-menu-counting (count)
1619 (let ((case-fold-search t
))
1621 (let ((case-fold-search t
))
1622 (goto-char (point-min))
1623 (or (search-forward "\n* menu:" nil t
)
1624 (error "No menu in this node"))
1626 (or (search-forward "\n* " nil t count
)
1627 (error "Too few items in menu"))
1628 (while (search-forward "\n* " nil t
)
1630 (Info-extract-menu-node-name)))))
1632 (defun Info-nth-menu-item ()
1633 "Go to the node of the Nth menu item.
1634 N is the digit argument used to invoke this command."
1637 (Info-extract-menu-counting
1638 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1640 (defun Info-top-node ()
1641 "Go to the Top node of this file."
1643 (Info-goto-node "Top"))
1645 (defun Info-final-node ()
1646 "Go to the final node in this file."
1648 (Info-goto-node "Top")
1649 (let ((Info-history nil
)
1650 (case-fold-search t
))
1651 ;; Go to the last node in the menu of Top.
1652 (Info-goto-node (Info-extract-menu-counting nil
))
1653 ;; If the last node in the menu is not last in pointer structure,
1654 ;; move forward until we can't go any farther.
1655 (while (Info-forward-node t t
) nil
)
1656 ;; Then keep moving down to last subnode, unless we reach an index.
1657 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1658 (save-excursion (search-forward "\n* Menu:" nil t
)))
1659 (Info-goto-node (Info-extract-menu-counting nil
)))))
1661 (defun Info-forward-node (&optional not-down no-error
)
1662 "Go forward one node, considering all nodes as forming one sequence."
1664 (goto-char (point-min))
1666 (let ((case-fold-search t
))
1667 ;; three possibilities, in order of priority:
1668 ;; 1. next node is in a menu in this node (but not in an index)
1669 ;; 2. next node is next at same level
1670 ;; 3. next node is up and next
1671 (cond ((and (not not-down
)
1672 (save-excursion (search-forward "\n* menu:" nil t
))
1673 (not (string-match "\\<index\\>" Info-current-node
)))
1674 (Info-goto-node (Info-extract-menu-counting 1))
1676 ((save-excursion (search-backward "next:" nil t
))
1679 ((and (save-excursion (search-backward "up:" nil t
))
1680 ;; Use string-equal, not equal, to ignore text props.
1681 (not (string-equal (downcase (Info-extract-pointer "up"))
1683 (let ((old-node Info-current-node
))
1685 (let (Info-history success
)
1687 (setq success
(Info-forward-node t no-error
))
1688 (or success
(Info-goto-node old-node
))))))
1690 (t (error "No pointer forward from this node")))))
1692 (defun Info-backward-node ()
1693 "Go backward one node, considering all nodes as forming one sequence."
1695 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1696 (upnode (Info-extract-pointer "up" t
))
1697 (case-fold-search t
))
1698 (cond ((and upnode
(string-match "(" upnode
))
1699 (error "First node in file"))
1700 ((and upnode
(or (null prevnode
)
1701 ;; Use string-equal, not equal,
1702 ;; to ignore text properties.
1703 (string-equal (downcase prevnode
)
1704 (downcase upnode
))))
1707 ;; If we move back at the same level,
1708 ;; go down to find the last subnode*.
1711 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1712 (save-excursion (search-forward "\n* Menu:" nil t
)))
1713 (Info-goto-node (Info-extract-menu-counting nil
)))))
1715 (error "No pointer backward from this node")))))
1718 "Exit Info by selecting some other buffer."
1721 (save-buffers-kill-emacs)
1724 (defun Info-next-menu-item ()
1725 "Go to the node of the next menu item."
1727 ;; Bind this in case the user sets it to nil.
1728 (let* ((case-fold-search t
)
1732 (search-forward "\n* menu:" nil t
)
1733 (and (search-forward "\n* " nil t
)
1734 (Info-extract-menu-node-name)))))
1735 (if node
(Info-goto-node node
)
1736 (error "No more items in menu"))))
1738 (defun Info-last-menu-item ()
1739 "Go to the node of the previous menu item."
1743 ;; Bind this in case the user sets it to nil.
1744 (let* ((case-fold-search t
)
1745 (beg (save-excursion
1746 (and (search-backward "\n* menu:" nil t
)
1748 (or (and beg
(search-backward "\n* " beg t
))
1749 (error "No previous items in menu")))
1750 (Info-goto-node (save-excursion
1751 (goto-char (match-end 0))
1752 (Info-extract-menu-node-name)))))
1754 (defmacro Info-no-error
(&rest body
)
1755 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1757 (defun Info-next-preorder ()
1758 "Go to the next subnode or the next node, or go up a level."
1760 (cond ((Info-no-error (Info-next-menu-item)))
1761 ((Info-no-error (Info-next)))
1762 ((Info-no-error (Info-up t
))
1763 ;; Since we have already gone thru all the items in this menu,
1764 ;; go up to the end of this node.
1765 (goto-char (point-max))
1766 ;; Since logically we are done with the node with that menu,
1768 (Info-next-preorder))
1770 (error "No more nodes"))))
1772 (defun Info-last-preorder ()
1773 "Go to the last node, popping up a level if there is none."
1775 (cond ((Info-no-error
1776 (Info-last-menu-item)
1777 ;; If we go down a menu item, go to the end of the node
1778 ;; so we can scroll back through it.
1779 (goto-char (point-max)))
1780 ;; Keep going down, as long as there are nested menu nodes.
1781 (while (Info-no-error
1782 (Info-last-menu-item)
1783 ;; If we go down a menu item, go to the end of the node
1784 ;; so we can scroll back through it.
1785 (goto-char (point-max))))
1787 ((and (Info-no-error (Info-extract-pointer "prev"))
1788 (not (equal (Info-extract-pointer "up")
1789 (Info-extract-pointer "prev"))))
1790 (Info-no-error (Info-prev))
1791 (goto-char (point-max))
1792 (while (Info-no-error
1793 (Info-last-menu-item)
1794 ;; If we go down a menu item, go to the end of the node
1795 ;; so we can scroll back through it.
1796 (goto-char (point-max))))
1798 ((Info-no-error (Info-up t
))
1799 (goto-char (point-min))
1800 (let ((case-fold-search t
))
1801 (or (search-forward "\n* Menu:" nil t
)
1802 (goto-char (point-max)))))
1803 (t (error "No previous nodes"))))
1805 (defun Info-scroll-up ()
1806 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1807 Once you scroll far enough in a node that its menu appears on the screen
1808 but after point, the next scroll moves into its first subnode, unless
1809 `Info-scroll-prefer-subnodes' is nil.
1811 When you scroll past the end of a node, that goes to the next node if
1812 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1813 if this node has no successor, it moves to the parent node's successor,
1814 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1815 the menu of a node, it moves to subnode indicated by the following menu
1816 item. (That case won't normally result from this command, but can happen
1820 (if (or (< (window-start) (point-min))
1821 (> (window-start) (point-max)))
1822 (set-window-start (selected-window) (point)))
1823 (let* ((case-fold-search t
)
1824 (virtual-end (save-excursion
1825 (goto-char (point-min))
1826 (if (and Info-scroll-prefer-subnodes
1827 (search-forward "\n* Menu:" nil t
))
1830 (if (or (< virtual-end
(window-start))
1831 (pos-visible-in-window-p virtual-end
))
1833 (Info-scroll-prefer-subnodes (Info-next-preorder))
1834 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1835 (t (Info-next-preorder)))
1838 (defun Info-scroll-down ()
1839 "Scroll one screenful back in Info, considering all nodes as one sequence.
1840 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1841 is non-nil, this goes to its last subnode. When you scroll past the
1842 beginning of a node, that goes to the previous node or back up to the
1845 (if (or (< (window-start) (point-min))
1846 (> (window-start) (point-max)))
1847 (set-window-start (selected-window) (point)))
1848 (let* ((case-fold-search t
)
1849 (current-point (point))
1851 (and Info-scroll-prefer-subnodes
1854 (setq current-point
(point))
1855 (goto-char (point-min))
1856 (search-forward "\n* Menu:"
1860 (pos-visible-in-window-p (point-min) nil t
))
1861 (Info-last-preorder)
1864 (defun Info-next-reference (&optional recur
)
1865 "Move cursor to the next cross-reference or menu item in the node."
1867 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1869 (case-fold-search t
))
1870 (or (eobp) (forward-char 1))
1871 (or (re-search-forward pat nil t
)
1873 (goto-char (point-min))
1874 (or (re-search-forward pat nil t
)
1877 (error "No cross references in this node")))))
1878 (goto-char (match-beginning 0))
1879 (if (looking-at "\\* Menu:")
1881 (error "No cross references in this node")
1882 (Info-next-reference t
)))))
1884 (defun Info-prev-reference (&optional recur
)
1885 "Move cursor to the previous cross-reference or menu item in the node."
1887 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1889 (case-fold-search t
))
1890 (or (re-search-backward pat nil t
)
1892 (goto-char (point-max))
1893 (or (re-search-backward pat nil t
)
1896 (error "No cross references in this node")))))
1897 (goto-char (match-beginning 0))
1898 (if (looking-at "\\* Menu:")
1900 (error "No cross references in this node")
1901 (Info-prev-reference t
)))))
1903 (defun Info-goto-index ()
1904 (Info-goto-node "Top")
1905 (or (search-forward "\n* menu:" nil t
)
1907 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1909 (goto-char (match-beginning 1))
1910 ;; Protect Info-history so that the current node (Top) is not added to it.
1911 (let ((Info-history nil
))
1912 (Info-goto-node (Info-extract-menu-node-name))))
1914 (defun Info-index (topic)
1915 "Look up a string TOPIC in the index for this file.
1916 The index is defined as the first node in the top level menu whose
1917 name contains the word \"Index\", plus any immediately following
1918 nodes whose names also contain the word \"Index\".
1919 If there are no exact matches to the specified topic, this chooses
1920 the first match which is a case-insensitive substring of a topic.
1921 Use the `,' command to see the other matches.
1922 Give a blank topic name to go to the Index node itself."
1925 (let ((Info-complete-menu-buffer (clone-buffer))
1926 (Info-complete-next-re "\\<Index\\>"))
1927 (if (equal Info-current-file
"dir")
1928 (error "The Info directory node has no index; use m to select a manual"))
1930 (with-current-buffer Info-complete-menu-buffer
1932 (completing-read "Index topic: " 'Info-complete-menu-item
))
1933 (kill-buffer Info-complete-menu-buffer
)))))
1934 (if (equal Info-current-file
"dir")
1935 (error "The Info directory node has no index; use m to select a manual"))
1936 (let ((orignode Info-current-node
)
1938 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1939 (regexp-quote topic
)))
1941 (case-fold-search t
))
1943 (or (equal topic
"")
1946 ;; We bind Info-history to nil for internal node-switches so
1947 ;; that we don't put junk in the history. In the first
1948 ;; Info-goto-index call, above, we do update the history
1949 ;; because that is what the user's previous node choice into it.
1954 (goto-char (point-min))
1955 (while (re-search-forward pattern nil t
)
1956 (push (list (match-string-no-properties 1)
1957 (match-string-no-properties 2)
1959 (string-to-number (concat "0"
1962 (and (setq node
(Info-extract-pointer "next" t
))
1963 (string-match "\\<Index\\>" node
)))
1964 (Info-goto-node node
))
1967 (Info-goto-node orignode
)
1968 (error "No `%s' in index" topic
)))
1969 ;; Here it is a feature that assoc is case-sensitive.
1970 (while (setq found
(assoc topic matches
))
1971 (setq exact
(cons found exact
)
1972 matches
(delq found matches
)))
1973 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1974 (Info-index-next 0)))))
1976 (defun Info-index-next (num)
1977 "Go to the next matching index item from the last `i' command."
1979 (or Info-index-alternatives
1980 (error "No previous `i' command"))
1982 (setq num
(+ num
(length Info-index-alternatives
))))
1984 (setq Info-index-alternatives
1985 (nconc (cdr Info-index-alternatives
)
1986 (list (car Info-index-alternatives
)))
1988 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1989 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1990 (forward-line (nth 3 (car Info-index-alternatives
)))
1991 (forward-line 3) ; don't search in headers
1992 (let ((name (car (car Info-index-alternatives
))))
1993 (Info-find-index-name name
)))
1994 (message "Found `%s' in %s. %s"
1995 (car (car Info-index-alternatives
))
1996 (nth 2 (car Info-index-alternatives
))
1997 (if (cdr Info-index-alternatives
)
1998 "(Press `,' for more)"
2001 (defun Info-find-index-name (name)
2002 "Move point to the place within the current node where NAME is defined."
2003 (let ((case-fold-search t
))
2004 (if (or (re-search-forward (format
2005 "[a-zA-Z]+: %s\\( \\|$\\)"
2006 (regexp-quote name
)) nil t
)
2007 ;; Find a function definition with a return type.
2008 (re-search-forward (format
2009 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2010 (regexp-quote name
)) nil t
)
2011 (search-forward (format "`%s'" name
) nil t
)
2012 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
2014 (format "`%s'" (substring name
0 (match-beginning 1)))
2016 (search-forward name nil t
))
2018 (goto-char (point-min)))))
2020 (defun Info-undefined ()
2021 "Make command be undefined in Info."
2026 "Enter the Info tutorial."
2028 (delete-other-windows)
2029 (Info-find-node "info"
2030 (if (< (window-height) 23)
2034 (defun Info-summary ()
2035 "Display a brief summary of all Info commands."
2037 (save-window-excursion
2038 (switch-to-buffer "*Help*")
2039 (setq buffer-read-only nil
)
2041 (insert (documentation 'Info-mode
))
2043 (goto-char (point-min))
2045 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
2046 (message (if flag
"Type Space to see more"
2047 "Type Space to return to Info"))
2048 (if (not (eq ?\
(setq ch
(read-event))))
2049 (progn (setq unread-command-events
(list ch
)) nil
)
2052 (bury-buffer "*Help*")))
2054 (defun Info-get-token (pos start all
&optional errorstring
)
2055 "Return the token around POS.
2056 POS must be somewhere inside the token
2057 START is a regular expression which will match the
2058 beginning of the tokens delimited string
2059 ALL is a regular expression with a single
2060 parenthesized subpattern which is the token to be
2061 returned. E.g. '{\(.*\)}' would return any string
2062 enclosed in braces around POS.
2063 ERRORSTRING optional fourth argument, controls action on no match
2066 a string: signal an error, using that string."
2067 (let ((case-fold-search t
))
2070 ;; First look for a match for START that goes across POS.
2071 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2072 (not (looking-at start
)))
2074 ;; If we did not find one, search back for START
2075 ;; (this finds only matches that end at or before POS).
2076 (or (looking-at start
)
2079 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2081 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2082 (not (setq found
(and (<= (match-beginning 0) pos
)
2083 (> (match-end 0) pos
))))))
2084 (if (and found
(<= (match-beginning 0) pos
)
2085 (> (match-end 0) pos
))
2086 (match-string-no-properties 1)
2087 (cond ((null errorstring
)
2093 (error "No %s around position %d" errorstring pos
))))))))
2095 (defun Info-mouse-follow-nearest-node (click)
2096 "\\<Info-mode-map>Follow a node reference near point.
2097 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2098 At end of the node's text, moves to the next node, or up if none."
2100 (mouse-set-point click
)
2101 (and (not (Info-try-follow-nearest-node))
2102 (save-excursion (forward-line 1) (eobp))
2103 (Info-next-preorder)))
2105 (defun Info-follow-nearest-node ()
2106 "\\<Info-mode-map>Follow a node reference near point.
2107 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
2108 If no reference to follow, moves to the next node, or up if none."
2110 (or (Info-try-follow-nearest-node)
2111 (Info-next-preorder)))
2113 ;; Common subroutine.
2114 (defun Info-try-follow-nearest-node ()
2115 "Follow a node reference near point. Return non-nil if successful."
2118 ((setq node
(Info-get-token (point) "\\*note[ \n]"
2119 "\\*note[ \n]\\([^:]*\\):"))
2120 (Info-follow-reference node
))
2121 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2122 (Info-goto-node node
))
2123 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
2126 (setq node
(Info-extract-menu-node-name))
2127 (Info-goto-node node
))
2128 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2129 (Info-goto-node node
))
2130 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2131 (Info-goto-node node
))
2132 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2133 (Info-goto-node "Top"))
2134 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2135 (Info-goto-node node
)))
2138 (defvar Info-mode-map nil
2139 "Keymap containing Info commands.")
2142 (setq Info-mode-map
(make-keymap))
2143 (suppress-keymap Info-mode-map
)
2144 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2145 (define-key Info-mode-map
" " 'Info-scroll-up
)
2146 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2147 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2148 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
2149 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
2150 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
2151 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
2152 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
2153 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
2154 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
2155 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
2156 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
2157 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
2158 (define-key Info-mode-map
"0" 'undefined
)
2159 (define-key Info-mode-map
"?" 'Info-summary
)
2160 (define-key Info-mode-map
"]" 'Info-forward-node
)
2161 (define-key Info-mode-map
"[" 'Info-backward-node
)
2162 (define-key Info-mode-map
"<" 'Info-top-node
)
2163 (define-key Info-mode-map
">" 'Info-final-node
)
2164 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
2165 (define-key Info-mode-map
"c" 'Info-copy-current-node-name
)
2166 (define-key Info-mode-map
"d" 'Info-directory
)
2167 (define-key Info-mode-map
"e" 'Info-edit
)
2168 (define-key Info-mode-map
"f" 'Info-follow-reference
)
2169 (define-key Info-mode-map
"g" 'Info-goto-node
)
2170 (define-key Info-mode-map
"h" 'Info-help
)
2171 (define-key Info-mode-map
"i" 'Info-index
)
2172 (define-key Info-mode-map
"l" 'Info-last
)
2173 (define-key Info-mode-map
"m" 'Info-menu
)
2174 (define-key Info-mode-map
"n" 'Info-next
)
2175 (define-key Info-mode-map
"p" 'Info-prev
)
2176 (define-key Info-mode-map
"q" 'Info-exit
)
2177 (define-key Info-mode-map
"s" 'Info-search
)
2178 ;; For consistency with Rmail.
2179 (define-key Info-mode-map
"\M-s" 'Info-search
)
2180 (define-key Info-mode-map
"\M-n" 'clone-buffer
)
2181 (define-key Info-mode-map
"t" 'Info-top-node
)
2182 (define-key Info-mode-map
"u" 'Info-up
)
2183 (define-key Info-mode-map
"," 'Info-index-next
)
2184 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
2185 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
2188 (defun Info-check-pointer (item)
2189 "Non-nil if ITEM is present in this node."
2191 (Info-extract-pointer item
)
2195 Info-mode-menu Info-mode-map
2196 "Menu for info files."
2198 ["Up" Info-up
:active
(Info-check-pointer "up")
2199 :help
"Go up in the Info tree"]
2200 ["Next" Info-next
:active
(Info-check-pointer "next")
2201 :help
"Go to the next node"]
2202 ["Previous" Info-prev
:active
(Info-check-pointer "prev[ious]*")
2203 :help
"Go to the previous node"]
2204 ["Backward" Info-backward-node
2205 :help
"Go backward one node, considering all as a sequence"]
2206 ["Forward" Info-forward-node
2207 :help
"Go forward one node, considering all as a sequence"]
2208 ["Beginning" beginning-of-buffer
2209 :help
"Go to beginning of this node"]
2210 ["Top" Info-top-node
2211 :help
"Go to top node of file"]
2212 ["Final Node" Info-final-node
2213 :help
"Go to final node in this file"]
2214 ("Menu Item" ["You should never see this" report-emacs-bug t
])
2215 ("Reference" ["You should never see this" report-emacs-bug t
])
2216 ["Search..." Info-search
2217 :help
"Search for regular expression in this Info file"]
2218 ["Go to Node..." Info-goto-node
2219 :help
"Go to a named node"]
2220 ["Last" Info-last
:active Info-history
2221 :help
"Go to the last node you were at"]
2223 ["Lookup a String" Info-index
2224 :help
"Look for a string in the index items"]
2225 ["Next Matching Item" Info-index-next
2226 :help
"Look for another occurrence of previous item"])
2227 ["Edit" Info-edit
:help
"Edit contents of this node"
2228 :active Info-enable-edit
]
2229 ["Copy Node Name" Info-copy-current-node-name
2230 :help
"Copy the name of the current node into the kill ring"]
2231 ["Exit" Info-exit
:help
"Stop reading Info"]))
2234 (defvar info-tool-bar-map
2235 (if (display-graphic-p)
2236 (let ((map (make-sparse-keymap)))
2237 (tool-bar-local-item-from-menu 'Info-exit
"close" map Info-mode-map
)
2238 (tool-bar-local-item-from-menu 'Info-prev
"left_arrow" map Info-mode-map
)
2239 (tool-bar-local-item-from-menu 'Info-next
"right_arrow" map Info-mode-map
)
2240 (tool-bar-local-item-from-menu 'Info-up
"up_arrow" map Info-mode-map
)
2241 (tool-bar-local-item-from-menu 'Info-last
"undo" map Info-mode-map
)
2242 (tool-bar-local-item-from-menu 'Info-top-node
"home" map Info-mode-map
)
2243 (tool-bar-local-item-from-menu 'Info-index
"index" map Info-mode-map
)
2244 (tool-bar-local-item-from-menu 'Info-goto-node
"jump_to" map Info-mode-map
)
2245 (tool-bar-local-item-from-menu 'Info-search
"search" map Info-mode-map
)
2248 (defvar Info-menu-last-node nil
)
2249 ;; Last node the menu was created for.
2250 ;; Value is a list, (FILE-NAME NODE-NAME).
2252 (defun Info-menu-update ()
2253 "Update the Info menu for the current node."
2255 (if (or (not (eq major-mode
'Info-mode
))
2256 (equal (list Info-current-file Info-current-node
)
2257 Info-menu-last-node
))
2259 ;; Update menu menu.
2260 (let* ((Info-complete-menu-buffer (current-buffer))
2261 (items (nreverse (condition-case nil
2262 (Info-complete-menu-item "" nil t
)
2266 (while (and items
(< number
9))
2267 (setq current
(car items
)
2270 (setq entries
(cons `[,current
2271 (Info-menu ,current
)
2272 :keys
,(format "%d" number
)]
2275 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
2277 (setq entries
(list ["No menu" nil nil
] nil
:active
)))
2278 (easy-menu-change '("Info") "Menu Item" (nreverse entries
)))
2279 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2281 str i entries current
2283 (case-fold-search t
))
2285 (goto-char (point-min))
2286 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
2287 (setq str
(buffer-substring
2291 (while (setq i
(string-match "[ \n\t]+" str i
))
2292 (setq str
(concat (substring str
0 i
) " "
2293 (substring str
(match-end 0))))
2297 (while (and items
(< number
9))
2298 (setq current
(car items
)
2301 (setq entries
(cons `[,current
2302 (Info-follow-reference ,current
)
2306 (setq entries
(cons ["Other..." Info-follow-reference t
]
2309 (setq entries
(list ["No references" nil nil
] nil
:active
)))
2310 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
2311 ;; Update last seen node.
2312 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
2313 ;; Try to avoid entering infinite beep mode in case of errors.
2317 (defun Info-copy-current-node-name ()
2318 "Put the name of the current info node into the kill ring.
2319 The name of the info file is prepended to the node name in parentheses."
2321 (unless Info-current-node
2322 (error "No current info node"))
2325 (file-name-nondirectory
2326 (if (stringp Info-current-file
)
2328 (or buffer-file-name
"")))
2330 Info-current-node
)))
2333 ;; Info mode is suitable only for specially formatted data.
2334 (put 'Info-mode
'mode-class
'special
)
2335 (put 'Info-mode
'no-clone-indirect t
)
2338 "Info mode provides commands for browsing through the Info documentation tree.
2339 Documentation in Info is divided into \"nodes\", each of which discusses
2340 one topic and contains references to other nodes which discuss related
2341 topics. Info has commands to follow the references and show you other nodes.
2344 \\[Info-help] Invoke the Info tutorial.
2345 \\[Info-exit] Quit Info: reselect previously selected buffer.
2347 Selecting other nodes:
2348 \\[Info-mouse-follow-nearest-node]
2349 Follow a node reference you click on.
2350 This works with menu items, cross references, and
2351 the \"next\", \"previous\" and \"up\", depending on where you click.
2352 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2353 \\[Info-next] Move to the \"next\" node of this node.
2354 \\[Info-prev] Move to the \"previous\" node of this node.
2355 \\[Info-up] Move \"up\" from this node.
2356 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2357 Picking a menu item causes another node to be selected.
2358 \\[Info-directory] Go to the Info directory node.
2359 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2360 \\[Info-last] Move to the last node you were at.
2361 \\[Info-index] Look up a topic in this file's Index and move to that node.
2362 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2363 \\[Info-top-node] Go to the Top node of this file.
2364 \\[Info-final-node] Go to the final node in this file.
2365 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2366 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2368 Moving within a node:
2369 \\[Info-scroll-up] Normally, scroll forward a full screen.
2370 Once you scroll far enough in a node that its menu appears on the
2371 screen but after point, the next scroll moves into its first
2372 subnode. When after all menu items (or if there is no menu),
2373 move up to the parent node.
2374 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2375 already visible, try to go to the previous menu entry, or up
2377 \\[beginning-of-buffer] Go to beginning of node.
2380 \\[Info-exit] Quit Info: reselect previously selected buffer.
2381 \\[Info-edit] Edit contents of selected node.
2382 1 Pick first item in node's menu.
2383 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2384 \\[Info-goto-node] Move to node specified by name.
2385 You may include a filename as well, as (FILENAME)NODENAME.
2386 \\[universal-argument] \\[info] Move to new Info file with completion.
2387 \\[Info-search] Search through this Info file for specified regexp,
2388 and select the node in which the next occurrence is found.
2389 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2390 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2391 (kill-all-local-variables)
2392 (setq major-mode
'Info-mode
)
2393 (setq mode-name
"Info")
2395 (use-local-map Info-mode-map
)
2396 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2397 (set-syntax-table text-mode-syntax-table
)
2398 (setq local-abbrev-table text-mode-abbrev-table
)
2399 (setq case-fold-search t
)
2400 (setq buffer-read-only t
)
2401 (make-local-variable 'Info-current-file
)
2402 (make-local-variable 'Info-current-subfile
)
2403 (make-local-variable 'Info-current-node
)
2404 (make-local-variable 'Info-tag-table-marker
)
2405 (setq Info-tag-table-marker
(make-marker))
2406 (make-local-variable 'Info-tag-table-buffer
)
2407 (setq Info-tag-table-buffer nil
)
2408 (make-local-variable 'Info-history
)
2409 (make-local-variable 'Info-index-alternatives
)
2410 (make-local-variable 'Info-header-line
)
2411 (setq header-line-format
(if Info-use-header-line
'Info-header-line
))
2412 (set (make-local-variable 'tool-bar-map
) info-tool-bar-map
)
2413 ;; This is for the sake of the invisible text we use handling titles.
2414 (make-local-variable 'line-move-ignore-invisible
)
2415 (setq line-move-ignore-invisible t
)
2416 (add-hook 'clone-buffer-hook
'Info-clone-buffer-hook nil t
)
2417 (add-hook 'change-major-mode-hook
'font-lock-defontify nil t
)
2418 (Info-set-mode-line)
2419 (run-hooks 'Info-mode-hook
))
2421 (defun Info-clone-buffer-hook ()
2422 (when (bufferp Info-tag-table-buffer
)
2423 (setq Info-tag-table-buffer
2424 (with-current-buffer Info-tag-table-buffer
(clone-buffer))))
2425 (let ((m Info-tag-table-marker
))
2427 (setq Info-tag-table-marker
2428 (if (and (marker-position m
) (bufferp Info-tag-table-buffer
))
2429 (with-current-buffer Info-tag-table-buffer
2430 (copy-marker (marker-position m
)))
2433 (defvar Info-edit-map
(let ((map (make-sparse-keymap)))
2434 (set-keymap-parent map text-mode-map
)
2435 (define-key map
"\C-c\C-c" 'Info-cease-edit
)
2437 "Local keymap used within `e' command of Info.")
2439 ;; Info-edit mode is suitable only for specially formatted data.
2440 (put 'Info-edit-mode
'mode-class
'special
)
2442 (defun Info-edit-mode ()
2443 "Major mode for editing the contents of an Info node.
2444 Like text mode with the addition of `Info-cease-edit'
2445 which returns to Info mode for browsing.
2447 (use-local-map Info-edit-map
)
2448 (setq major-mode
'Info-edit-mode
)
2449 (setq mode-name
"Info Edit")
2450 (kill-local-variable 'mode-line-buffer-identification
)
2451 (setq buffer-read-only nil
)
2452 (force-mode-line-update)
2453 (buffer-enable-undo (current-buffer))
2454 (run-hooks 'Info-edit-mode-hook
))
2457 "Edit the contents of this Info node.
2458 Allowed only if variable `Info-enable-edit' is non-nil."
2460 (or Info-enable-edit
2461 (error "Editing info nodes is not enabled"))
2463 (message "%s" (substitute-command-keys
2464 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2466 (defun Info-cease-edit ()
2467 "Finish editing Info node; switch back to Info proper."
2469 ;; Do this first, so nothing has changed if user C-g's at query.
2470 (and (buffer-modified-p)
2471 (y-or-n-p "Save the file? ")
2473 (use-local-map Info-mode-map
)
2474 (setq major-mode
'Info-mode
)
2475 (setq mode-name
"Info")
2476 (Info-set-mode-line)
2477 (setq buffer-read-only t
)
2478 (force-mode-line-update)
2479 (and (marker-position Info-tag-table-marker
)
2481 (message "Tags may have changed. Use Info-tagify if necessary")))
2483 (defvar Info-file-list-for-emacs
2484 '("ediff" "eudc" "forms" "gnus" "info" ("mh" .
"mh-e")
2485 "sc" "message" ("dired" .
"dired-x") "viper" "vip" "idlwave"
2486 ("c" .
"ccmode") ("c++" .
"ccmode") ("objc" .
"ccmode")
2487 ("java" .
"ccmode") ("idl" .
"ccmode") ("pike" .
"ccmode")
2488 ("skeleton" .
"autotype") ("auto-insert" .
"autotype")
2489 ("copyright" .
"autotype") ("executable" .
"autotype")
2490 ("time-stamp" .
"autotype") ("quickurl" .
"autotype")
2491 ("tempo" .
"autotype") ("hippie-expand" .
"autotype")
2492 ("cvs" .
"pcl-cvs") ("ada" .
"ada-mode") "calc"
2493 ("calcAlg" .
"calc") ("calcDigit" .
"calc") ("calcVar" .
"calc")
2494 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2495 ("mail-header" .
"emacs-mime") ("mail-content" .
"emacs-mime")
2496 ("mail-encode" .
"emacs-mime") ("mail-decode" .
"emacs-mime")
2497 ("rfc2045" .
"emacs-mime")
2498 ("rfc2231" .
"emacs-mime") ("rfc2047" .
"emacs-mime")
2499 ("rfc2045" .
"emacs-mime") ("rfc1843" .
"emacs-mime")
2500 ("ietf-drums" .
"emacs-mime") ("quoted-printable" .
"emacs-mime")
2501 ("binhex" .
"emacs-mime") ("uudecode" .
"emacs-mime")
2502 ("mailcap" .
"emacs-mime") ("mm" .
"emacs-mime")
2503 ("mml" .
"emacs-mime"))
2504 "List of Info files that describe Emacs commands.
2505 An element can be a file name, or a list of the form (PREFIX . FILE)
2506 where PREFIX is a name prefix and FILE is the file to look in.
2507 If the element is just a file name, the file name also serves as the prefix.")
2509 (defun Info-find-emacs-command-nodes (command)
2510 "Return a list of locations documenting COMMAND.
2511 The `info-file' property of COMMAND says which Info manual to search.
2512 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2513 defines heuristics for which Info manual to try.
2514 The locations are of the format used in `Info-history', i.e.
2515 \(FILENAME NODENAME BUFFERPOS\)."
2517 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2518 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2519 (info-file "emacs")) ;default
2520 ;; Determine which info file this command is documented in.
2521 (if (get command
'info-file
)
2522 (setq info-file
(get command
'info-file
))
2523 ;; If it doesn't say explicitly, test its name against
2524 ;; various prefixes that we know.
2525 (let ((file-list Info-file-list-for-emacs
))
2527 (let* ((elt (car file-list
))
2528 (name (if (consp elt
)
2531 (file (if (consp elt
) (cdr elt
) elt
))
2532 (regexp (concat "\\`" (regexp-quote name
)
2534 (if (string-match regexp
(symbol-name command
))
2535 (setq info-file file file-list nil
))
2536 (setq file-list
(cdr file-list
))))))
2537 (Info-find-node info-file
"Top")
2538 (or (and (search-forward "\n* menu:" nil t
)
2539 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2540 (error "Info file `%s' appears to lack an index" info-file
))
2541 (goto-char (match-beginning 1))
2542 ;; Bind Info-history to nil, to prevent the index nodes from
2543 ;; getting into the node history.
2544 (let ((Info-history nil
)
2547 (Info-goto-node (Info-extract-menu-node-name))
2550 (goto-char (point-min))
2551 (while (re-search-forward cmd-desc nil t
)
2553 (cons (list Info-current-file
2554 (match-string-no-properties 2)
2557 (and (setq node
(Info-extract-pointer "next" t
))
2558 (string-match "\\<Index\\>" node
)))
2559 (Info-goto-node node
)))
2563 (defun Info-goto-emacs-command-node (command)
2564 "Go to the Info node in the Emacs manual for command COMMAND.
2565 The command is found by looking up in Emacs manual's indices
2566 or in another manual found via COMMAND's `info-file' property or
2567 the variable `Info-file-list-for-emacs'."
2568 (interactive "CFind documentation for command: ")
2569 (or (commandp command
)
2570 (signal 'wrong-type-argument
(list 'commandp command
)))
2571 (let ((where (Info-find-emacs-command-nodes command
)))
2573 (let ((num-matches (length where
)))
2574 ;; Get Info running, and pop to it in another window.
2575 (save-window-excursion
2577 ;; FIXME It would be cool if this could use a buffer other
2579 (pop-to-buffer "*info*")
2580 ;; Bind Info-history to nil, to prevent the last Index node
2581 ;; visited by Info-find-emacs-command-nodes from being
2582 ;; pushed onto the history.
2583 (let ((Info-history nil
))
2584 (Info-find-node (car (car where
))
2585 (car (cdr (car where
)))))
2586 (if (> num-matches
1)
2588 ;; (car where) will be pushed onto Info-history
2589 ;; when/if they go to another node. Put the other
2590 ;; nodes that were found on the history.
2591 (setq Info-history
(nconc (cdr where
) Info-history
))
2592 (message "Found %d other entr%s. Use %s to see %s."
2594 (if (> num-matches
2) "ies" "y")
2595 (substitute-command-keys "\\[Info-last]")
2596 (if (> num-matches
2) "them" "it")))))
2597 (error "Couldn't find documentation for %s" command
))))
2600 (defun Info-goto-emacs-key-command-node (key)
2601 "Go to the node in the Emacs manual which describes the command bound to KEY.
2603 Interactively, if the binding is `execute-extended-command', a command is read.
2604 The command is found by looking up in Emacs manual's indices
2605 or in another manual found via COMMAND's `info-file' property or
2606 the variable `Info-file-list-for-emacs'."
2607 (interactive "kFind documentation for key: ")
2608 (let ((command (key-binding key
)))
2609 (cond ((null command
)
2610 (message "%s is undefined" (key-description key
)))
2611 ((and (interactive-p)
2612 (eq command
'execute-extended-command
))
2613 (Info-goto-emacs-command-node
2614 (read-command "Find documentation for command: ")))
2616 (Info-goto-emacs-command-node command
)))))
2618 (defface Info-title-1-face
2619 '((((type tty pc
) (class color
)) (:foreground
"yellow" :weight bold
))
2620 (t (:height
1.2 :inherit Info-title-2-face
)))
2621 "Face for Info titles at level 1."
2624 (defface Info-title-2-face
2625 '((((type tty pc
) (class color
)) (:foreground
"lightblue" :weight bold
))
2626 (t (:height
1.2 :inherit Info-title-3-face
)))
2627 "Face for Info titles at level 2."
2630 (defface Info-title-3-face
2631 '((((type tty pc
) (class color
)) (:weight bold
))
2632 (t (:height
1.2 :inherit Info-title-4-face
)))
2633 "Face for Info titles at level 3."
2636 (defface Info-title-4-face
2637 '((((type tty pc
) (class color
)) (:weight bold
))
2638 (t (:weight bold
:inherit variable-pitch
)))
2639 "Face for Info titles at level 4."
2642 (defface info-menu-header
2647 :inherit variable-pitch
2649 "Face for headers in Info menus."
2652 (defun Info-fontify-menu-headers ()
2653 "Add the face `info-menu-header' to any header before a menu entry."
2655 (goto-char (point-min))
2656 (when (re-search-forward "\\* Menu:" nil t
)
2657 (put-text-property (match-beginning 0) (match-end 0)
2658 'font-lock-face
'info-menu-header
)
2659 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t
)
2660 (put-text-property (match-beginning 1) (match-end 1)
2661 'font-lock-face
'info-menu-header
)))))
2663 (defvar Info-next-link-keymap
2664 (let ((keymap (make-sparse-keymap)))
2665 (define-key keymap
[header-line mouse-1
] 'Info-next
)
2666 (define-key keymap
[header-line mouse-2
] 'Info-next
)
2667 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2668 (define-key keymap
[mouse-2
] 'Info-next
)
2670 "Keymap to put on the Next link in the text or the header line.")
2672 (defvar Info-prev-link-keymap
2673 (let ((keymap (make-sparse-keymap)))
2674 (define-key keymap
[header-line mouse-1
] 'Info-prev
)
2675 (define-key keymap
[header-line mouse-2
] 'Info-prev
)
2676 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2677 (define-key keymap
[mouse-2
] 'Info-prev
)
2679 "Keymap to put on the Prev link in the text or the header line.")
2682 (defvar Info-up-link-keymap
2683 (let ((keymap (make-sparse-keymap)))
2684 (define-key keymap
[header-line mouse-1
] 'Info-up
)
2685 (define-key keymap
[header-line mouse-2
] 'Info-up
)
2686 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2687 (define-key keymap
[mouse-2
] 'Info-up
)
2689 "Keymap to put on the Up link in the text or the header line.")
2691 (defun Info-fontify-node ()
2692 ;; Only fontify the node if it hasn't already been done.
2693 (unless (next-property-change (point-min))
2695 (let ((inhibit-read-only t
)
2696 (case-fold-search t
)
2698 (goto-char (point-min))
2699 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
2700 (goto-char (match-end 0))
2701 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2702 (goto-char (match-end 0))
2703 (let* ((nbeg (match-beginning 2))
2704 (nend (match-end 2))
2705 (tbeg (match-beginning 1))
2706 (tag (buffer-substring tbeg
(match-end 1))))
2707 (if (string-equal tag
"Node")
2708 (put-text-property nbeg nend
'font-lock-face
'info-header-node
)
2709 (put-text-property nbeg nend
'font-lock-face
'info-header-xref
)
2710 (put-text-property tbeg nend
'mouse-face
'highlight
)
2711 (put-text-property tbeg nend
2713 (concat "Go to node "
2714 (buffer-substring nbeg nend
)))
2715 ;; Always set up the text property keymap.
2716 ;; It will either be used in the buffer
2717 ;; or copied in the header line.
2718 (put-text-property tbeg nend
'keymap
2720 ((equal tag
"Prev") Info-prev-link-keymap
)
2721 ((equal tag
"Next") Info-next-link-keymap
)
2722 ((equal tag
"Up") Info-up-link-keymap
))))))
2723 (when Info-use-header-line
2724 (goto-char (point-min))
2725 (let ((header-end (save-excursion (end-of-line) (point)))
2727 ;; If we find neither Next: nor Prev: link, show the entire
2728 ;; node header. Otherwise, don't show the File: and Node:
2729 ;; parts, to avoid wasting precious space on information that
2730 ;; is available in the mode line.
2731 (if (re-search-forward
2732 "\\(next\\|up\\|prev[ious]*\\): "
2735 (goto-char (match-beginning 1))
2736 (setq header
(buffer-substring (point) header-end
)))
2737 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" nil t
)
2739 (concat "No next, prev or up links -- "
2740 (buffer-substring (point) header-end
)))
2741 (setq header
(buffer-substring (point) header-end
))))
2743 (put-text-property (point-min) (1+ (point-min))
2744 'header-line header
)
2745 ;; Hide the part of the first line
2746 ;; that is in the header, if it is just part.
2748 ;; Hide the punctuation at the end, too.
2749 (skip-chars-backward " \t,")
2750 (put-text-property (point) header-end
'invisible t
)))))
2751 (goto-char (point-min))
2752 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2754 (let* ((c (preceding-char))
2756 (cond ((= c ?
*) 'Info-title-1-face
)
2757 ((= c ?
=) 'Info-title-2-face
)
2758 ((= c ?-
) 'Info-title-3-face
)
2759 (t 'Info-title-4-face
))))
2760 (put-text-property (match-beginning 1) (match-end 1)
2761 'font-lock-face face
))
2762 ;; This is a serious problem for trying to handle multiple
2763 ;; frame types at once. We want this text to be invisible
2764 ;; on frames that can display the font above.
2765 (when (memq (framep (selected-frame)) '(x pc w32 mac
))
2766 (add-text-properties (match-beginning 2) (1+ (match-end 2))
2768 (goto-char (point-min))
2769 (while (re-search-forward "\\(\\*Note[ \n\t]*\\)\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t
)
2770 (unless (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2771 (let ((start (match-beginning 0))
2773 (hide-tag Info-hide-note-references
)
2776 ;; *Note is often used where *note should have been
2778 (skip-syntax-backward " ")
2781 ((or (<= (point) (point-min))
2782 (memq (char-after (1- (point))) '( ?\. ?
! )))
2784 ((memq (char-after (1- (point))) '( ?\
( ?\
[ ?\
{ ?\
, ?\
; ?\: ))
2789 (add-text-properties (match-beginning 1) (match-end 1)
2791 (add-text-properties (match-beginning 2) (match-end 2)
2792 '(font-lock-face info-xref
2793 mouse-face highlight
2794 help-echo
"mouse-2: go to this node"))
2795 (when (eq Info-hide-note-references t
)
2796 (add-text-properties (match-beginning 3) (match-end 3)
2799 (goto-char (match-beginning 1))
2801 (when (or hide-tag
(eq Info-hide-note-references t
))
2802 (setq paragraph-markers
(cons (set-marker (make-marker) start
)
2803 paragraph-markers
))))))
2805 (let ((fill-nobreak-invisible t
))
2806 (goto-char (point-max))
2807 (while paragraph-markers
2808 (let ((m (car paragraph-markers
)))
2809 (setq paragraph-markers
(cdr paragraph-markers
))
2812 (fill-paragraph nil
)
2813 (backward-paragraph 1))
2814 (set-marker m nil
))))
2816 (goto-char (point-min))
2817 (if (and (search-forward "\n* Menu:" nil t
)
2818 (not (string-match "\\<Index\\>" Info-current-node
))
2819 ;; Don't take time to annotate huge menus
2820 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2823 (while (re-search-forward "^\\* +\\([^:\t\n]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:.][ \t]*\\)" nil t
)
2825 (if (zerop (% n
3)) ; visual aids to help with 1-9 keys
2826 (put-text-property (match-beginning 0)
2827 (1+ (match-beginning 0))
2828 'font-lock-face
'info-menu-5
))
2829 (add-text-properties (match-beginning 1) (match-end 1)
2830 '(font-lock-face info-xref
2831 mouse-face highlight
2832 help-echo
"mouse-2: go to this node"))
2833 (when (eq Info-hide-note-references t
)
2834 (add-text-properties (match-beginning 2) (match-end 2)
2836 (make-string (max 2 (- 22 (- (match-end 1) (match-beginning 1)))) ?
)))
2837 (setq cont
(looking-at "[ \t]*[^\n]")))
2838 (if (eq Info-hide-note-references t
)
2839 (while (and (= (forward-line 1) 0)
2840 (looking-at "\\([ \t]+\\)[^*\n]"))
2841 (add-text-properties (match-beginning 1) (match-end 1)
2842 (list 'display
(make-string (+ 22 (if cont
4 2)) ?
)))
2845 (Info-fontify-menu-headers)
2846 (set-buffer-modified-p nil
)))))
2849 ;; When an Info buffer is killed, make sure the associated tags buffer
2851 (defun Info-kill-buffer ()
2852 (and (eq major-mode
'Info-mode
)
2853 Info-tag-table-buffer
2854 (kill-buffer Info-tag-table-buffer
)))
2856 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
2858 ;;; Speedbar support:
2859 ;; These functions permit speedbar to display the "tags" in the
2860 ;; current info node.
2861 (eval-when-compile (require 'speedbar
))
2863 (defvar Info-speedbar-key-map nil
2864 "Keymap used when in the info display mode.")
2866 (defun Info-install-speedbar-variables ()
2867 "Install those variables used by speedbar to enhance Info."
2868 (if Info-speedbar-key-map
2870 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
2872 ;; Basic tree features
2873 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
2874 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
2875 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
2876 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
2879 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2880 Info-speedbar-key-map
2881 Info-speedbar-hierarchy-buttons
)))
2883 (defvar Info-speedbar-menu-items
2884 '(["Browse Node" speedbar-edit-line t
]
2885 ["Expand Node" speedbar-expand-line
2886 (save-excursion (beginning-of-line)
2887 (looking-at "[0-9]+: *.\\+. "))]
2888 ["Contract Node" speedbar-contract-line
2889 (save-excursion (beginning-of-line)
2890 (looking-at "[0-9]+: *.-. "))]
2892 "Additional menu-items to add to speedbar frame.")
2894 ;; Make sure our special speedbar major mode is loaded
2895 (if (featurep 'speedbar
)
2896 (Info-install-speedbar-variables)
2897 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
2899 ;;; Info hierarchy display method
2901 (defun Info-speedbar-browser ()
2902 "Initialize speedbar to display an info node browser.
2903 This will add a speedbar major display mode."
2906 ;; Make sure that speedbar is active
2907 (speedbar-frame-mode 1)
2908 ;; Now, throw us into Info mode on speedbar.
2909 (speedbar-change-initial-expansion-list "Info")
2912 (eval-when-compile (defvar speedbar-attached-frame
))
2914 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
2915 "Display an Info directory hierarchy in speedbar.
2916 DIRECTORY is the current directory in the attached frame.
2917 DEPTH is the current indentation depth.
2918 NODE is an optional argument that is used to represent the
2919 specific node to expand."
2921 (save-excursion (goto-char (point-min))
2922 (let ((case-fold-search t
))
2923 (looking-at "Info Nodes:"))))
2924 ;; Update our "current node" maybe?
2926 ;; We cannot use the generic list code, that depends on all leaves
2927 ;; being known at creation time.
2929 (speedbar-with-writable (insert "Info Nodes:\n")))
2930 (let ((completions nil
)
2931 (cf (selected-frame)))
2932 (select-frame speedbar-attached-frame
)
2933 (save-window-excursion
2935 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
2938 (speedbar-with-writable
2940 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
2941 (cdr (car completions
))
2942 (car (car completions
))
2943 'Info-speedbar-goto-node
2944 (cdr (car completions
))
2946 (setq completions
(cdr completions
)))
2950 (defun Info-speedbar-goto-node (text node indent
)
2951 "When user clicks on TEXT, go to an info NODE.
2952 The INDENT level is ignored."
2953 (select-frame speedbar-attached-frame
)
2954 (let* ((buff (or (get-buffer "*info*")
2955 (progn (info) (get-buffer "*info*"))))
2956 (bwin (get-buffer-window buff
0)))
2959 (select-window bwin
)
2960 (raise-frame (window-frame bwin
)))
2961 (if speedbar-power-click
2962 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
2963 (select-frame speedbar-attached-frame
)
2964 (switch-to-buffer buff
)))
2965 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
2966 (file (match-string 1 node
))
2967 (node (match-string 2 node
)))
2968 (Info-find-node file node
)
2969 ;; If we do a find-node, and we were in info mode, restore
2970 ;; the old default method. Once we are in info mode, it makes
2971 ;; sense to return to whatever method the user was using before.
2972 (if (string= speedbar-initial-expansion-list-name
"Info")
2973 (speedbar-change-initial-expansion-list
2974 speedbar-previously-used-expansion-list-name
)))))
2976 (defun Info-speedbar-expand-node (text token indent
)
2977 "Expand the node the user clicked on.
2978 TEXT is the text of the button we clicked on, a + or - item.
2979 TOKEN is data related to this node (NAME . FILE).
2980 INDENT is the current indentation depth."
2981 (cond ((string-match "+" text
) ;we have to expand this file
2982 (speedbar-change-expand-button-char ?-
)
2983 (if (speedbar-with-writable
2985 (end-of-line) (forward-char 1)
2986 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
2987 (speedbar-change-expand-button-char ?-
)
2988 (speedbar-change-expand-button-char ??
)))
2989 ((string-match "-" text
) ;we have to contract this node
2990 (speedbar-change-expand-button-char ?
+)
2991 (speedbar-delete-subblock indent
))
2992 (t (error "Ooops... not sure what to do")))
2993 (speedbar-center-buffer-smartly))
2995 (defun Info-speedbar-fetch-file-nodes (nodespec)
2996 "Fetch the subnodes from the info NODESPEC.
2997 NODESPEC is a string of the form: (file)node.
2998 Optional THISFILE represends the filename of"
3000 ;; Set up a buffer we can use to fake-out Info.
3001 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3002 (if (not (equal major-mode
'Info-mode
))
3004 ;; Get the node into this buffer
3005 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
3006 (file (match-string 1 nodespec
))
3007 (node (match-string 2 nodespec
)))
3008 (Info-find-node file node
))
3009 ;; Scan the created buffer
3010 (goto-char (point-min))
3011 (let ((completions nil
)
3012 (case-fold-search t
)
3013 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
3014 (match-string 1 nodespec
))))
3015 ;; Always skip the first one...
3016 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
3017 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
3018 (let ((name (match-string 1)))
3019 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3020 (setq name
(cons name
(match-string 1)))
3021 (if (looking-at " *\\(([^)]+)\\)\\.")
3022 (setq name
(cons name
(concat (match-string 1) "Top")))
3023 (if (looking-at " \\([^.]+\\).")
3025 (cons name
(concat "(" thisfile
")" (match-string 1))))
3026 (setq name
(cons name
(concat "(" thisfile
")" name
))))))
3027 (setq completions
(cons name completions
))))
3028 (nreverse completions
))))
3030 ;;; Info mode node listing
3031 (defun Info-speedbar-buttons (buffer)
3032 "Create a speedbar display to help navigation in an Info file.
3033 BUFFER is the buffer speedbar is requesting buttons for."
3034 (if (save-excursion (goto-char (point-min))
3035 (let ((case-fold-search t
))
3036 (not (looking-at "Info Nodes:"))))
3038 (Info-speedbar-hierarchy-buttons nil
0)
3041 (dolist (mess '("^Node has no Previous$"
3042 "^No menu in this node$"
3043 "^Node has no Next$"
3044 "^No cross-references in this node^"
3046 "^No \".*\" in index$"))
3047 (add-to-list 'debug-ignored-errors mess
))
3051 ;;; info.el ends here