1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99 Free Software
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.
38 (defvar Info-history nil
39 "List of info nodes user has visited.
40 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
42 (defcustom Info-enable-edit nil
43 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
44 This is convenient if you want to write info files by hand.
45 However, we recommend that you not do this.
46 It is better to write a Texinfo file and generate the Info file from that,
47 because that gives you a printed manual as well."
51 (defvar Info-enable-active-nodes nil
52 "Non-nil allows Info to execute Lisp code associated with nodes.
53 The Lisp code is executed when the node is selected.")
54 (put 'Info-enable-active-nodes
'risky-local-variable t
)
56 (defcustom Info-fontify t
57 "*Non-nil enables highlighting and fonts in Info nodes."
62 '((t (:bold t
:italic t
)))
63 "Face for Info node names."
68 "Face for the fifth and tenth `*' in an Info menu."
73 "Face for Info cross-references."
76 (defcustom Info-fontify-maximum-menu-size
30000
77 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
81 (defvar Info-directory-list nil
82 "List of directories to search for Info documentation files.
83 nil means not yet initialized. In this case, Info uses the environment
84 variable INFOPATH to initialize it, or `Info-default-directory-list'
85 if there is no INFOPATH variable in the environment.
86 The last element of `Info-default-directory-list' is the directory
87 where Emacs installs the Info files that come with it.
89 If you run the Emacs executable from the `src' directory in the Emacs
90 source tree, the `info' directory in the source tree is used as the last
91 element, in place of the installation Info directory. This is useful
92 when you run a version of Emacs without installing it.")
94 (defcustom Info-additional-directory-list nil
95 "List of additional directories to search for Info documentation files.
96 These directories are not searched for merging the `dir' file."
97 :type
'(repeat directory
)
100 (defvar Info-current-file nil
101 "Info file that Info is now looking at, or nil.
102 This is the name that was specified in Info, not the actual file name.
103 It doesn't contain directory names or file name extensions added by Info.")
105 (defvar Info-current-subfile nil
106 "Info subfile that is actually in the *info* buffer now,
107 or nil if current info file is not split into subfiles.")
109 (defvar Info-current-node nil
110 "Name of node that Info is now looking at, or nil.")
112 (defvar Info-tag-table-marker nil
113 "Marker pointing at beginning of current Info file's tag table.
114 Marker points nowhere if file has no tag table.")
116 (defvar Info-tag-table-buffer nil
117 "Buffer used for indirect tag tables.")
119 (defvar Info-current-file-completions nil
120 "Cached completion list for current Info file.")
122 (defvar Info-index-alternatives nil
123 "List of possible matches for last Info-index command.")
125 (defvar Info-standalone nil
126 "Non-nil if Emacs was started solely as an Info browser.")
128 (defvar Info-suffix-list
129 ;; The MS-DOS list should work both when long file names are
130 ;; supported (Windows 9X), and when only 8+3 file names are available.
131 (if (eq system-type
'ms-dos
)
132 '( (".gz" .
"gunzip")
136 (".info.Z" .
"gunzip")
137 (".info.gz" .
"gunzip")
138 ("-info.Z" .
"gunzip")
139 ("-info.gz" .
"gunzip")
140 ("/index.gz".
"gunzip")
141 ("/index.z" .
"gunzip")
147 '( (".info.Z".
"uncompress")
148 (".info.Y".
"unyabba")
149 (".info.gz".
"gunzip")
150 (".info.z".
"gunzip")
152 ("-info.Z".
"uncompress")
153 ("-info.Y".
"unyabba")
154 ("-info.gz".
"gunzip")
155 ("-info.z".
"gunzip")
157 ("/index.Z".
"uncompress")
158 ("/index.Y".
"unyabba")
159 ("/index.gz".
"gunzip")
160 ("/index.z".
"gunzip")
167 "List of file name suffixes and associated decoding commands.
168 Each entry should be (SUFFIX . STRING); the file is given to
169 the command as standard input. If STRING is nil, no decoding is done.
170 Because the SUFFIXes are tried in order, the empty string should
171 be last in the list.")
173 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
174 ;; First, on ms-dos, delete some of the extension in FILENAME
176 (defun info-insert-file-contents-1 (filename suffix
)
177 (if (not (eq system-type
'ms-dos
))
178 (concat filename suffix
)
179 (let* ((sans-exts (file-name-sans-extension filename
))
180 ;; How long is the extension in FILENAME (not counting the dot).
181 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
183 ;; SUFFIX starts with a dot. If FILENAME already has one,
184 ;; get rid of the one in SUFFIX (unless suffix is empty).
185 (or (and (<= ext-len
0)
186 (not (eq (aref filename
(1- (length filename
))) ?.
)))
187 (= (length suffix
) 0)
188 (setq suffix
(substring suffix
1)))
189 ;; How many chars of that extension should we keep?
190 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
191 ;; Get rid of the rest of the extension, and add SUFFIX.
192 (concat (substring filename
0 (- (length filename
)
193 (- ext-len ext-left
)))
196 (defun info-file-exists-p (filename)
197 (and (file-exists-p filename
)
198 (not (file-directory-p filename
))))
200 (defun info-insert-file-contents (filename &optional visit
)
201 "Insert the contents of an info file in the current buffer.
202 Do the right thing if the file has been compressed or zipped."
203 (let ((tail Info-suffix-list
)
205 (if (file-exists-p filename
)
206 ;; FILENAME exists--see if that name contains a suffix.
207 ;; If so, set DECODE accordingly.
211 (concat (regexp-quote (car (car tail
))) "$")
213 (setq tail
(cdr tail
)))
214 (setq fullname filename
215 decoder
(cdr (car tail
))))
216 ;; Try adding suffixes to FILENAME and see if we can find something.
218 (not (info-file-exists-p (info-insert-file-contents-1
219 filename
(car (car tail
))))))
220 (setq tail
(cdr tail
)))
221 ;; If we found a file with a suffix, set DECODER according to the suffix
222 ;; and set FULLNAME to the file's actual name.
223 (setq fullname
(info-insert-file-contents-1 filename
(car (car tail
)))
224 decoder
(cdr (car tail
)))
226 (error "Can't find %s or any compressed version of it" filename
)))
227 ;; check for conflict with jka-compr
228 (if (and (featurep 'jka-compr
)
229 (jka-compr-installed-p)
230 (jka-compr-get-compression-info fullname
))
234 (insert-file-contents-literally fullname visit
)
235 (let ((buffer-read-only nil
)
236 (coding-system-for-write 'no-conversion
)
237 (default-directory (or (file-name-directory fullname
)
239 (call-process-region (point-min) (point-max) decoder t t
)))
240 (insert-file-contents fullname visit
))))
242 ;; Initialize Info-directory-list, if that hasn't been done yet.
243 (defun info-initialize ()
244 (unless Info-directory-list
245 (let ((path (getenv "INFOPATH"))
246 (source (expand-file-name "info/" source-directory
))
247 (sibling (if installation-directory
248 (expand-file-name "info/" installation-directory
)))
250 (setq Info-directory-list
252 (split-string path
(regexp-quote path-separator
))
253 (if (and sibling
(file-exists-p sibling
))
254 ;; Uninstalled, Emacs builddir != srcdir.
255 (setq alternative sibling
)
256 ;; Uninstalled, builddir == srcdir
257 (setq alternative source
))
258 (if (or (member alternative Info-default-directory-list
)
259 (not (file-exists-p alternative
))
260 ;; On DOS/NT, we use movable executables always,
261 ;; and we must always find the Info dir at run time.
262 (if (memq system-type
'(ms-dos windows-nt
))
264 ;; Use invocation-directory for Info
265 ;; only if we used it for exec-directory also.
266 (not (string= exec-directory
267 (expand-file-name "lib-src/"
268 installation-directory
)))))
269 Info-default-directory-list
270 ;; `alternative' contains the Info files that came with this
271 ;; version, so we should look there first. `Info-insert-dir'
272 ;; currently expects to find `alternative' first on the list.
274 (reverse (cdr (reverse Info-default-directory-list
))))))))))
277 (defun info-other-window (&optional file
)
278 "Like `info' but show the Info buffer in another window."
279 (interactive (if current-prefix-arg
280 (list (read-file-name "Info file name: " nil nil t
))))
281 (let (same-window-buffer-names)
284 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
287 (defun info (&optional file
)
288 "Enter Info, the documentation browser.
289 Optional argument FILE specifies the file to examine;
290 the default is the top-level directory of Info.
292 In interactive use, a prefix argument directs this command
293 to read a file name from the minibuffer.
295 The search path for Info files is in the variable `Info-directory-list'.
296 The top-level Info directory is made by combining all the files named `dir'
297 in all the directories in that path."
298 (interactive (if current-prefix-arg
299 (list (read-file-name "Info file name: " nil nil t
))))
302 (pop-to-buffer "*info*")
303 ;; If argument already contains parentheses, don't add another set
304 ;; since the argument will then be parsed improperly. This also
305 ;; has the added benefit of allowing node names to be included
306 ;; following the parenthesized filename.
307 (if (and (stringp file
) (string-match "(.*)" file
))
308 (Info-goto-node file
)
309 (Info-goto-node (concat "(" file
")"))))
310 (if (get-buffer "*info*")
311 (pop-to-buffer "*info*")
315 (defun info-standalone ()
316 "Run Emacs as a standalone Info reader.
317 Usage: emacs -f info-standalone [filename]
318 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
319 (setq Info-standalone t
)
320 (if (and command-line-args-left
321 (not (string-match "^-" (car command-line-args-left
))))
324 (info (car command-line-args-left
))
325 (setq command-line-args-left
(cdr command-line-args-left
)))
326 (error (send-string-to-terminal
327 (format "%s\n" (if (eq (car-safe err
) 'error
)
329 (save-buffers-kill-emacs)))
332 ;; See if the the accessible portion of the buffer begins with a node
333 ;; delimiter, and the node header line which follows matches REGEXP.
334 ;; Typically, this test will be followed by a loop that examines the
335 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
336 ;; to have the overhead of this special test inside the loop.
338 ;; This function changes match-data, but supposedly the caller might
339 ;; want to use the results of re-search-backward.
341 ;; The return value is the value of point at the beginning of matching
342 ;; REGERXP, if the function succeeds, nil otherwise.
343 (defun Info-node-at-bob-matching (regexp)
344 (and (bobp) ; are we at beginning of buffer?
345 (looking-at "\^_") ; does it begin with node delimiter?
349 (forward-line 1) ; does the line after delimiter match REGEXP?
350 (re-search-backward regexp beg t
))))
352 ;; Go to an info node specified as separate filename and nodename.
353 ;; no-going-back is non-nil if recovering from an error in this function;
354 ;; it says do not attempt further (recursive) error recovery.
355 (defun Info-find-node (filename nodename
&optional no-going-back
)
357 ;; Convert filename to lower case if not found as specified.
360 (let (temp temp-downcase found
)
361 (setq filename
(substitute-in-file-name filename
))
362 (if (string= (downcase filename
) "dir")
364 (let ((dirs (if (string-match "^\\./" filename
)
365 ;; If specified name starts with `./'
366 ;; then just try current directory.
368 (if (file-name-absolute-p filename
)
369 ;; No point in searching for an
370 ;; absolute file name
372 (if Info-additional-directory-list
373 (append Info-directory-list
374 Info-additional-directory-list
)
375 Info-directory-list
)))))
376 ;; Search the directory list for file FILENAME.
377 (while (and dirs
(not found
))
378 (setq temp
(expand-file-name filename
(car dirs
)))
380 (expand-file-name (downcase filename
) (car dirs
)))
381 ;; Try several variants of specified name.
382 (let ((suffix-list Info-suffix-list
))
383 (while (and suffix-list
(not found
))
384 (cond ((info-file-exists-p
385 (info-insert-file-contents-1
386 temp
(car (car suffix-list
))))
389 (info-insert-file-contents-1
390 temp-downcase
(car (car suffix-list
))))
391 (setq found temp-downcase
)))
392 (setq suffix-list
(cdr suffix-list
))))
393 (setq dirs
(cdr dirs
)))))
395 (setq filename found
)
396 (error "Info file %s does not exist" filename
))))
397 ;; Record the node we are leaving.
398 (if (and Info-current-file
(not no-going-back
))
400 (cons (list Info-current-file Info-current-node
(point))
402 ;; Go into info buffer.
403 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
404 (buffer-disable-undo (current-buffer))
405 (or (eq major-mode
'Info-mode
)
408 (setq Info-current-node nil
)
410 ;; Bind case-fold-search in case the user sets it to nil.
411 (let ((case-fold-search t
)
413 ;; Switch files if necessary
415 (equal Info-current-file filename
)
416 (let ((buffer-read-only nil
))
417 (setq Info-current-file nil
418 Info-current-subfile nil
419 Info-current-file-completions nil
420 buffer-file-name nil
)
424 (info-insert-file-contents filename t
)
425 (setq default-directory
(file-name-directory filename
)))
426 (set-buffer-modified-p nil
)
427 ;; See whether file has a tag table. Record the location if yes.
428 (goto-char (point-max))
430 ;; Use string-equal, not equal, to ignore text props.
431 (if (not (or (string-equal nodename
"*")
433 (search-forward "\^_\nEnd tag table\n" nil t
))))
435 ;; We have a tag table. Find its beginning.
436 ;; Is this an indirect file?
437 (search-backward "\nTag table:\n")
441 (looking-at "(Indirect)\n"))
442 ;; It is indirect. Copy it to another buffer
443 ;; and record that the tag table is in that buffer.
444 (let ((buf (current-buffer))
446 (or Info-tag-table-buffer
447 (generate-new-buffer " *info tag table*"))))
448 (setq Info-tag-table-buffer tagbuf
)
451 (buffer-disable-undo (current-buffer))
452 (setq case-fold-search t
)
454 (insert-buffer-substring buf
))
455 (set-marker Info-tag-table-marker
456 (match-end 0) tagbuf
))
457 (set-marker Info-tag-table-marker pos
)))
458 (set-marker Info-tag-table-marker nil
))
459 (setq Info-current-file
460 (if (eq filename t
) "dir" filename
))))
461 ;; Use string-equal, not equal, to ignore text props.
462 (if (string-equal nodename
"*")
463 (progn (setq Info-current-node nodename
)
464 (Info-set-mode-line))
467 ;; 1. Anchor found in tag table
468 ;; 2. Anchor *not* in tag table
470 ;; 3. Node found in tag table
471 ;; 4. Node *not* found in tag table, but found in file
472 ;; 5. Node *not* in tag table, and *not* in file
474 ;; *Or* the same, but in an indirect subfile.
476 ;; Search file for a suitable node.
477 (let ((guesspos (point-min))
479 (concat "\\(Node:\\|Ref:\\) *\\("
480 (regexp-quote nodename
)
484 ;; First, search a tag table, if any
485 (if (marker-position Info-tag-table-marker
)
486 (let ((found-in-tag-table t
)
489 (m Info-tag-table-marker
))
491 (set-buffer (marker-buffer m
))
493 (beginning-of-line) ; so re-search will work.
497 (while (re-search-forward regexp nil t
)
499 (string-equal "Ref:" (match-string 1)))
500 (or nodepos
(setq nodepos
(point))
501 (if (string-equal (match-string 2) nodename
)
505 (setq found-in-tag-table nil
)))
506 (if found-in-tag-table
507 (setq guesspos
(1+ (read (current-buffer)))))
508 (setq found-mode major-mode
))
510 ;; Indirect file among split files
511 (if found-in-tag-table
513 ;; If this is an indirect file, determine
514 ;; which file really holds this node and
516 (if (not (eq found-mode
'Info-mode
))
517 ;; Note that the current buffer must be
518 ;; the *info* buffer on entry to
519 ;; Info-read-subfile. Thus the hackery
521 (setq guesspos
(Info-read-subfile guesspos
)))))
525 (goto-char (setq anchorpos guesspos
))
527 ;; Else we may have a node, which we search for:
528 (goto-char (max (point-min)
529 (- (byte-to-position guesspos
) 1000)))
530 ;; Now search from our advised position
531 ;; (or from beg of buffer)
532 ;; to find the actual node.
533 ;; First, check whether the node is right
534 ;; where we are, in case the buffer begins
537 (or (Info-node-at-bob-matching regexp
)
539 (while (search-forward "\n\^_" nil t
)
543 (if (re-search-backward regexp beg t
)
544 (if (string-equal (match-string 2) nodename
)
549 (setq nodepos
(point)))))))
555 "No such anchor in tag table or node in tag table or file: %s"
557 (goto-char (max (point-min) (- guesspos
1000)))
558 ;; Now search from our advised position (or from beg of buffer)
559 ;; to find the actual node.
560 ;; First, check whether the node is right where we are, in case
561 ;; the buffer begins with a node.
563 (or (Info-node-at-bob-matching regexp
)
565 (while (search-forward "\n\^_" nil t
)
569 (if (re-search-backward regexp beg t
)
570 (if (string-equal (match-string 2) nodename
)
573 (setq nodepos
(point)))))))
576 (error "No such node: %s" nodename
))))))
578 (goto-char (or anchorpos
(point-min)))))
579 ;; If we did not finish finding the specified node,
580 ;; go back to the previous one.
581 (or Info-current-node no-going-back
(null Info-history
)
582 (let ((hist (car Info-history
)))
583 (setq Info-history
(cdr Info-history
))
584 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
585 (goto-char (nth 2 hist
))))))
587 ;; Cache the contents of the (virtual) dir file, once we have merged
588 ;; it for the first time, so we can save time subsequently.
589 (defvar Info-dir-contents nil
)
591 ;; Cache for the directory we decided to use for the default-directory
592 ;; of the merged dir text.
593 (defvar Info-dir-contents-directory nil
)
595 ;; Record the file attributes of all the files from which we
596 ;; constructed Info-dir-contents.
597 (defvar Info-dir-file-attributes nil
)
599 (defvar Info-dir-file-name nil
)
601 ;; Construct the Info directory node by merging the files named `dir'
602 ;; from various directories. Set the *info* buffer's
603 ;; default-directory to the first directory we actually get any text
605 (defun Info-insert-dir ()
606 (if (and Info-dir-contents Info-dir-file-attributes
607 ;; Verify that none of the files we used has changed
610 (mapcar '(lambda (elt)
611 (let ((curr (file-attributes
613 (file-truename (car elt
)))))
615 ;; Don't compare the access time.
616 (if curr
(setcar (nthcdr 4 curr
) 0))
617 (setcar (nthcdr 4 (cdr elt
)) 0)
618 (equal (cdr elt
) curr
)))
619 Info-dir-file-attributes
))))
621 (insert Info-dir-contents
)
622 (goto-char (point-min)))
623 (let ((dirs Info-directory-list
)
624 ;; Bind this in case the user sets it to nil.
626 ;; This is set non-nil if we find a problem in some input files.
628 buffers buffer others nodes dirs-done
)
630 (setq Info-dir-file-attributes nil
)
632 ;; Search the directory list for the directory file.
634 (let ((truename (file-truename (expand-file-name (car dirs
)))))
635 (or (member truename dirs-done
)
636 (member (directory-file-name truename
) dirs-done
)
637 ;; Try several variants of specified name.
638 ;; Try upcasing, appending `.info', or both.
642 (progn (setq file
(expand-file-name "dir" truename
))
643 (file-attributes file
))
644 (progn (setq file
(expand-file-name "DIR" truename
))
645 (file-attributes file
))
646 (progn (setq file
(expand-file-name "dir.info" truename
))
647 (file-attributes file
))
648 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
649 (file-attributes file
)))))
652 (cons (directory-file-name truename
)
657 (message "Composing main Info directory..."))
658 (set-buffer (generate-new-buffer " info dir"))
661 (insert-file-contents file
)
662 (make-local-variable 'Info-dir-file-name
)
663 (setq Info-dir-file-name file
)
664 (setq buffers
(cons (current-buffer) buffers
)
665 Info-dir-file-attributes
666 (cons (cons file attrs
)
667 Info-dir-file-attributes
)))
668 (error (kill-buffer (current-buffer))))))))
669 (or (cdr dirs
) (setq Info-dir-contents-directory
670 (file-name-as-directory (car dirs
))))
671 (setq dirs
(cdr dirs
))))
674 (error "Can't find the Info directory node"))
675 ;; Distinguish the dir file that comes with Emacs from all the
676 ;; others. Yes, that is really what this is supposed to do.
677 ;; The definition of `Info-directory-list' puts it first on that
678 ;; list and so last in `buffers' at this point.
679 (setq buffer
(car (last buffers
))
680 others
(delq buffer buffers
))
682 ;; Insert the entire original dir file as a start; note that we've
683 ;; already saved its default directory to use as the default
684 ;; directory for the whole concatenation.
685 (insert-buffer buffer
)
687 ;; Look at each of the other buffers one by one.
689 (let ((other (car others
))
691 ;; In each, find all the menus.
694 (goto-char (point-min))
695 ;; Find each menu, and add an elt to NODES for it.
696 (while (re-search-forward "^\\* Menu:" nil t
)
697 (let (beg nodename end
)
700 (or (search-backward "\n\^_" nil
'move
)
702 (signal 'search-failed
(list "\n\^_")))
703 (search-forward "Node: ")
704 (setq nodename
(Info-following-node-name))
705 (search-forward "\n\^_" nil
'move
)
708 (setq this-buffer-nodes
709 (cons (list nodename other beg end
)
710 this-buffer-nodes
))))
711 (if (assoc-ignore-case "top" this-buffer-nodes
)
712 (setq nodes
(nconc this-buffer-nodes nodes
))
714 (message "No `top' node in %s" Info-dir-file-name
))))
715 (setq others
(cdr others
)))
716 ;; Add to the main menu a menu item for each other node.
717 (re-search-forward "^\\* Menu:")
719 (let ((menu-items '("top"))
722 (end (save-excursion (search-forward "\^_" nil t
) (point))))
724 (let ((nodename (car (car nodes
))))
726 (or (member (downcase nodename
) menu-items
)
727 (re-search-forward (concat "^\\* +"
728 (regexp-quote nodename
)
732 (insert "* " nodename
"::" "\n")
733 (setq menu-items
(cons nodename menu-items
))))))
734 (setq nodes
(cdr nodes
))))
735 ;; Now take each node of each of the other buffers
736 ;; and merge it into the main buffer.
738 (let ((nodename (car (car nodes
))))
739 (goto-char (point-min))
740 ;; Find the like-named node in the main buffer.
741 (if (re-search-forward (concat "^\^_.*\n.*Node: "
742 (regexp-quote nodename
)
746 (search-forward "\n\^_" nil
'move
)
749 ;; If none exists, add one.
750 (goto-char (point-max))
751 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
752 ;; Merge the text from the other buffer's menu
753 ;; into the menu in the like-named node in the main buffer.
754 (apply 'insert-buffer-substring
(cdr (car nodes
))))
755 (setq nodes
(cdr nodes
)))
756 ;; Kill all the buffers we just made.
758 (kill-buffer (car buffers
))
759 (setq buffers
(cdr buffers
)))
760 (goto-char (point-min))
762 (message "Composing main Info directory...problems encountered, see `*Messages*'")
763 (message "Composing main Info directory...done")))
764 (setq Info-dir-contents
(buffer-string)))
765 (setq default-directory Info-dir-contents-directory
))
767 ;; Note that on entry to this function the current-buffer must be the
768 ;; *info* buffer; not the info tags buffer.
769 (defun Info-read-subfile (nodepos)
770 ;; NODEPOS is either a position (in the Info file as a whole,
771 ;; not relative to a subfile) or the name of a subfile.
774 (if (numberp nodepos
)
776 (set-buffer (marker-buffer Info-tag-table-marker
))
777 (goto-char (point-min))
778 (or (looking-at "\^_")
779 (search-forward "\n\^_"))
782 (while (not (looking-at "\^_"))
785 thisfilepos thisfilename
)
786 (search-forward ": ")
787 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
788 (setq thisfilepos
(read (current-buffer)))
789 ;; read in version 19 stops at the end of number.
790 ;; Advance to the next line.
792 (if (> thisfilepos nodepos
)
794 (setq lastfilename thisfilename
)
795 (setq lastfilepos thisfilepos
))
797 (setq lastfilename nodepos
)
798 (setq lastfilepos
0))
799 ;; Assume previous buffer is in Info-mode.
800 ;; (set-buffer (get-buffer "*info*"))
801 (or (equal Info-current-subfile lastfilename
)
802 (let ((buffer-read-only nil
))
803 (setq buffer-file-name nil
)
806 (info-insert-file-contents lastfilename
)
807 (set-buffer-modified-p nil
)
808 (setq Info-current-subfile lastfilename
)))
809 (goto-char (point-min))
810 (if (looking-at "\^_")
812 (search-forward "\n\^_"))
813 (if (numberp nodepos
)
814 (+ (- nodepos lastfilepos
) (point)))))
816 ;; Select the info node that point is in.
817 (defun Info-select-node ()
818 ;; Bind this in case the user sets it to nil.
819 (let ((case-fold-search t
))
821 ;; Find beginning of node.
822 (if (search-backward "\n\^_" nil
'move
)
824 (if (looking-at "\^_")
826 (signal 'search-failed
(list "\n\^_"))))
827 ;; Get nodename spelled as it is in the node.
828 (re-search-forward "Node:[ \t]*")
829 (setq Info-current-node
830 (buffer-substring-no-properties (point)
832 (skip-chars-forward "^,\t\n")
835 ;; Find the end of it, and narrow.
837 (let (active-expression)
838 (narrow-to-region (point)
839 (if (re-search-forward "\n[\^_\f]" nil t
)
842 (if (looking-at "[\n\^_\f]*execute: ")
844 (goto-char (match-end 0))
845 (setq active-expression
846 (read (current-buffer))))))
848 (if Info-enable-active-nodes
(eval active-expression
))
849 (if Info-fontify
(Info-fontify-node))
850 (run-hooks 'Info-selection-hook
)))))
852 (defun Info-set-mode-line ()
853 (setq mode-line-buffer-identification
856 (if Info-current-file
857 (file-name-nondirectory Info-current-file
)
860 (or Info-current-node
""))))
862 ;; Go to an info node specified with a filename-and-nodename string
863 ;; of the sort that is found in pointers in nodes.
865 (defun Info-goto-node (nodename)
866 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
867 (interactive (list (Info-read-node-name "Goto node: ")))
870 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
872 (setq filename
(if (= (match-beginning 1) (match-end 1))
874 (substring nodename
(match-beginning 2) (match-end 2)))
875 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
876 (let ((trim (string-match "\\s *\\'" filename
)))
877 (if trim
(setq filename
(substring filename
0 trim
))))
878 (let ((trim (string-match "\\s *\\'" nodename
)))
879 (if trim
(setq nodename
(substring nodename
0 trim
))))
880 (if transient-mark-mode
(deactivate-mark))
881 (Info-find-node (if (equal filename
"") nil filename
)
882 (if (equal nodename
"") "Top" nodename
))))
884 (defvar Info-read-node-completion-table
)
886 ;; This function is used as the "completion table" while reading a node name.
887 ;; It does completion using the alist in Info-read-node-completion-table
888 ;; unless STRING starts with an open-paren.
889 (defun Info-read-node-name-1 (string predicate code
)
890 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
894 (try-completion string Info-read-node-completion-table predicate
)))
898 (all-completions string Info-read-node-completion-table predicate
)))
902 (assoc string Info-read-node-completion-table
))))))
904 (defun Info-read-node-name (prompt &optional default
)
905 (let* ((completion-ignore-case t
)
906 (Info-read-node-completion-table (Info-build-node-completions))
907 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
908 (if (equal nodename
"")
910 (Info-read-node-name prompt
))
913 (defun Info-build-node-completions ()
914 (or Info-current-file-completions
916 ;; Bind this in case the user sets it to nil.
918 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
921 (if (marker-buffer Info-tag-table-marker
)
922 (let ((marker Info-tag-table-marker
))
923 (set-buffer (marker-buffer marker
))
926 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
928 (cons (list (buffer-substring (match-beginning 1)
932 (goto-char (point-min))
933 ;; If the buffer begins with a node header, process that first.
934 (if (Info-node-at-bob-matching node-regexp
)
935 (setq compl
(list (buffer-substring (match-beginning 1)
937 ;; Now for the rest of the nodes.
938 (while (search-forward "\n\^_" nil t
)
942 (if (re-search-backward node-regexp beg t
)
944 (cons (list (buffer-substring (match-beginning 1)
947 (setq Info-current-file-completions compl
))))
949 (defun Info-restore-point (hl)
950 "If this node has been visited, restore the point value when we left."
952 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
953 ;; Use string-equal, not equal, to ignore text props.
954 (string-equal (nth 1 (car hl
)) Info-current-node
))
956 (goto-char (nth 2 (car hl
)))
957 (setq hl nil
)) ;terminate the while at next iter
958 (setq hl
(cdr hl
)))))
960 (defvar Info-last-search nil
961 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
963 (defun Info-search (regexp)
964 "Search for REGEXP, starting from point, and select node it's found in."
965 (interactive "sSearch (regexp): ")
966 (if transient-mark-mode
(deactivate-mark))
967 (if (equal regexp
"")
968 (setq regexp Info-last-search
)
969 (setq Info-last-search regexp
))
971 (let ((found ()) current
972 (onode Info-current-node
)
973 (ofile Info-current-file
)
975 (ostart (window-start))
976 (osubfile Info-current-subfile
))
980 (if (null Info-current-subfile
)
981 (progn (re-search-forward regexp
) (setq found
(point)))
983 (progn (re-search-forward regexp
) (setq found
(point)))
984 (search-failed nil
)))))
985 (if (not found
) ;can only happen in subfile case -- else would have erred
989 (set-buffer (marker-buffer Info-tag-table-marker
))
990 (goto-char (point-min))
991 (search-forward "\n\^_\nIndirect:")
993 (narrow-to-region (point)
994 (progn (search-forward "\n\^_")
996 (goto-char (point-min))
997 (search-forward (concat "\n" osubfile
": "))
1000 (re-search-forward "\\(^.*\\): [0-9]+$")
1001 (goto-char (+ (match-end 1) 2))
1002 (setq list
(cons (cons (read (current-buffer))
1004 (match-beginning 1) (match-end 1)))
1006 (goto-char (1+ (match-end 0))))
1007 (setq list
(nreverse list
)
1008 current
(car (car list
))
1011 (message "Searching subfile %s..." (cdr (car list
)))
1012 (Info-read-subfile (car (car list
)))
1013 (setq list
(cdr list
))
1014 ;;; (goto-char (point-min))
1015 (if (re-search-forward regexp nil t
)
1016 (setq found
(point) list
())))
1019 (signal 'search-failed
(list regexp
))))
1021 (progn (Info-read-subfile osubfile
)
1024 (set-window-start (selected-window) ostart
)))))
1028 ;; Use string-equal, not equal, to ignore text props.
1029 (or (and (string-equal onode Info-current-node
)
1030 (equal ofile Info-current-file
))
1031 (setq Info-history
(cons (list ofile onode opoint
)
1034 ;; Extract the value of the node-pointer named NAME.
1035 ;; If there is none, use ERRORNAME in the error message;
1036 ;; if ERRORNAME is nil, just return nil.
1037 (defun Info-extract-pointer (name &optional errorname
)
1038 ;; Bind this in case the user sets it to nil.
1039 (let ((case-fold-search t
))
1041 (goto-char (point-min))
1043 (if (re-search-backward (concat name
":") nil t
)
1045 (goto-char (match-end 0))
1046 (Info-following-node-name))
1047 (if (eq errorname t
)
1049 (error "Node has no %s" (capitalize (or errorname name
))))))))
1051 ;; Return the node name in the buffer following point.
1052 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1053 ;; saying which chars may appear in the node name.
1054 (defun Info-following-node-name (&optional allowedchars
)
1055 (skip-chars-forward " \t")
1056 (buffer-substring-no-properties
1059 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
1060 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
1061 (if (looking-at "(")
1062 (skip-chars-forward "^)")))
1063 (skip-chars-backward " ")
1067 "Go to the next node of this node."
1069 (Info-goto-node (Info-extract-pointer "next")))
1072 "Go to the previous node of this node."
1074 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1076 (defun Info-up (&optional same-file
)
1077 "Go to the superior node of this node.
1078 If SAME-FILE is non-nil, do not move to a different Info file."
1080 (let ((node (Info-extract-pointer "up")))
1082 (string-match "^(" node
)
1083 (error "Up node is in another Info file"))
1084 (Info-goto-node node
))
1085 (Info-restore-point Info-history
))
1088 "Go back to the last node visited."
1091 (error "This is the first Info node you looked at"))
1092 (let (filename nodename opoint
)
1093 (setq filename
(car (car Info-history
)))
1094 (setq nodename
(car (cdr (car Info-history
))))
1095 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1096 (setq Info-history
(cdr Info-history
))
1097 (Info-find-node filename nodename
)
1098 (setq Info-history
(cdr Info-history
))
1099 (goto-char opoint
)))
1101 (defun Info-directory ()
1102 "Go to the Info directory node."
1104 (Info-find-node "dir" "top"))
1106 (defun Info-follow-reference (footnotename)
1107 "Follow cross reference named NAME to the node it refers to.
1108 NAME may be an abbreviation of the reference name."
1110 (let ((completion-ignore-case t
)
1111 (case-fold-search t
)
1112 completions default alt-default
(start-point (point)) str i bol eol
)
1114 ;; Store end and beginning of line.
1120 (goto-char (point-min))
1121 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1122 (setq str
(buffer-substring
1125 ;; See if this one should be the default.
1127 (<= (match-beginning 0) start-point
)
1128 (<= start-point
(point))
1130 ;; See if this one should be the alternate default.
1131 (and (null alt-default
)
1132 (and (<= bol
(match-beginning 0))
1134 (setq alt-default t
))
1136 (while (setq i
(string-match "[ \n\t]+" str i
))
1137 (setq str
(concat (substring str
0 i
) " "
1138 (substring str
(match-end 0))))
1140 ;; Record as a completion and perhaps as default.
1141 (if (eq default t
) (setq default str
))
1142 (if (eq alt-default t
) (setq alt-default str
))
1143 ;; Don't add this string if it's a duplicate.
1144 ;; We use a loop instead of "(assoc str completions)" because
1145 ;; we want to do a case-insensitive compare.
1146 (let ((tail completions
)
1147 (tem (downcase str
)))
1149 (not (string-equal tem
(downcase (car (car tail
))))))
1150 (setq tail
(cdr tail
)))
1153 (cons (cons str nil
)
1155 ;; If no good default was found, try an alternate.
1157 (setq default alt-default
))
1158 ;; If only one cross-reference found, then make it default.
1159 (if (eq (length completions
) 1)
1160 (setq default
(car (car completions
))))
1162 (let ((input (completing-read (if default
1163 (concat "Follow reference named: ("
1165 "Follow reference named: ")
1166 completions nil t
)))
1167 (list (if (equal input
"")
1169 (error "No cross-references in this node"))))
1171 (unless footnotename
1172 (error "No reference was specified"))
1174 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
)))
1175 (case-fold-search t
))
1176 (while (setq i
(string-match " " str i
))
1177 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1180 (goto-char (point-min))
1181 (or (re-search-forward str nil t
)
1182 (error "No cross-reference named %s" footnotename
))
1183 (goto-char (+ (match-beginning 0) 5))
1185 (Info-extract-menu-node-name "Bad format cross reference" t
)))
1186 (while (setq i
(string-match "[ \t\n]+" target i
))
1187 (setq target
(concat (substring target
0 i
) " "
1188 (substring target
(match-end 0))))
1190 (Info-goto-node target
)))
1192 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
1193 (skip-chars-forward " \t\n")
1196 (skip-chars-forward "^:")
1199 (if (looking-at ":")
1200 (buffer-substring-no-properties beg
(1- (point)))
1201 (skip-chars-forward " \t\n")
1202 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
1203 (while (setq i
(string-match "\n" str i
))
1205 ;; Collapse multiple spaces.
1206 (while (string-match " +" str
)
1207 (setq str
(replace-match " " t t str
)))
1210 ;; No one calls this.
1211 ;;(defun Info-menu-item-sequence (list)
1213 ;; (Info-menu (car list))
1214 ;; (setq list (cdr list))))
1216 (defvar Info-complete-menu-buffer
)
1218 (defun Info-complete-menu-item (string predicate action
)
1219 (let ((case-fold-search t
))
1220 (cond ((eq action nil
)
1222 (pattern (concat "\n\\* +\\("
1223 (regexp-quote string
)
1226 (set-buffer Info-complete-menu-buffer
)
1227 (goto-char (point-min))
1228 (search-forward "\n* Menu:")
1229 (while (re-search-forward pattern nil t
)
1230 (setq completions
(cons (cons (format "%s"
1234 (match-beginning 1))
1236 (try-completion string completions predicate
)))
1239 (pattern (concat "\n\\* +\\("
1240 (regexp-quote string
)
1243 (set-buffer Info-complete-menu-buffer
)
1244 (goto-char (point-min))
1245 (search-forward "\n* Menu:")
1246 (while (re-search-forward pattern nil t
)
1247 (setq completions
(cons (cons (format "%s"
1251 (match-beginning 1))
1253 (all-completions string completions predicate
)))
1256 (set-buffer Info-complete-menu-buffer
)
1257 (goto-char (point-min))
1258 (search-forward "\n* Menu:")
1259 (re-search-forward (concat "\n\\* +"
1260 (regexp-quote string
)
1265 (defun Info-menu (menu-item)
1266 "Go to node for menu item named (or abbreviated) NAME.
1267 Completion is allowed, and the menu item point is on is the default."
1269 (let ((completions '())
1270 ;; If point is within a menu item, use that item as the default
1276 (goto-char (point-min))
1277 (if (not (search-forward "\n* menu:" nil t
))
1278 (error "No menu in this node"))
1284 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t
)
1285 (setq default
(format "%s" (buffer-substring
1287 (match-end 1))))))))
1290 (setq item
(let ((completion-ignore-case t
)
1291 (Info-complete-menu-buffer (current-buffer)))
1292 (completing-read (if default
1293 (format "Menu item (default %s): "
1296 'Info-complete-menu-item nil t
)))
1297 ;; we rely on the fact that completing-read accepts an input
1298 ;; of "" even when the require-match argument is true and ""
1299 ;; is not a valid possibility
1300 (if (string= item
"")
1306 ;; there is a problem here in that if several menu items have the same
1307 ;; name you can only go to the node of the first with this command.
1308 (Info-goto-node (Info-extract-menu-item menu-item
)))
1310 (defun Info-extract-menu-item (menu-item)
1311 (setq menu-item
(regexp-quote menu-item
))
1312 (let ((case-fold-search t
))
1314 (goto-char (point-min))
1315 (or (search-forward "\n* menu:" nil t
)
1316 (error "No menu in this node"))
1317 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1318 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1319 (error "No such item in menu"))
1322 (Info-extract-menu-node-name))))
1324 ;; If COUNT is nil, use the last item in the menu.
1325 (defun Info-extract-menu-counting (count)
1326 (let ((case-fold-search t
))
1328 (goto-char (point-min))
1329 (or (search-forward "\n* menu:" nil t
)
1330 (error "No menu in this node"))
1332 (or (search-forward "\n* " nil t count
)
1333 (error "Too few items in menu"))
1334 (while (search-forward "\n* " nil t
)
1336 (Info-extract-menu-node-name))))
1338 (defun Info-nth-menu-item ()
1339 "Go to the node of the Nth menu item.
1340 N is the digit argument used to invoke this command."
1343 (Info-extract-menu-counting
1344 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1346 (defun Info-top-node ()
1347 "Go to the Top node of this file."
1349 (Info-goto-node "Top"))
1351 (defun Info-final-node ()
1352 "Go to the final node in this file."
1354 (Info-goto-node "Top")
1356 ;; Go to the last node in the menu of Top.
1357 (Info-goto-node (Info-extract-menu-counting nil
))
1358 ;; If the last node in the menu is not last in pointer structure,
1359 ;; move forward until we can't go any farther.
1360 (while (Info-forward-node t t
) nil
)
1361 ;; Then keep moving down to last subnode, unless we reach an index.
1362 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1363 (save-excursion (search-forward "\n* Menu:" nil t
)))
1364 (Info-goto-node (Info-extract-menu-counting nil
)))))
1366 (defun Info-forward-node (&optional not-down no-error
)
1367 "Go forward one node, considering all nodes as forming one sequence."
1369 (goto-char (point-min))
1371 ;; three possibilities, in order of priority:
1372 ;; 1. next node is in a menu in this node (but not in an index)
1373 ;; 2. next node is next at same level
1374 ;; 3. next node is up and next
1375 (cond ((and (not not-down
)
1376 (save-excursion (search-forward "\n* menu:" nil t
))
1377 (not (string-match "\\<index\\>" Info-current-node
)))
1378 (Info-goto-node (Info-extract-menu-counting 1))
1380 ((save-excursion (search-backward "next:" nil t
))
1383 ((and (save-excursion (search-backward "up:" nil t
))
1384 ;; Use string-equal, not equal, to ignore text props.
1385 (not (string-equal (downcase (Info-extract-pointer "up"))
1387 (let ((old-node Info-current-node
))
1389 (let (Info-history success
)
1391 (setq success
(Info-forward-node t no-error
))
1392 (or success
(Info-goto-node old-node
))))))
1394 (t (error "No pointer forward from this node"))))
1396 (defun Info-backward-node ()
1397 "Go backward one node, considering all nodes as forming one sequence."
1399 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1400 (upnode (Info-extract-pointer "up" t
)))
1401 (cond ((and upnode
(string-match "(" upnode
))
1402 (error "First node in file"))
1403 ((and upnode
(or (null prevnode
)
1404 ;; Use string-equal, not equal,
1405 ;; to ignore text properties.
1406 (string-equal (downcase prevnode
)
1407 (downcase upnode
))))
1410 ;; If we move back at the same level,
1411 ;; go down to find the last subnode*.
1414 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1415 (save-excursion (search-forward "\n* Menu:" nil t
)))
1416 (Info-goto-node (Info-extract-menu-counting nil
)))))
1418 (error "No pointer backward from this node")))))
1421 "Exit Info by selecting some other buffer."
1424 (save-buffers-kill-emacs)
1427 (defun Info-next-menu-item ()
1432 (search-forward "\n* menu:" nil t
)
1433 (and (search-forward "\n* " nil t
)
1434 (Info-extract-menu-node-name)))))
1435 (if node
(Info-goto-node node
)
1436 (error "No more items in menu"))))
1438 (defun Info-last-menu-item ()
1442 (let ((beg (save-excursion
1443 (and (search-backward "\n* menu:" nil t
)
1445 (or (and beg
(search-backward "\n* " beg t
))
1446 (error "No previous items in menu")))
1447 (Info-goto-node (save-excursion
1448 (goto-char (match-end 0))
1449 (Info-extract-menu-node-name)))))
1451 (defmacro Info-no-error
(&rest body
)
1452 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1454 (defun Info-next-preorder ()
1455 "Go to the next subnode or the next node, or go up a level."
1457 (cond ((Info-no-error (Info-next-menu-item)))
1458 ((Info-no-error (Info-next)))
1459 ((Info-no-error (Info-up t
))
1460 ;; Since we have already gone thru all the items in this menu,
1461 ;; go up to the end of this node.
1462 (goto-char (point-max))
1463 ;; Since logically we are done with the node with that menu,
1465 (Info-next-preorder))
1467 (error "No more nodes"))))
1469 (defun Info-last-preorder ()
1470 "Go to the last node, popping up a level if there is none."
1472 (cond ((Info-no-error
1473 (Info-last-menu-item)
1474 ;; If we go down a menu item, go to the end of the node
1475 ;; so we can scroll back through it.
1476 (goto-char (point-max)))
1477 ;; Keep going down, as long as there are nested menu nodes.
1478 (while (Info-no-error
1479 (Info-last-menu-item)
1480 ;; If we go down a menu item, go to the end of the node
1481 ;; so we can scroll back through it.
1482 (goto-char (point-max))))
1484 ((and (not (equal (Info-extract-pointer "up")
1485 (Info-extract-pointer "prev"))))
1486 (Info-no-error (Info-prev))
1487 (goto-char (point-max))
1488 (while (Info-no-error
1489 (Info-last-menu-item)
1490 ;; If we go down a menu item, go to the end of the node
1491 ;; so we can scroll back through it.
1492 (goto-char (point-max))))
1494 ((Info-no-error (Info-up t
))
1495 (goto-char (point-min))
1496 (or (search-forward "\n* Menu:" nil t
)
1497 (goto-char (point-max))))
1498 (t (error "No previous nodes"))))
1500 (defun Info-scroll-up ()
1501 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1502 Once you scroll far enough in a node that its menu appears on the screen
1503 but after point, the next scroll moves into its first subnode.
1505 When you scroll past the end of a node, that goes to the next node; if
1506 this node has no successor, it moves to the parent node's successor,
1507 and so on. If point is inside the menu of a node, it moves to
1508 subnode indicated by the following menu item. (That case won't
1509 normally result from this command, but can happen in other ways.)"
1512 (if (or (< (window-start) (point-min))
1513 (> (window-start) (point-max)))
1514 (set-window-start (selected-window) (point)))
1515 (let ((virtual-end (save-excursion
1516 (goto-char (point-min))
1517 (if (search-forward "\n* Menu:" nil t
)
1520 (if (or (< virtual-end
(window-start))
1521 (pos-visible-in-window-p virtual-end
))
1522 (Info-next-preorder)
1525 (defun Info-scroll-down ()
1526 "Scroll one screenful back in Info, considering all nodes as one sequence.
1527 Within the menu of a node, this goes to its last subnode.
1528 When you scroll past the beginning of a node, that goes to the
1529 previous node or back up to the parent node."
1531 (if (or (< (window-start) (point-min))
1532 (> (window-start) (point-max)))
1533 (set-window-start (selected-window) (point)))
1534 (let* ((current-point (point))
1535 (virtual-end (save-excursion
1537 (setq current-point
(point))
1538 (goto-char (point-min))
1539 (search-forward "\n* Menu:"
1542 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1543 (Info-last-preorder)
1546 (defun Info-next-reference (&optional recur
)
1547 "Move cursor to the next cross-reference or menu item in the node."
1549 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1551 (case-fold-search t
))
1552 (or (eobp) (forward-char 1))
1553 (or (re-search-forward pat nil t
)
1555 (goto-char (point-min))
1556 (or (re-search-forward pat nil t
)
1559 (error "No cross references in this node")))))
1560 (goto-char (match-beginning 0))
1561 (if (looking-at "\\* Menu:")
1563 (error "No cross references in this node")
1564 (Info-next-reference t
)))))
1566 (defun Info-prev-reference (&optional recur
)
1567 "Move cursor to the previous cross-reference or menu item in the node."
1569 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1571 (case-fold-search t
))
1572 (or (re-search-backward pat nil t
)
1574 (goto-char (point-max))
1575 (or (re-search-backward pat nil t
)
1578 (error "No cross references in this node")))))
1579 (goto-char (match-beginning 0))
1580 (if (looking-at "\\* Menu:")
1582 (error "No cross references in this node")
1583 (Info-prev-reference t
)))))
1585 (defun Info-index (topic)
1586 "Look up a string in the index for this file.
1587 The index is defined as the first node in the top-level menu whose
1588 name contains the word \"Index\", plus any immediately following
1589 nodes whose names also contain the word \"Index\".
1590 If there are no exact matches to the specified topic, this chooses
1591 the first match which is a case-insensitive substring of a topic.
1592 Use the `,' command to see the other matches.
1593 Give a blank topic name to go to the Index node itself."
1594 (interactive "sIndex topic: ")
1595 (let ((orignode Info-current-node
)
1597 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1598 (regexp-quote topic
)))
1600 (case-fold-search t
))
1601 (Info-goto-node "Top")
1602 (or (search-forward "\n* menu:" nil t
)
1604 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1606 (goto-char (match-beginning 1))
1607 ;; Here, and subsequently in this function,
1608 ;; we bind Info-history to nil for internal node-switches
1609 ;; so that we don't put junk in the history.
1610 ;; In the first Info-goto-node call, above, we do update the history
1611 ;; because that is what the user's previous node choice into it.
1612 (let ((Info-history nil
))
1613 (Info-goto-node (Info-extract-menu-node-name)))
1614 (or (equal topic
"")
1621 (goto-char (point-min))
1622 (while (re-search-forward pattern nil t
)
1624 (cons (list (buffer-substring (match-beginning 1)
1626 (buffer-substring (match-beginning 2)
1629 (string-to-int (concat "0"
1634 (and (setq node
(Info-extract-pointer "next" t
))
1635 (string-match "\\<Index\\>" node
)))
1636 (Info-goto-node node
))
1639 (Info-goto-node orignode
)
1640 (error "No `%s' in index" topic
)))
1641 ;; Here it is a feature that assoc is case-sensitive.
1642 (while (setq found
(assoc topic matches
))
1643 (setq exact
(cons found exact
)
1644 matches
(delq found matches
)))
1645 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1646 (Info-index-next 0)))))
1648 (defun Info-index-next (num)
1649 "Go to the next matching index item from the last `i' command."
1651 (or Info-index-alternatives
1652 (error "No previous `i' command"))
1654 (setq num
(+ num
(length Info-index-alternatives
))))
1656 (setq Info-index-alternatives
1657 (nconc (cdr Info-index-alternatives
)
1658 (list (car Info-index-alternatives
)))
1660 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1661 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1662 (forward-line (nth 3 (car Info-index-alternatives
)))
1663 (forward-line 3) ; don't search in headers
1664 (let ((name (car (car Info-index-alternatives
))))
1665 (Info-find-index-name name
)))
1666 (message "Found `%s' in %s. %s"
1667 (car (car Info-index-alternatives
))
1668 (nth 2 (car Info-index-alternatives
))
1669 (if (cdr Info-index-alternatives
)
1670 "(Press `,' for more)"
1673 (defun Info-find-index-name (name)
1674 "Move point to the place within the current node where NAME is defined."
1675 (let ((case-fold-search t
))
1676 (if (or (re-search-forward (format
1677 "[a-zA-Z]+: %s\\( \\|$\\)"
1678 (regexp-quote name
)) nil t
)
1679 (search-forward (format "`%s'" name
) nil t
)
1680 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1682 (format "`%s'" (substring name
0 (match-beginning 1)))
1684 (search-forward name nil t
))
1686 (goto-char (point-min)))))
1688 (defun Info-undefined ()
1689 "Make command be undefined in Info."
1694 "Enter the Info tutorial."
1696 (delete-other-windows)
1697 (Info-find-node "info"
1698 (if (< (window-height) 23)
1702 (defun Info-summary ()
1703 "Display a brief summary of all Info commands."
1705 (save-window-excursion
1706 (switch-to-buffer "*Help*")
1707 (setq buffer-read-only nil
)
1709 (insert (documentation 'Info-mode
))
1711 (goto-char (point-min))
1713 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1714 (message (if flag
"Type Space to see more"
1715 "Type Space to return to Info"))
1716 (if (not (eq ?\
(setq ch
(read-event))))
1717 (progn (setq unread-command-events
(list ch
)) nil
)
1720 (bury-buffer "*Help*")))
1722 (defun Info-get-token (pos start all
&optional errorstring
)
1723 "Return the token around POS,
1724 POS must be somewhere inside the token
1725 START is a regular expression which will match the
1726 beginning of the tokens delimited string
1727 ALL is a regular expression with a single
1728 parenthesized subpattern which is the token to be
1729 returned. E.g. '{\(.*\)}' would return any string
1730 enclosed in braces around POS.
1731 SIG optional fourth argument, controls action on no match
1734 a string: signal an error, using that string."
1735 (let ((case-fold-search t
))
1738 ;; First look for a match for START that goes across POS.
1739 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
1740 (not (looking-at start
)))
1742 ;; If we did not find one, search back for START
1743 ;; (this finds only matches that end at or before POS).
1744 (or (looking-at start
)
1747 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
1749 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1750 (not (setq found
(and (<= (match-beginning 0) pos
)
1751 (> (match-end 0) pos
))))))
1752 (if (and found
(<= (match-beginning 0) pos
)
1753 (> (match-end 0) pos
))
1754 (buffer-substring (match-beginning 1) (match-end 1))
1755 (cond ((null errorstring
)
1761 (error "No %s around position %d" errorstring pos
))))))))
1763 (defun Info-mouse-follow-nearest-node (click)
1764 "\\<Info-mode-map>Follow a node reference near point.
1765 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1766 At end of the node's text, moves to the next node, or up if none."
1768 (let* ((start (event-start click
))
1769 (window (car start
))
1770 (pos (car (cdr start
))))
1771 (select-window window
)
1773 (and (not (Info-try-follow-nearest-node))
1774 (save-excursion (forward-line 1) (eobp))
1775 (Info-next-preorder)))
1777 (defun Info-follow-nearest-node ()
1778 "\\<Info-mode-map>Follow a node reference near point.
1779 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1780 If no reference to follow, moves to the next node, or up if none."
1782 (or (Info-try-follow-nearest-node)
1783 (Info-next-preorder)))
1785 ;; Common subroutine.
1786 (defun Info-try-follow-nearest-node ()
1787 "Follow a node reference near point. Return non-nil if successful."
1790 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1791 "\\*note[ \n]\\([^:]*\\):"))
1792 (Info-follow-reference node
))
1793 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1794 (Info-goto-node node
))
1795 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1798 (setq node
(Info-extract-menu-node-name))
1799 (Info-goto-node node
))
1800 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1801 (Info-goto-node node
))
1802 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1803 (Info-goto-node node
))
1804 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1805 (Info-goto-node "Top"))
1806 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1807 (Info-goto-node node
)))
1810 (defvar Info-mode-map nil
1811 "Keymap containing Info commands.")
1814 (setq Info-mode-map
(make-keymap))
1815 (suppress-keymap Info-mode-map
)
1816 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1817 (define-key Info-mode-map
" " 'Info-scroll-up
)
1818 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1819 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1820 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1821 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1822 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1823 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1824 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1825 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1826 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1827 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1828 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1829 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1830 (define-key Info-mode-map
"0" 'undefined
)
1831 (define-key Info-mode-map
"?" 'Info-summary
)
1832 (define-key Info-mode-map
"]" 'Info-forward-node
)
1833 (define-key Info-mode-map
"[" 'Info-backward-node
)
1834 (define-key Info-mode-map
"<" 'Info-top-node
)
1835 (define-key Info-mode-map
">" 'Info-final-node
)
1836 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1837 (define-key Info-mode-map
"d" 'Info-directory
)
1838 (define-key Info-mode-map
"e" 'Info-edit
)
1839 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1840 (define-key Info-mode-map
"g" 'Info-goto-node
)
1841 (define-key Info-mode-map
"h" 'Info-help
)
1842 (define-key Info-mode-map
"i" 'Info-index
)
1843 (define-key Info-mode-map
"l" 'Info-last
)
1844 (define-key Info-mode-map
"m" 'Info-menu
)
1845 (define-key Info-mode-map
"n" 'Info-next
)
1846 (define-key Info-mode-map
"p" 'Info-prev
)
1847 (define-key Info-mode-map
"q" 'Info-exit
)
1848 (define-key Info-mode-map
"s" 'Info-search
)
1849 ;; For consistency with Rmail.
1850 (define-key Info-mode-map
"\M-s" 'Info-search
)
1851 (define-key Info-mode-map
"t" 'Info-top-node
)
1852 (define-key Info-mode-map
"u" 'Info-up
)
1853 (define-key Info-mode-map
"," 'Info-index-next
)
1854 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1855 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1858 (defun Info-check-pointer (item)
1859 ;; Non-nil if ITEM is present in this node.
1861 (Info-extract-pointer item
)
1864 (easy-menu-define Info-mode-menu Info-mode-map
1865 "Menu for info files."
1867 ["Up" Info-up
(Info-check-pointer "up")]
1868 ["Next" Info-next
(Info-check-pointer "next")]
1869 ["Previous" Info-prev
(Info-check-pointer "prev[ious]*")]
1870 ("Menu item" ["You should never see this" report-emacs-bug t
])
1871 ("Reference" ["You should never see this" report-emacs-bug t
])
1872 ["Search..." Info-search t
]
1873 ["Goto node..." Info-goto-node t
]
1874 ["Last" Info-last Info-history
]
1875 ["Exit" Info-exit t
]))
1877 (defvar Info-menu-last-node nil
)
1878 ;; Last node the menu was created for.
1879 ;; Value is a list, (FILE-NAME NODE-NAME).
1881 (defun Info-menu-update ()
1882 ;; Update the Info menu for the current node.
1884 (if (or (not (eq major-mode
'Info-mode
))
1885 (equal (list Info-current-file Info-current-node
)
1886 Info-menu-last-node
))
1888 ;; Update menu menu.
1889 (let* ((Info-complete-menu-buffer (current-buffer))
1890 (items (nreverse (condition-case nil
1891 (Info-complete-menu-item
1892 "" (lambda (e) t
) t
)
1896 (while (and items
(< number
9))
1897 (setq current
(car items
)
1900 (setq entries
(cons `[,current
1901 (Info-menu ,current
)
1902 :keys
,(format "%d" number
)]
1905 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
1907 (setq entries
(list ["No menu" nil nil
])))
1908 (easy-menu-change '("Info") "Menu item" (nreverse entries
)))
1909 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1911 str i entries current
1913 (case-fold-search t
))
1915 (goto-char (point-min))
1916 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1917 (setq str
(buffer-substring
1921 (while (setq i
(string-match "[ \n\t]+" str i
))
1922 (setq str
(concat (substring str
0 i
) " "
1923 (substring str
(match-end 0))))
1927 (while (and items
(< number
9))
1928 (setq current
(car items
)
1931 (setq entries
(cons `[,current
1932 (Info-follow-reference ,current
)
1936 (setq entries
(cons ["Other..." Info-follow-reference t
]
1939 (setq entries
(list ["No references" nil nil
])))
1940 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
1941 ;; Update last seen node.
1942 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
1943 ;; Try to avoid entering infinite beep mode in case of errors.
1947 ;; Info mode is suitable only for specially formatted data.
1948 (put 'info-mode
'mode-class
'special
)
1952 Info mode provides commands for browsing through the Info documentation tree.
1953 Documentation in Info is divided into \"nodes\", each of which discusses
1954 one topic and contains references to other nodes which discuss related
1955 topics. Info has commands to follow the references and show you other nodes.
1957 \\[Info-help] Invoke the Info tutorial.
1958 \\[Info-exit] Quit Info: reselect previously selected buffer.
1960 Selecting other nodes:
1961 \\[Info-mouse-follow-nearest-node]
1962 Follow a node reference you click on.
1963 This works with menu items, cross references, and
1964 the \"next\", \"previous\" and \"up\", depending on where you click.
1965 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1966 \\[Info-next] Move to the \"next\" node of this node.
1967 \\[Info-prev] Move to the \"previous\" node of this node.
1968 \\[Info-up] Move \"up\" from this node.
1969 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1970 Picking a menu item causes another node to be selected.
1971 \\[Info-directory] Go to the Info directory node.
1972 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1973 \\[Info-last] Move to the last node you were at.
1974 \\[Info-index] Look up a topic in this file's Index and move to that node.
1975 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1976 \\[Info-top-node] Go to the Top node of this file.
1977 \\[Info-final-node] Go to the final node in this file.
1978 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1979 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1981 Moving within a node:
1982 \\[Info-scroll-up] Normally, scroll forward a full screen.
1983 Once you scroll far enough in a node that its menu appears on the screen
1984 but after point, the next scroll moves into its first subnode.
1985 When after all menu items (or if their is no menu), move up to
1987 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1988 already visible, try to go to the previous menu entry, or up if there is none.
1989 \\[beginning-of-buffer] Go to beginning of node.
1992 \\[Info-exit] Quit Info: reselect previously selected buffer.
1993 \\[Info-edit] Edit contents of selected node.
1994 1 Pick first item in node's menu.
1995 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1996 \\[Info-goto-node] Move to node specified by name.
1997 You may include a filename as well, as (FILENAME)NODENAME.
1998 \\[universal-argument] \\[info] Move to new Info file with completion.
1999 \\[Info-search] Search through this Info file for specified regexp,
2000 and select the node in which the next occurrence is found.
2001 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2002 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2003 (kill-all-local-variables)
2004 (setq major-mode
'Info-mode
)
2005 (setq mode-name
"Info")
2007 (use-local-map Info-mode-map
)
2008 (make-local-hook 'activate-menubar-hook
)
2009 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2010 (set-syntax-table text-mode-syntax-table
)
2011 (setq local-abbrev-table text-mode-abbrev-table
)
2012 (setq case-fold-search t
)
2013 (setq buffer-read-only t
)
2014 (make-local-variable 'Info-current-file
)
2015 (make-local-variable 'Info-current-subfile
)
2016 (make-local-variable 'Info-current-node
)
2017 (make-local-variable 'Info-tag-table-marker
)
2018 (setq Info-tag-table-marker
(make-marker))
2019 (make-local-variable 'Info-tag-table-buffer
)
2020 (setq Info-tag-table-buffer nil
)
2021 (make-local-variable 'Info-history
)
2022 (make-local-variable 'Info-index-alternatives
)
2023 ;; This is for the sake of the invisible text we use handling titles.
2024 (make-local-variable 'line-move-ignore-invisible
)
2025 (setq line-move-ignore-invisible t
)
2026 (Info-set-mode-line)
2027 (run-hooks 'Info-mode-hook
))
2029 (defvar Info-edit-map nil
2030 "Local keymap used within `e' command of Info.")
2033 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
2034 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
2036 ;; Info-edit mode is suitable only for specially formatted data.
2037 (put 'info-edit-mode
'mode-class
'special
)
2039 (defun Info-edit-mode ()
2040 "Major mode for editing the contents of an Info node.
2041 Like text mode with the addition of `Info-cease-edit'
2042 which returns to Info mode for browsing.
2044 (use-local-map Info-edit-map
)
2045 (setq major-mode
'Info-edit-mode
)
2046 (setq mode-name
"Info Edit")
2047 (kill-local-variable 'mode-line-buffer-identification
)
2048 (setq buffer-read-only nil
)
2049 (force-mode-line-update)
2050 (buffer-enable-undo (current-buffer))
2051 (run-hooks 'Info-edit-mode-hook
))
2054 "Edit the contents of this Info node.
2055 Allowed only if variable `Info-enable-edit' is non-nil."
2057 (or Info-enable-edit
2058 (error "Editing info nodes is not enabled"))
2060 (message "%s" (substitute-command-keys
2061 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2063 (defun Info-cease-edit ()
2064 "Finish editing Info node; switch back to Info proper."
2066 ;; Do this first, so nothing has changed if user C-g's at query.
2067 (and (buffer-modified-p)
2068 (y-or-n-p "Save the file? ")
2070 (use-local-map Info-mode-map
)
2071 (setq major-mode
'Info-mode
)
2072 (setq mode-name
"Info")
2073 (Info-set-mode-line)
2074 (setq buffer-read-only t
)
2075 (force-mode-line-update)
2076 (and (marker-position Info-tag-table-marker
)
2078 (message "Tags may have changed. Use Info-tagify if necessary")))
2080 (defvar Info-file-list-for-emacs
2081 '("ediff" "forms" "gnus" "info" ("mh" .
"mh-e") "sc" "message"
2082 ("dired" .
"dired-x") ("c" .
"ccmode") "viper")
2083 "List of Info files that describe Emacs commands.
2084 An element can be a file name, or a list of the form (PREFIX . FILE)
2085 where PREFIX is a name prefix and FILE is the file to look in.
2086 If the element is just a file name, the file name also serves as the prefix.")
2088 (defun Info-find-emacs-command-nodes (command)
2089 "Return a list of locations documenting COMMAND.
2090 The `info-file' property of COMMAND says which Info manual to search.
2091 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2092 defines heuristics for which Info manual to try.
2093 The locations are of the format used in Info-history, i.e.
2094 \(FILENAME NODENAME BUFFERPOS\)."
2096 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2097 ":\\s *\\(.*\\)\\.$"))
2098 (info-file "emacs")) ;default
2099 ;; Determine which info file this command is documented in.
2100 (if (get command
'info-file
)
2101 (setq info-file
(get command
'info-file
))
2102 ;; If it doesn't say explicitly, test its name against
2103 ;; various prefixes that we know.
2104 (let ((file-list Info-file-list-for-emacs
))
2106 (let* ((elt (car file-list
))
2107 (name (if (consp elt
)
2110 (file (if (consp elt
) (cdr elt
) elt
))
2111 (regexp (concat "\\`" (regexp-quote name
)
2113 (if (string-match regexp
(symbol-name command
))
2114 (setq info-file file file-list nil
))
2115 (setq file-list
(cdr file-list
))))))
2118 (Info-find-node info-file
"Command Index")
2119 ;; Some manuals may not have a separate Command Index node,
2120 ;; so try just Index instead.
2122 (Info-find-node info-file
"Index")))
2123 ;; Take the index node off the Info history.
2124 (setq Info-history
(cdr Info-history
))
2125 (goto-char (point-max))
2126 (while (re-search-backward cmd-desc nil t
)
2127 (setq where
(cons (list Info-current-file
2136 (defun Info-goto-emacs-command-node (command)
2137 "Go to the Info node in the Emacs manual for command COMMAND.
2138 The command is found by looking up in Emacs manual's Command Index
2139 or in another manual found via COMMAND's `info-file' property or
2140 the variable `Info-file-list-for-emacs'."
2141 (interactive "CFind documentation for command: ")
2142 (or (commandp command
)
2143 (signal 'wrong-type-argument
(list 'commandp command
)))
2144 (let ((where (Info-find-emacs-command-nodes command
)))
2146 (let ((num-matches (length where
)))
2147 ;; Get Info running, and pop to it in another window.
2148 (save-window-excursion
2150 ;; FIXME It would be cool if this could use a buffer other
2152 (pop-to-buffer "*info*")
2153 (Info-find-node (car (car where
))
2154 (car (cdr (car where
))))
2155 (if (> num-matches
1)
2157 ;; Info-find-node already pushed (car where) onto
2158 ;; Info-history. Put the other nodes that were found on
2160 (setq Info-history
(nconc (cdr where
) Info-history
))
2161 (message "Found %d other entr%s. Use %s to see %s."
2163 (if (> num-matches
2) "ies" "y")
2164 (substitute-command-keys "\\[Info-last]")
2165 (if (> num-matches
2) "them" "it")))))
2166 (error "Couldn't find documentation for %s" command
))))
2169 (defun Info-goto-emacs-key-command-node (key)
2170 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2171 Interactively, if the binding is execute-extended-command, a command is read.
2172 The command is found by looking up in Emacs manual's Command Index
2173 or in another manual found via COMMAND's `info-file' property or
2174 the variable `Info-file-list-for-emacs'."
2175 (interactive "kFind documentation for key:")
2176 (let ((command (key-binding key
)))
2177 (cond ((null command
)
2178 (message "%s is undefined" (key-description key
)))
2179 ((and (interactive-p)
2180 (eq command
'execute-extended-command
))
2181 (Info-goto-emacs-command-node
2182 (read-command "Find documentation for command: ")))
2184 (Info-goto-emacs-command-node command
)))))
2186 (defcustom Info-title-face-alist
2187 '((?
* bold underline
)
2188 (?
= bold-italic underline
)
2189 (?- italic underline
))
2190 "*Alist of face or list of faces to use for pseudo-underlined titles.
2191 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2192 :type
'(repeat (list character face face
))
2195 (defun Info-fontify-node ()
2197 (let ((buffer-read-only nil
)
2198 (case-fold-search t
))
2199 (goto-char (point-min))
2200 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2201 (goto-char (match-end 0))
2203 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2204 (goto-char (match-end 0))
2206 (goto-char (match-beginning 1))
2207 (save-match-data (looking-at "Node:")))
2208 (put-text-property (match-beginning 2) (match-end 2)
2210 (put-text-property (match-beginning 2) (match-end 2)
2212 (put-text-property (match-beginning 2) (match-end 2)
2213 'mouse-face
'highlight
))))
2214 (goto-char (point-min))
2215 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2217 (put-text-property (match-beginning 1) (match-end 1)
2219 (cdr (assq (preceding-char) Info-title-face-alist
)))
2220 ;; This is a serious problem for trying to handle multiple
2221 ;; frame types at once. We want this text to be invisible
2222 ;; on frames that can display the font above.
2223 (if (memq (framep (selected-frame)) '(x pc w32
))
2224 (put-text-property (match-end 1) (match-end 2)
2226 (goto-char (point-min))
2227 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
2228 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2230 (put-text-property (match-beginning 1) (match-end 1)
2232 (put-text-property (match-beginning 1) (match-end 1)
2233 'mouse-face
'highlight
)))
2234 (goto-char (point-min))
2235 (if (and (search-forward "\n* Menu:" nil t
)
2236 (not (string-match "\\<Index\\>" Info-current-node
))
2237 ;; Don't take time to annotate huge menus
2238 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2240 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t
)
2242 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
2243 (put-text-property (match-beginning 0)
2244 (1+ (match-beginning 0))
2245 'face
'info-menu-5
))
2246 (put-text-property (match-beginning 1) (match-end 1)
2248 (put-text-property (match-beginning 1) (match-end 1)
2249 'mouse-face
'highlight
))))
2250 (set-buffer-modified-p nil
))))
2253 ;; When an Info buffer is killed, make sure the associated tags buffer
2255 (defun Info-kill-buffer ()
2256 (and (eq major-mode
'Info-mode
)
2257 Info-tag-table-buffer
2258 (kill-buffer Info-tag-table-buffer
)))
2260 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
2262 ;;; Speedbar support:
2263 ;; These functions permit speedbar to display the "tags" in the
2264 ;; current info node.
2265 (eval-when-compile (require 'speedbar
))
2267 (defvar Info-speedbar-key-map nil
2268 "Keymap used when in the info display mode.")
2270 (defun Info-install-speedbar-variables ()
2271 "Install those variables used by speedbar to enhance Info."
2272 (if Info-speedbar-key-map
2274 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
2276 ;; Basic tree features
2277 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
2278 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
2279 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
2280 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
2283 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2284 Info-speedbar-key-map
2285 Info-speedbar-hierarchy-buttons
)))
2287 (defvar Info-speedbar-menu-items
2288 '(["Browse Node" speedbar-edit-line t
]
2289 ["Expand Node" speedbar-expand-line
2290 (save-excursion (beginning-of-line)
2291 (looking-at "[0-9]+: *.\\+. "))]
2292 ["Contract Node" speedbar-contract-line
2293 (save-excursion (beginning-of-line)
2294 (looking-at "[0-9]+: *.-. "))]
2296 "Additional menu-items to add to speedbar frame.")
2298 ;; Make sure our special speedbar major mode is loaded
2299 (if (featurep 'speedbar
)
2300 (Info-install-speedbar-variables)
2301 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
2303 ;;; Info hierarchy display method
2305 (defun Info-speedbar-browser ()
2306 "Initialize speedbar to display an info node browser.
2307 This will add a speedbar major display mode."
2310 ;; Make sure that speedbar is active
2311 (speedbar-frame-mode 1)
2312 ;; Now, throw us into Info mode on speedbar.
2313 (speedbar-change-initial-expansion-list "Info")
2316 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
2317 "Display an Info directory hierarchy in speedbar.
2318 DIRECTORY is the current directory in the attached frame.
2319 DEPTH is the current indentation depth.
2320 NODE is an optional argument that is used to represent the
2321 specific node to expand."
2323 (save-excursion (goto-char (point-min))
2324 (let ((case-fold-search t
))
2325 (looking-at "Info Nodes:"))))
2326 ;; Update our "current node" maybe?
2328 ;; We cannot use the generic list code, that depends on all leaves
2329 ;; being known at creation time.
2331 (speedbar-with-writable (insert "Info Nodes:\n")))
2332 (let ((completions nil
)
2333 (cf (selected-frame)))
2334 (select-frame speedbar-attached-frame
)
2335 (save-window-excursion
2337 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
2340 (speedbar-with-writable
2342 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
2343 (cdr (car completions
))
2344 (car (car completions
))
2345 'Info-speedbar-goto-node
2346 (cdr (car completions
))
2348 (setq completions
(cdr completions
)))
2352 (defun Info-speedbar-goto-node (text node indent
)
2353 "When user clicks on TEXT, goto an info NODE.
2354 The INDENT level is ignored."
2355 (select-frame speedbar-attached-frame
)
2356 (let* ((buff (or (get-buffer "*info*")
2357 (progn (info) (get-buffer "*info*"))))
2358 (bwin (get-buffer-window buff
0)))
2361 (select-window bwin
)
2362 (raise-frame (window-frame bwin
)))
2363 (if speedbar-power-click
2364 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
2365 (select-frame speedbar-attached-frame
)
2366 (switch-to-buffer buff
)))
2367 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
2368 (file (match-string 1 node
))
2369 (node (match-string 2 node
)))
2370 (Info-find-node file node
)
2371 ;; If we do a find-node, and we were in info mode, restore
2372 ;; the old default method. Once we are in info mode, it makes
2373 ;; sense to return to whatever method the user was using before.
2374 (if (string= speedbar-initial-expansion-list-name
"Info")
2375 (speedbar-change-initial-expansion-list
2376 speedbar-previously-used-expansion-list-name
)))))
2378 (defun Info-speedbar-expand-node (text token indent
)
2379 "Expand the node the user clicked on.
2380 TEXT is the text of the button we clicked on, a + or - item.
2381 TOKEN is data related to this node (NAME . FILE).
2382 INDENT is the current indentation depth."
2383 (cond ((string-match "+" text
) ;we have to expand this file
2384 (speedbar-change-expand-button-char ?-
)
2385 (if (speedbar-with-writable
2387 (end-of-line) (forward-char 1)
2388 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
2389 (speedbar-change-expand-button-char ?-
)
2390 (speedbar-change-expand-button-char ??
)))
2391 ((string-match "-" text
) ;we have to contract this node
2392 (speedbar-change-expand-button-char ?
+)
2393 (speedbar-delete-subblock indent
))
2394 (t (error "Ooops... not sure what to do")))
2395 (speedbar-center-buffer-smartly))
2397 (defun Info-speedbar-fetch-file-nodes (nodespec)
2398 "Fetch the subnodes from the info NODESPEC.
2399 NODESPEC is a string of the form: (file)node.
2400 Optional THISFILE represends the filename of"
2402 ;; Set up a buffer we can use to fake-out Info.
2403 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2404 (if (not (equal major-mode
'Info-mode
))
2406 ;; Get the node into this buffer
2407 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
2408 (file (match-string 1 nodespec
))
2409 (node (match-string 2 nodespec
)))
2410 (Info-find-node file node
))
2411 ;; Scan the created buffer
2412 (goto-char (point-min))
2413 (let ((completions nil
)
2414 (case-fold-search t
)
2415 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
2416 (match-string 1 nodespec
))))
2417 ;; Always skip the first one...
2418 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2419 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2420 (let ((name (match-string 1)))
2421 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2422 (setq name
(cons name
(match-string 1)))
2423 (if (looking-at " *\\(([^)]+)\\)\\.")
2424 (setq name
(cons name
(concat (match-string 1) "Top")))
2425 (if (looking-at " \\([^.]+\\).")
2427 (cons name
(concat "(" thisfile
")" (match-string 1))))
2428 (setq name
(cons name
(concat "(" thisfile
")" name
))))))
2429 (setq completions
(cons name completions
))))
2430 (nreverse completions
))))
2432 ;;; Info mode node listing
2433 (defun Info-speedbar-buttons (buffer)
2434 "Create a speedbar display to help navigation in an Info file.
2435 BUFFER is the buffer speedbar is requesting buttons for."
2436 (if (save-excursion (goto-char (point-min))
2437 (let ((case-fold-search t
))
2438 (not (looking-at "Info Nodes:"))))
2440 (Info-speedbar-hierarchy-buttons nil
0)
2445 ;;; info.el ends here