1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98 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
82 (let ((path (getenv "INFOPATH"))
83 ;; This is for older Emacs versions
84 ;; which might get this info.el from the Texinfo distribution.
85 (path-separator (if (boundp 'path-separator) path-separator
86 (if (eq system-type 'ms-dos) ";" ":")))
87 (source (expand-file-name "info/" source-directory))
88 (sibling (if installation-directory
89 (expand-file-name "info/" installation-directory)))
94 (while (> (length path) 0)
95 (setq idx (or (string-match path-separator path) (length path))
96 list (cons (substring path 0 idx) list)
97 path (substring path (min (1+ idx)
100 (if (and sibling (file-exists-p sibling))
101 (setq alternative sibling)
102 (setq alternative source))
103 (if (or (member alternative Info-default-directory-list)
104 (not (file-exists-p alternative))
105 ;; On DOS/NT, we use movable executables always,
106 ;; and we must always find the Info dir at run time.
107 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
109 ;; Use invocation-directory for Info only if we used it for
110 ;; exec-directory also.
111 (not (string= exec-directory
112 (expand-file-name "lib-src/"
113 installation-directory)))))
114 Info-default-directory-list
115 (reverse (cons alternative
116 (cdr (reverse Info-default-directory-list)))))))
117 "List of directories to search for Info documentation files.
118 nil means not yet initialized. In this case, Info uses the environment
119 variable INFOPATH to initialize it, or `Info-default-directory-list'
120 if there is no INFOPATH variable in the environment.
121 The last element of `Info-default-directory-list' is the directory
122 where Emacs installs the Info files that come with it.
124 If you run the Emacs executable from the `src' directory in the Emacs
125 source tree, the `info' directory in the source tree is used as the last
126 element, in place of the installation Info directory. This is useful
127 when you run a version of Emacs without installing it.")
129 (defcustom Info-additional-directory-list nil
130 "List of additional directories to search for Info documentation files.
131 These directories are not searched for merging the `dir' file."
132 :type '(repeat directory)
135 (defvar Info-current-file nil
136 "Info file that Info is now looking at, or nil.
137 This is the name that was specified in Info, not the actual file name.
138 It doesn't contain directory names or file name extensions added by Info.")
140 (defvar Info-current-subfile nil
141 "Info subfile that is actually in the *info* buffer now,
142 or nil if current info file is not split into subfiles.")
144 (defvar Info-current-node nil
145 "Name of node that Info is now looking at, or nil.")
147 (defvar Info-tag-table-marker nil
148 "Marker pointing at beginning of current Info file's tag table.
149 Marker points nowhere if file has no tag table.")
151 (defvar Info-tag-table-buffer nil
152 "Buffer used for indirect tag tables.")
154 (defvar Info-current-file-completions nil
155 "Cached completion list for current Info file.")
157 (defvar Info-index-alternatives nil
158 "List of possible matches for last Info-index command.")
160 (defvar Info-standalone nil
161 "Non-nil if Emacs was started solely as an Info browser.")
163 (defvar Info-suffix-list
164 ;; The MS-DOS list should work both when long file names are
165 ;; supported (Windows 9X), and when only 8+3 file names are available.
166 (if (eq system-type 'ms-dos)
167 '( (".gz" . "gunzip")
171 (".info.Z" . "gunzip")
172 (".info.gz" . "gunzip")
173 ("-info.Z" . "gunzip")
174 ("-info.gz" . "gunzip")
175 ("/index.gz". "gunzip")
176 ("/index.z" . "gunzip")
182 '( (".info.Z". "uncompress")
183 (".info.Y". "unyabba")
184 (".info.gz". "gunzip")
185 (".info.z". "gunzip")
187 ("-info.Z". "uncompress")
188 ("-info.Y". "unyabba")
189 ("-info.gz". "gunzip")
190 ("-info.z". "gunzip")
192 ("/index.Z". "uncompress")
193 ("/index.Y". "unyabba")
194 ("/index.gz". "gunzip")
195 ("/index.z". "gunzip")
202 "List of file name suffixes and associated decoding commands.
203 Each entry should be (SUFFIX . STRING); the file is given to
204 the command as standard input. If STRING is nil, no decoding is done.
205 Because the SUFFIXes are tried in order, the empty string should
206 be last in the list.")
208 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
209 ;; First, on ms-dos, delete some of the extension in FILENAME
211 (defun info-insert-file-contents-1 (filename suffix)
212 (if (not (eq system-type 'ms-dos))
213 (concat filename suffix)
214 (let* ((sans-exts (file-name-sans-extension filename))
215 ;; How long is the extension in FILENAME (not counting the dot).
216 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
218 ;; SUFFIX starts with a dot. If FILENAME already has one,
219 ;; get rid of the one in SUFFIX (unless suffix is empty).
220 (or (and (<= ext-len 0)
221 (not (eq (aref filename (1- (length filename))) ?.)))
222 (= (length suffix) 0)
223 (setq suffix (substring suffix 1)))
224 ;; How many chars of that extension should we keep?
225 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
226 ;; Get rid of the rest of the extension, and add SUFFIX.
227 (concat (substring filename 0 (- (length filename)
228 (- ext-len ext-left)))
231 (defun info-file-exists-p (filename)
232 (and (file-exists-p filename)
233 (not (file-directory-p filename))))
235 (defun info-insert-file-contents (filename &optional visit)
236 "Insert the contents of an info file in the current buffer.
237 Do the right thing if the file has been compressed or zipped."
238 (let ((tail Info-suffix-list)
240 (if (file-exists-p filename)
241 ;; FILENAME exists--see if that name contains a suffix.
242 ;; If so, set DECODE accordingly.
246 (concat (regexp-quote (car (car tail))) "$")
248 (setq tail (cdr tail)))
249 (setq fullname filename
250 decoder (cdr (car tail))))
251 ;; Try adding suffixes to FILENAME and see if we can find something.
253 (not (info-file-exists-p (info-insert-file-contents-1
254 filename (car (car tail))))))
255 (setq tail (cdr tail)))
256 ;; If we found a file with a suffix, set DECODER according to the suffix
257 ;; and set FULLNAME to the file's actual name.
258 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
259 decoder (cdr (car tail)))
261 (error "Can't find %s or any compressed version of it" filename)))
262 ;; check for conflict with jka-compr
263 (if (and (featurep 'jka-compr)
264 (jka-compr-installed-p)
265 (jka-compr-get-compression-info fullname))
269 (insert-file-contents-literally fullname visit)
270 (let ((buffer-read-only nil)
271 (coding-system-for-write 'no-conversion)
272 (default-directory (or (file-name-directory fullname)
274 (call-process-region (point-min) (point-max) decoder t t)))
275 (insert-file-contents fullname visit))))
278 (defun info-other-window (&optional file)
279 "Like `info' but show the Info buffer in another window."
280 (interactive (if current-prefix-arg
281 (list (read-file-name "Info file name: " nil nil t))))
282 (let (same-window-buffer-names)
285 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
288 (defun info (&optional file)
289 "Enter Info, the documentation browser.
290 Optional argument FILE specifies the file to examine;
291 the default is the top-level directory of Info.
293 In interactive use, a prefix argument directs this command
294 to read a file name from the minibuffer.
296 The search path for Info files is in the variable `Info-directory-list'.
297 The top-level Info directory is made by combining all the files named `dir'
298 in all the directories in that path."
299 (interactive (if current-prefix-arg
300 (list (read-file-name "Info file name: " nil nil t))))
303 (pop-to-buffer "*info*")
304 ;; If argument already contains parentheses, don't add another set
305 ;; since the argument will then be parsed improperly. This also
306 ;; has the added benefit of allowing node names to be included
307 ;; following the parenthesized filename.
308 (if (and (stringp file) (string-match "(.*)" file))
309 (Info-goto-node file)
310 (Info-goto-node (concat "(" file ")"))))
311 (if (get-buffer "*info*")
312 (pop-to-buffer "*info*")
316 (defun info-standalone ()
317 "Run Emacs as a standalone Info reader.
318 Usage: emacs -f info-standalone [filename]
319 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
320 (setq Info-standalone t)
321 (if (and command-line-args-left
322 (not (string-match "^-" (car command-line-args-left))))
325 (info (car command-line-args-left))
326 (setq command-line-args-left (cdr command-line-args-left)))
327 (error (send-string-to-terminal
328 (format "%s\n" (if (eq (car-safe err) 'error)
330 (save-buffers-kill-emacs)))
333 ;; Go to an info node specified as separate filename and nodename.
334 ;; no-going-back is non-nil if recovering from an error in this function;
335 ;; it says do not attempt further (recursive) error recovery.
336 (defun Info-find-node (filename nodename &optional no-going-back)
337 ;; Convert filename to lower case if not found as specified.
340 (let (temp temp-downcase found)
341 (setq filename (substitute-in-file-name filename))
342 (if (string= (downcase filename) "dir")
344 (let ((dirs (if (string-match "^\\./" filename)
345 ;; If specified name starts with `./'
346 ;; then just try current directory.
348 (if (file-name-absolute-p filename)
349 ;; No point in searching for an
350 ;; absolute file name
352 (if Info-additional-directory-list
353 (append Info-directory-list
354 Info-additional-directory-list)
355 Info-directory-list)))))
356 ;; Search the directory list for file FILENAME.
357 (while (and dirs (not found))
358 (setq temp (expand-file-name filename (car dirs)))
360 (expand-file-name (downcase filename) (car dirs)))
361 ;; Try several variants of specified name.
362 (let ((suffix-list Info-suffix-list))
363 (while (and suffix-list (not found))
364 (cond ((info-file-exists-p
365 (info-insert-file-contents-1
366 temp (car (car suffix-list))))
369 (info-insert-file-contents-1
370 temp-downcase (car (car suffix-list))))
371 (setq found temp-downcase)))
372 (setq suffix-list (cdr suffix-list))))
373 (setq dirs (cdr dirs)))))
375 (setq filename found)
376 (error "Info file %s does not exist" filename))))
377 ;; Record the node we are leaving.
378 (if (and Info-current-file (not no-going-back))
380 (cons (list Info-current-file Info-current-node (point))
382 ;; Go into info buffer.
383 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
384 (buffer-disable-undo (current-buffer))
385 (or (eq major-mode 'Info-mode)
388 (setq Info-current-node nil)
390 ;; Bind case-fold-search in case the user sets it to nil.
391 (let ((case-fold-search t))
392 ;; Switch files if necessary
394 (equal Info-current-file filename)
395 (let ((buffer-read-only nil))
396 (setq Info-current-file nil
397 Info-current-subfile nil
398 Info-current-file-completions nil
399 buffer-file-name nil)
403 (info-insert-file-contents filename t)
404 (setq default-directory (file-name-directory filename)))
405 (set-buffer-modified-p nil)
406 ;; See whether file has a tag table. Record the location if yes.
407 (goto-char (point-max))
409 ;; Use string-equal, not equal, to ignore text props.
410 (if (not (or (string-equal nodename "*")
412 (search-forward "\^_\nEnd tag table\n" nil t))))
414 ;; We have a tag table. Find its beginning.
415 ;; Is this an indirect file?
416 (search-backward "\nTag table:\n")
420 (looking-at "(Indirect)\n"))
421 ;; It is indirect. Copy it to another buffer
422 ;; and record that the tag table is in that buffer.
423 (let ((buf (current-buffer))
425 (or Info-tag-table-buffer
426 (generate-new-buffer " *info tag table*"))))
427 (setq Info-tag-table-buffer tagbuf)
430 (buffer-disable-undo (current-buffer))
431 (setq case-fold-search t)
433 (insert-buffer-substring buf))
434 (set-marker Info-tag-table-marker
435 (match-end 0) tagbuf))
436 (set-marker Info-tag-table-marker pos)))
437 (set-marker Info-tag-table-marker nil))
438 (setq Info-current-file
439 (if (eq filename t) "dir" filename))))
440 ;; Use string-equal, not equal, to ignore text props.
441 (if (string-equal nodename "*")
442 (progn (setq Info-current-node nodename)
443 (Info-set-mode-line))
446 ;; 1. Anchor found in tag table
447 ;; 2. Anchor *not* in tag table
449 ;; 3. Node found in tag table
450 ;; 4. Node *not* found in tag table, but found in file
451 ;; 5. Node *not* in tag table, and *not* in file
453 ;; *Or* the same, but in an indirect subfile.
455 ;; Search file for a suitable node.
456 (let ((guesspos (point-min))
458 (concat "\\(Node:\\|Ref:\\) *"
459 (regexp-quote nodename)
462 ;; First, search a tag table, if any
463 (if (marker-position Info-tag-table-marker)
465 (let (found-in-tag-table
467 (m Info-tag-table-marker))
469 (set-buffer (marker-buffer m))
471 (beginning-of-line) ; so re-search will work.
474 (setq found-in-tag-table
475 (re-search-forward regexp nil t))
476 (if found-in-tag-table
477 (setq guesspos (read (current-buffer))))
478 (setq found-mode major-mode))
480 ;; Indirect file among split files
481 (if found-in-tag-table
483 ;; If this is an indirect file, determine
484 ;; which file really holds this node and
486 (if (not (eq found-mode 'Info-mode))
487 ;; Note that the current buffer must be
488 ;; the *info* buffer on entry to
489 ;; Info-read-subfile. Thus the hackery
491 (setq guesspos (Info-read-subfile guesspos)))))
494 (if (and found-in-tag-table
495 (string-equal "Ref:" (match-string 1)))
498 ;; Else we may have a node, which we search for:
499 (goto-char (max (point-min)
500 (- (byte-to-position guesspos) 1000)))
501 ;; Now search from our advised position
502 ;; (or from beg of buffer)
503 ;; to find the actual node.
505 (while (search-forward "\n\^_" nil t)
509 (if (re-search-backward regexp beg t)
514 "No such anchor in tag table or node in tag table or file: %s"
518 (goto-char (point-min))))
519 ;; If we did not finish finding the specified node,
520 ;; go back to the previous one.
521 (or Info-current-node no-going-back (null Info-history)
522 (let ((hist (car Info-history)))
523 (setq Info-history (cdr Info-history))
524 (Info-find-node (nth 0 hist) (nth 1 hist) t)
525 (goto-char (nth 2 hist))))))
527 ;; Cache the contents of the (virtual) dir file, once we have merged
528 ;; it for the first time, so we can save time subsequently.
529 (defvar Info-dir-contents nil)
531 ;; Cache for the directory we decided to use for the default-directory
532 ;; of the merged dir text.
533 (defvar Info-dir-contents-directory nil)
535 ;; Record the file attributes of all the files from which we
536 ;; constructed Info-dir-contents.
537 (defvar Info-dir-file-attributes nil)
539 ;; Construct the Info directory node by merging the files named `dir'
540 ;; from various directories. Set the *info* buffer's
541 ;; default-directory to the first directory we actually get any text
543 (defun Info-insert-dir ()
544 (if (and Info-dir-contents Info-dir-file-attributes
545 ;; Verify that none of the files we used has changed
548 (mapcar '(lambda (elt)
549 (let ((curr (file-attributes (car elt))))
550 ;; Don't compare the access time.
551 (if curr (setcar (nthcdr 4 curr) 0))
552 (setcar (nthcdr 4 (cdr elt)) 0)
553 (equal (cdr elt) curr)))
554 Info-dir-file-attributes))))
555 (insert Info-dir-contents)
556 (let ((dirs Info-directory-list)
557 ;; Bind this in case the user sets it to nil.
559 buffers buffer others nodes dirs-done)
561 (setq Info-dir-file-attributes nil)
563 ;; Search the directory list for the directory file.
565 (let ((truename (file-truename (expand-file-name (car dirs)))))
566 (or (member truename dirs-done)
567 (member (directory-file-name truename) dirs-done)
568 ;; Try several variants of specified name.
569 ;; Try upcasing, appending `.info', or both.
573 (progn (setq file (expand-file-name "dir" truename))
574 (file-attributes file))
575 (progn (setq file (expand-file-name "DIR" truename))
576 (file-attributes file))
577 (progn (setq file (expand-file-name "dir.info" truename))
578 (file-attributes file))
579 (progn (setq file (expand-file-name "DIR.INFO" truename))
580 (file-attributes file)))))
583 (cons (directory-file-name truename)
588 (message "Composing main Info directory..."))
589 (set-buffer (generate-new-buffer " info dir"))
592 (insert-file-contents file)
593 (setq buffers (cons (current-buffer) buffers)
594 Info-dir-file-attributes
595 (cons (cons file attrs)
596 Info-dir-file-attributes)))
597 (error (kill-buffer (current-buffer))))))))
598 (or (cdr dirs) (setq Info-dir-contents-directory
599 (file-name-as-directory (car dirs))))
600 (setq dirs (cdr dirs))))
603 (error "Can't find the Info directory node"))
604 ;; Distinguish the dir file that comes with Emacs from all the
605 ;; others. Yes, that is really what this is supposed to do.
606 ;; If it doesn't work, fix it.
607 (setq buffer (car buffers)
608 others (cdr buffers))
610 ;; Insert the entire original dir file as a start; note that we've
611 ;; already saved its default directory to use as the default
612 ;; directory for the whole concatenation.
613 (insert-buffer buffer)
615 ;; Look at each of the other buffers one by one.
617 (let ((other (car others)))
618 ;; In each, find all the menus.
621 (goto-char (point-min))
622 ;; Find each menu, and add an elt to NODES for it.
623 (while (re-search-forward "^\\* Menu:" nil t)
624 (let (beg nodename end)
627 (search-backward "\n\^_")
628 (search-forward "Node: ")
629 (setq nodename (Info-following-node-name))
630 (search-forward "\n\^_" nil 'move)
633 (setq nodes (cons (list nodename other beg end) nodes))))))
634 (setq others (cdr others)))
635 ;; Add to the main menu a menu item for each other node.
636 (re-search-forward "^\\* Menu:")
638 (let ((menu-items '("top"))
641 (end (save-excursion (search-forward "\^_" nil t) (point))))
643 (let ((nodename (car (car nodes))))
645 (or (member (downcase nodename) menu-items)
646 (re-search-forward (concat "^\\* +"
647 (regexp-quote nodename)
651 (insert "* " nodename "::" "\n")
652 (setq menu-items (cons nodename menu-items))))))
653 (setq nodes (cdr nodes))))
654 ;; Now take each node of each of the other buffers
655 ;; and merge it into the main buffer.
657 (let ((nodename (car (car nodes))))
658 (goto-char (point-min))
659 ;; Find the like-named node in the main buffer.
660 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
661 (regexp-quote nodename)
665 (search-forward "\n\^_" nil 'move)
668 ;; If none exists, add one.
669 (goto-char (point-max))
670 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
671 ;; Merge the text from the other buffer's menu
672 ;; into the menu in the like-named node in the main buffer.
673 (apply 'insert-buffer-substring (cdr (car nodes))))
674 (setq nodes (cdr nodes)))
675 ;; Kill all the buffers we just made.
677 (kill-buffer (car buffers))
678 (setq buffers (cdr buffers)))
679 (message "Composing main Info directory...done"))
680 (setq Info-dir-contents (buffer-string)))
681 (setq default-directory Info-dir-contents-directory))
683 ;; Note that on entry to this function the current-buffer must be the
684 ;; *info* buffer; not the info tags buffer.
685 (defun Info-read-subfile (nodepos)
686 ;; NODEPOS is either a position (in the Info file as a whole,
687 ;; not relative to a subfile) or the name of a subfile.
690 (if (numberp nodepos)
692 (set-buffer (marker-buffer Info-tag-table-marker))
693 (goto-char (point-min))
694 (search-forward "\n\^_")
697 (while (not (looking-at "\^_"))
700 thisfilepos thisfilename)
701 (search-forward ": ")
702 (setq thisfilename (buffer-substring beg (- (point) 2)))
703 (setq thisfilepos (read (current-buffer)))
704 ;; read in version 19 stops at the end of number.
705 ;; Advance to the next line.
707 (if (> thisfilepos nodepos)
709 (setq lastfilename thisfilename)
710 (setq lastfilepos thisfilepos))
712 (setq lastfilename nodepos)
713 (setq lastfilepos 0))
714 ;; Assume previous buffer is in Info-mode.
715 ;; (set-buffer (get-buffer "*info*"))
716 (or (equal Info-current-subfile lastfilename)
717 (let ((buffer-read-only nil))
718 (setq buffer-file-name nil)
721 (info-insert-file-contents lastfilename)
722 (set-buffer-modified-p nil)
723 (setq Info-current-subfile lastfilename)))
724 (goto-char (point-min))
725 (search-forward "\n\^_")
726 (if (numberp nodepos)
727 (+ (- nodepos lastfilepos) (point)))))
729 ;; Select the info node that point is in.
730 (defun Info-select-node ()
731 ;; Bind this in case the user sets it to nil.
732 (let ((case-fold-search t))
734 ;; Find beginning of node.
735 (search-backward "\n\^_")
737 ;; Get nodename spelled as it is in the node.
738 (re-search-forward "Node:[ \t]*")
739 (setq Info-current-node
740 (buffer-substring-no-properties (point)
742 (skip-chars-forward "^,\t\n")
745 ;; Find the end of it, and narrow.
747 (let (active-expression)
748 (narrow-to-region (point)
749 (if (re-search-forward "\n[\^_\f]" nil t)
752 (if (looking-at "[\n\^_\f]*execute: ")
754 (goto-char (match-end 0))
755 (setq active-expression
756 (read (current-buffer))))))
758 (if Info-enable-active-nodes (eval active-expression))
759 (if Info-fontify (Info-fontify-node))
760 (run-hooks 'Info-selection-hook)))))
762 (defun Info-set-mode-line ()
763 (setq mode-line-buffer-identification
766 (if Info-current-file
767 (file-name-nondirectory Info-current-file)
770 (or Info-current-node ""))))
772 ;; Go to an info node specified with a filename-and-nodename string
773 ;; of the sort that is found in pointers in nodes.
775 (defun Info-goto-node (nodename)
776 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
777 (interactive (list (Info-read-node-name "Goto node: ")))
779 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
781 (setq filename (if (= (match-beginning 1) (match-end 1))
783 (substring nodename (match-beginning 2) (match-end 2)))
784 nodename (substring nodename (match-beginning 3) (match-end 3)))
785 (let ((trim (string-match "\\s *\\'" filename)))
786 (if trim (setq filename (substring filename 0 trim))))
787 (let ((trim (string-match "\\s *\\'" nodename)))
788 (if trim (setq nodename (substring nodename 0 trim))))
789 (if transient-mark-mode (deactivate-mark))
790 (Info-find-node (if (equal filename "") nil filename)
791 (if (equal nodename "") "Top" nodename))))
793 (defvar Info-read-node-completion-table)
795 ;; This function is used as the "completion table" while reading a node name.
796 ;; It does completion using the alist in Info-read-node-completion-table
797 ;; unless STRING starts with an open-paren.
798 (defun Info-read-node-name-1 (string predicate code)
799 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
803 (try-completion string Info-read-node-completion-table predicate)))
807 (all-completions string Info-read-node-completion-table predicate)))
811 (assoc string Info-read-node-completion-table))))))
813 (defun Info-read-node-name (prompt &optional default)
814 (let* ((completion-ignore-case t)
815 (Info-read-node-completion-table (Info-build-node-completions))
816 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
817 (if (equal nodename "")
819 (Info-read-node-name prompt))
822 (defun Info-build-node-completions ()
823 (or Info-current-file-completions
825 ;; Bind this in case the user sets it to nil.
826 (case-fold-search t))
829 (if (marker-buffer Info-tag-table-marker)
830 (let ((marker Info-tag-table-marker))
831 (set-buffer (marker-buffer marker))
834 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
836 (cons (list (buffer-substring (match-beginning 1)
840 (goto-char (point-min))
841 (while (search-forward "\n\^_" nil t)
845 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
848 (cons (list (buffer-substring (match-beginning 1)
851 (setq Info-current-file-completions compl))))
853 (defun Info-restore-point (hl)
854 "If this node has been visited, restore the point value when we left."
856 (if (and (equal (nth 0 (car hl)) Info-current-file)
857 ;; Use string-equal, not equal, to ignore text props.
858 (string-equal (nth 1 (car hl)) Info-current-node))
860 (goto-char (nth 2 (car hl)))
861 (setq hl nil)) ;terminate the while at next iter
862 (setq hl (cdr hl)))))
864 (defvar Info-last-search nil
865 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
867 (defun Info-search (regexp)
868 "Search for REGEXP, starting from point, and select node it's found in."
869 (interactive "sSearch (regexp): ")
870 (if transient-mark-mode (deactivate-mark))
871 (if (equal regexp "")
872 (setq regexp Info-last-search)
873 (setq Info-last-search regexp))
874 (let ((found ()) current
875 (onode Info-current-node)
876 (ofile Info-current-file)
878 (ostart (window-start))
879 (osubfile Info-current-subfile))
883 (if (null Info-current-subfile)
884 (progn (re-search-forward regexp) (setq found (point)))
886 (progn (re-search-forward regexp) (setq found (point)))
887 (search-failed nil)))))
888 (if (not found) ;can only happen in subfile case -- else would have erred
892 (set-buffer (marker-buffer Info-tag-table-marker))
893 (goto-char (point-min))
894 (search-forward "\n\^_\nIndirect:")
896 (narrow-to-region (point)
897 (progn (search-forward "\n\^_")
899 (goto-char (point-min))
900 (search-forward (concat "\n" osubfile ": "))
903 (re-search-forward "\\(^.*\\): [0-9]+$")
904 (goto-char (+ (match-end 1) 2))
905 (setq list (cons (cons (read (current-buffer))
907 (match-beginning 1) (match-end 1)))
909 (goto-char (1+ (match-end 0))))
910 (setq list (nreverse list)
911 current (car (car list))
914 (message "Searching subfile %s..." (cdr (car list)))
915 (Info-read-subfile (car (car list)))
916 (setq list (cdr list))
917 ;; (goto-char (point-min))
918 (if (re-search-forward regexp nil t)
919 (setq found (point) list ())))
922 (signal 'search-failed (list regexp))))
924 (progn (Info-read-subfile osubfile)
927 (set-window-start (selected-window) ostart)))))
931 ;; Use string-equal, not equal, to ignore text props.
932 (or (and (string-equal onode Info-current-node)
933 (equal ofile Info-current-file))
934 (setq Info-history (cons (list ofile onode opoint)
937 ;; Extract the value of the node-pointer named NAME.
938 ;; If there is none, use ERRORNAME in the error message;
939 ;; if ERRORNAME is nil, just return nil.
940 (defun Info-extract-pointer (name &optional errorname)
941 ;; Bind this in case the user sets it to nil.
942 (let ((case-fold-search t))
944 (goto-char (point-min))
946 (if (re-search-backward (concat name ":") nil t)
948 (goto-char (match-end 0))
949 (Info-following-node-name))
952 (error "Node has no %s" (capitalize (or errorname name))))))))
954 ;; Return the node name in the buffer following point.
955 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
956 ;; saying which chars may appear in the node name.
957 (defun Info-following-node-name (&optional allowedchars)
958 (skip-chars-forward " \t")
959 (buffer-substring-no-properties
962 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
963 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
965 (skip-chars-forward "^)")))
966 (skip-chars-backward " ")
970 "Go to the next node of this node."
972 (Info-goto-node (Info-extract-pointer "next")))
975 "Go to the previous node of this node."
977 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
979 (defun Info-up (&optional same-file)
980 "Go to the superior node of this node.
981 If SAME-FILE is non-nil, do not move to a different Info file."
983 (let ((node (Info-extract-pointer "up")))
985 (string-match "^(" node)
986 (error "Up node is in another Info file"))
987 (Info-goto-node node))
988 (Info-restore-point Info-history))
991 "Go back to the last node visited."
994 (error "This is the first Info node you looked at"))
995 (let (filename nodename opoint)
996 (setq filename (car (car Info-history)))
997 (setq nodename (car (cdr (car Info-history))))
998 (setq opoint (car (cdr (cdr (car Info-history)))))
999 (setq Info-history (cdr Info-history))
1000 (Info-find-node filename nodename)
1001 (setq Info-history (cdr Info-history))
1002 (goto-char opoint)))
1004 (defun Info-directory ()
1005 "Go to the Info directory node."
1007 (Info-find-node "dir" "top"))
1009 (defun Info-follow-reference (footnotename)
1010 "Follow cross reference named NAME to the node it refers to.
1011 NAME may be an abbreviation of the reference name."
1013 (let ((completion-ignore-case t)
1014 (case-fold-search t)
1015 completions default alt-default (start-point (point)) str i bol eol)
1017 ;; Store end and beginning of line.
1023 (goto-char (point-min))
1024 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1025 (setq str (buffer-substring
1028 ;; See if this one should be the default.
1030 (<= (match-beginning 0) start-point)
1031 (<= start-point (point))
1033 ;; See if this one should be the alternate default.
1034 (and (null alt-default)
1035 (and (<= bol (match-beginning 0))
1037 (setq alt-default t))
1039 (while (setq i (string-match "[ \n\t]+" str i))
1040 (setq str (concat (substring str 0 i) " "
1041 (substring str (match-end 0))))
1043 ;; Record as a completion and perhaps as default.
1044 (if (eq default t) (setq default str))
1045 (if (eq alt-default t) (setq alt-default str))
1046 ;; Don't add this string if it's a duplicate.
1047 ;; We use a loop instead of "(assoc str completions)" because
1048 ;; we want to do a case-insensitive compare.
1049 (let ((tail completions)
1050 (tem (downcase str)))
1052 (not (string-equal tem (downcase (car (car tail))))))
1053 (setq tail (cdr tail)))
1056 (cons (cons str nil)
1058 ;; If no good default was found, try an alternate.
1060 (setq default alt-default))
1061 ;; If only one cross-reference found, then make it default.
1062 (if (eq (length completions) 1)
1063 (setq default (car (car completions))))
1065 (let ((input (completing-read (if default
1066 (concat "Follow reference named: ("
1068 "Follow reference named: ")
1069 completions nil t)))
1070 (list (if (equal input "")
1072 (error "No cross-references in this node"))))
1074 (unless footnotename
1075 (error "No reference was specified"))
1077 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1078 (case-fold-search t))
1079 (while (setq i (string-match " " str i))
1080 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1083 (goto-char (point-min))
1084 (or (re-search-forward str nil t)
1085 (error "No cross-reference named %s" footnotename))
1086 (goto-char (+ (match-beginning 0) 5))
1088 (Info-extract-menu-node-name "Bad format cross reference" t)))
1089 (while (setq i (string-match "[ \t\n]+" target i))
1090 (setq target (concat (substring target 0 i) " "
1091 (substring target (match-end 0))))
1093 (Info-goto-node target)))
1095 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1096 (skip-chars-forward " \t\n")
1099 (skip-chars-forward "^:")
1102 (if (looking-at ":")
1103 (buffer-substring-no-properties beg (1- (point)))
1104 (skip-chars-forward " \t\n")
1105 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1106 (while (setq i (string-match "\n" str i))
1108 ;; Collapse multiple spaces.
1109 (while (string-match " +" str)
1110 (setq str (replace-match " " t t str)))
1113 ;; No one calls this.
1114 ;;(defun Info-menu-item-sequence (list)
1116 ;; (Info-menu (car list))
1117 ;; (setq list (cdr list))))
1119 (defvar Info-complete-menu-buffer)
1121 (defun Info-complete-menu-item (string predicate action)
1122 (let ((case-fold-search t))
1123 (cond ((eq action nil)
1125 (pattern (concat "\n\\* +\\("
1126 (regexp-quote string)
1129 (set-buffer Info-complete-menu-buffer)
1130 (goto-char (point-min))
1131 (search-forward "\n* Menu:")
1132 (while (re-search-forward pattern nil t)
1133 (setq completions (cons (cons (format "%s"
1137 (match-beginning 1))
1139 (try-completion string completions predicate)))
1142 (pattern (concat "\n\\* +\\("
1143 (regexp-quote string)
1146 (set-buffer Info-complete-menu-buffer)
1147 (goto-char (point-min))
1148 (search-forward "\n* Menu:")
1149 (while (re-search-forward pattern nil t)
1150 (setq completions (cons (cons (format "%s"
1154 (match-beginning 1))
1156 (all-completions string completions predicate)))
1159 (set-buffer Info-complete-menu-buffer)
1160 (goto-char (point-min))
1161 (search-forward "\n* Menu:")
1162 (re-search-forward (concat "\n\\* +"
1163 (regexp-quote string)
1168 (defun Info-menu (menu-item)
1169 "Go to node for menu item named (or abbreviated) NAME.
1170 Completion is allowed, and the menu item point is on is the default."
1172 (let ((completions '())
1173 ;; If point is within a menu item, use that item as the default
1179 (goto-char (point-min))
1180 (if (not (search-forward "\n* menu:" nil t))
1181 (error "No menu in this node"))
1187 (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1188 (setq default (format "%s" (buffer-substring
1193 (setq item (let ((completion-ignore-case t)
1194 (Info-complete-menu-buffer (current-buffer)))
1195 (completing-read (if default
1196 (format "Menu item (default %s): "
1199 'Info-complete-menu-item nil t)))
1200 ;; we rely on the fact that completing-read accepts an input
1201 ;; of "" even when the require-match argument is true and ""
1202 ;; is not a valid possibility
1203 (if (string= item "")
1209 ;; there is a problem here in that if several menu items have the same
1210 ;; name you can only go to the node of the first with this command.
1211 (Info-goto-node (Info-extract-menu-item menu-item)))
1213 (defun Info-extract-menu-item (menu-item)
1214 (setq menu-item (regexp-quote menu-item))
1215 (let ((case-fold-search t))
1217 (goto-char (point-min))
1218 (or (search-forward "\n* menu:" nil t)
1219 (error "No menu in this node"))
1220 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1221 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1222 (error "No such item in menu"))
1225 (Info-extract-menu-node-name))))
1227 ;; If COUNT is nil, use the last item in the menu.
1228 (defun Info-extract-menu-counting (count)
1229 (let ((case-fold-search t))
1231 (goto-char (point-min))
1232 (or (search-forward "\n* menu:" nil t)
1233 (error "No menu in this node"))
1235 (or (search-forward "\n* " nil t count)
1236 (error "Too few items in menu"))
1237 (while (search-forward "\n* " nil t)
1239 (Info-extract-menu-node-name))))
1241 (defun Info-nth-menu-item ()
1242 "Go to the node of the Nth menu item.
1243 N is the digit argument used to invoke this command."
1246 (Info-extract-menu-counting
1247 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1249 (defun Info-top-node ()
1250 "Go to the Top node of this file."
1252 (Info-goto-node "Top"))
1254 (defun Info-final-node ()
1255 "Go to the final node in this file."
1257 (Info-goto-node "Top")
1259 ;; Go to the last node in the menu of Top.
1260 (Info-goto-node (Info-extract-menu-counting nil))
1261 ;; If the last node in the menu is not last in pointer structure,
1262 ;; move forward until we can't go any farther.
1263 (while (Info-forward-node t t) nil)
1264 ;; Then keep moving down to last subnode, unless we reach an index.
1265 (while (and (not (string-match "\\<index\\>" Info-current-node))
1266 (save-excursion (search-forward "\n* Menu:" nil t)))
1267 (Info-goto-node (Info-extract-menu-counting nil)))))
1269 (defun Info-forward-node (&optional not-down no-error)
1270 "Go forward one node, considering all nodes as forming one sequence."
1272 (goto-char (point-min))
1274 ;; three possibilities, in order of priority:
1275 ;; 1. next node is in a menu in this node (but not in an index)
1276 ;; 2. next node is next at same level
1277 ;; 3. next node is up and next
1278 (cond ((and (not not-down)
1279 (save-excursion (search-forward "\n* menu:" nil t))
1280 (not (string-match "\\<index\\>" Info-current-node)))
1281 (Info-goto-node (Info-extract-menu-counting 1))
1283 ((save-excursion (search-backward "next:" nil t))
1286 ((and (save-excursion (search-backward "up:" nil t))
1287 ;; Use string-equal, not equal, to ignore text props.
1288 (not (string-equal (downcase (Info-extract-pointer "up"))
1290 (let ((old-node Info-current-node))
1292 (let (Info-history success)
1294 (setq success (Info-forward-node t no-error))
1295 (or success (Info-goto-node old-node))))))
1297 (t (error "No pointer forward from this node"))))
1299 (defun Info-backward-node ()
1300 "Go backward one node, considering all nodes as forming one sequence."
1302 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1303 (upnode (Info-extract-pointer "up" t)))
1304 (cond ((and upnode (string-match "(" upnode))
1305 (error "First node in file"))
1306 ((and upnode (or (null prevnode)
1307 ;; Use string-equal, not equal,
1308 ;; to ignore text properties.
1309 (string-equal (downcase prevnode)
1310 (downcase upnode))))
1313 ;; If we move back at the same level,
1314 ;; go down to find the last subnode*.
1317 (while (and (not (string-match "\\<index\\>" Info-current-node))
1318 (save-excursion (search-forward "\n* Menu:" nil t)))
1319 (Info-goto-node (Info-extract-menu-counting nil)))))
1321 (error "No pointer backward from this node")))))
1324 "Exit Info by selecting some other buffer."
1327 (save-buffers-kill-emacs)
1330 (defun Info-next-menu-item ()
1334 (search-forward "\n* menu:" nil t)
1335 (or (search-forward "\n* " nil t)
1336 (error "No more items in menu"))
1337 (Info-goto-node (Info-extract-menu-node-name))))
1339 (defun Info-last-menu-item ()
1343 (let ((beg (save-excursion
1344 (and (search-backward "\n* menu:" nil t)
1346 (or (and beg (search-backward "\n* " beg t))
1347 (error "No previous items in menu")))
1348 (Info-goto-node (save-excursion
1349 (goto-char (match-end 0))
1350 (Info-extract-menu-node-name)))))
1352 (defmacro Info-no-error (&rest body)
1353 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1355 (defun Info-next-preorder ()
1356 "Go to the next subnode or the next node, or go up a level."
1358 (cond ((Info-no-error (Info-next-menu-item)))
1359 ((Info-no-error (Info-next)))
1360 ((Info-no-error (Info-up t))
1361 ;; Since we have already gone thru all the items in this menu,
1362 ;; go up to the end of this node.
1363 (goto-char (point-max))
1364 ;; Since logically we are done with the node with that menu,
1366 (Info-next-preorder))
1368 (error "No more nodes"))))
1370 (defun Info-last-preorder ()
1371 "Go to the last node, popping up a level if there is none."
1373 (cond ((Info-no-error
1374 (Info-last-menu-item)
1375 ;; If we go down a menu item, go to the end of the node
1376 ;; so we can scroll back through it.
1377 (goto-char (point-max)))
1378 ;; Keep going down, as long as there are nested menu nodes.
1379 (while (Info-no-error
1380 (Info-last-menu-item)
1381 ;; If we go down a menu item, go to the end of the node
1382 ;; so we can scroll back through it.
1383 (goto-char (point-max))))
1385 ((and (not (equal (Info-extract-pointer "up")
1386 (Info-extract-pointer "prev"))))
1387 (Info-no-error (Info-prev))
1388 (goto-char (point-max))
1389 (while (Info-no-error
1390 (Info-last-menu-item)
1391 ;; If we go down a menu item, go to the end of the node
1392 ;; so we can scroll back through it.
1393 (goto-char (point-max))))
1395 ((Info-no-error (Info-up t))
1396 (goto-char (point-min))
1397 (or (search-forward "\n* Menu:" nil t)
1398 (goto-char (point-max))))
1399 (t (error "No previous nodes"))))
1401 (defun Info-scroll-up ()
1402 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1403 Once you scroll far enough in a node that its menu appears on the screen
1404 but after point, the next scroll moves into its first subnode.
1406 When you scroll past the end of a node, that goes to the next node; if
1407 this node has no successor, it moves to the parent node's successor,
1408 and so on. If point is inside the menu of a node, it moves to
1409 subnode indicated by the following menu item. (That case won't
1410 normally result from this command, but can happen in other ways.)"
1413 (if (or (< (window-start) (point-min))
1414 (> (window-start) (point-max)))
1415 (set-window-start (selected-window) (point)))
1416 (let ((virtual-end (save-excursion
1417 (goto-char (point-min))
1418 (if (search-forward "\n* Menu:" nil t)
1421 (if (or (< virtual-end (window-start))
1422 (pos-visible-in-window-p virtual-end))
1423 (Info-next-preorder)
1426 (defun Info-scroll-down ()
1427 "Scroll one screenful back in Info, considering all nodes as one sequence.
1428 Within the menu of a node, this goes to its last subnode.
1429 When you scroll past the beginning of a node, that goes to the
1430 previous node or back up to the parent node."
1432 (if (or (< (window-start) (point-min))
1433 (> (window-start) (point-max)))
1434 (set-window-start (selected-window) (point)))
1435 (let* ((current-point (point))
1436 (virtual-end (save-excursion
1438 (setq current-point (point))
1439 (goto-char (point-min))
1440 (search-forward "\n* Menu:"
1443 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1444 (Info-last-preorder)
1447 (defun Info-next-reference (&optional recur)
1448 "Move cursor to the next cross-reference or menu item in the node."
1450 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1452 (case-fold-search t))
1453 (or (eobp) (forward-char 1))
1454 (or (re-search-forward pat nil t)
1456 (goto-char (point-min))
1457 (or (re-search-forward pat nil t)
1460 (error "No cross references in this node")))))
1461 (goto-char (match-beginning 0))
1462 (if (looking-at "\\* Menu:")
1464 (error "No cross references in this node")
1465 (Info-next-reference t)))))
1467 (defun Info-prev-reference (&optional recur)
1468 "Move cursor to the previous cross-reference or menu item in the node."
1470 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1472 (case-fold-search t))
1473 (or (re-search-backward pat nil t)
1475 (goto-char (point-max))
1476 (or (re-search-backward pat nil t)
1479 (error "No cross references in this node")))))
1480 (goto-char (match-beginning 0))
1481 (if (looking-at "\\* Menu:")
1483 (error "No cross references in this node")
1484 (Info-prev-reference t)))))
1486 (defun Info-index (topic)
1487 "Look up a string in the index for this file.
1488 The index is defined as the first node in the top-level menu whose
1489 name contains the word \"Index\", plus any immediately following
1490 nodes whose names also contain the word \"Index\".
1491 If there are no exact matches to the specified topic, this chooses
1492 the first match which is a case-insensitive substring of a topic.
1493 Use the `,' command to see the other matches.
1494 Give a blank topic name to go to the Index node itself."
1495 (interactive "sIndex topic: ")
1496 (let ((orignode Info-current-node)
1498 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1499 (regexp-quote topic)))
1501 (case-fold-search t))
1502 (Info-goto-node "Top")
1503 (or (search-forward "\n* menu:" nil t)
1505 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1507 (goto-char (match-beginning 1))
1508 ;; Here, and subsequently in this function,
1509 ;; we bind Info-history to nil for internal node-switches
1510 ;; so that we don't put junk in the history.
1511 ;; In the first Info-goto-node call, above, we do update the history
1512 ;; because that is what the user's previous node choice into it.
1513 (let ((Info-history nil))
1514 (Info-goto-node (Info-extract-menu-node-name)))
1515 (or (equal topic "")
1522 (goto-char (point-min))
1523 (while (re-search-forward pattern nil t)
1525 (cons (list (buffer-substring (match-beginning 1)
1527 (buffer-substring (match-beginning 2)
1530 (string-to-int (concat "0"
1535 (and (setq node (Info-extract-pointer "next" t))
1536 (string-match "\\<Index\\>" node)))
1537 (Info-goto-node node))
1540 (Info-goto-node orignode)
1541 (error "No `%s' in index" topic)))
1542 ;; Here it is a feature that assoc is case-sensitive.
1543 (while (setq found (assoc topic matches))
1544 (setq exact (cons found exact)
1545 matches (delq found matches)))
1546 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1547 (Info-index-next 0)))))
1549 (defun Info-index-next (num)
1550 "Go to the next matching index item from the last `i' command."
1552 (or Info-index-alternatives
1553 (error "No previous `i' command"))
1555 (setq num (+ num (length Info-index-alternatives))))
1557 (setq Info-index-alternatives
1558 (nconc (cdr Info-index-alternatives)
1559 (list (car Info-index-alternatives)))
1561 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1562 (if (> (nth 3 (car Info-index-alternatives)) 0)
1563 (forward-line (nth 3 (car Info-index-alternatives)))
1564 (forward-line 3) ; don't search in headers
1565 (let ((name (car (car Info-index-alternatives))))
1566 (Info-find-index-name name)))
1567 (message "Found `%s' in %s. %s"
1568 (car (car Info-index-alternatives))
1569 (nth 2 (car Info-index-alternatives))
1570 (if (cdr Info-index-alternatives)
1571 "(Press `,' for more)"
1574 (defun Info-find-index-name (name)
1575 "Move point to the place within the current node where NAME is defined."
1576 (let ((case-fold-search t))
1577 (if (or (re-search-forward (format
1578 "[a-zA-Z]+: %s\\( \\|$\\)"
1579 (regexp-quote name)) nil t)
1580 (search-forward (format "`%s'" name) nil t)
1581 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1583 (format "`%s'" (substring name 0 (match-beginning 1)))
1585 (search-forward name nil t))
1587 (goto-char (point-min)))))
1589 (defun Info-undefined ()
1590 "Make command be undefined in Info."
1595 "Enter the Info tutorial."
1597 (delete-other-windows)
1598 (Info-find-node "info"
1599 (if (< (window-height) 23)
1603 (defun Info-summary ()
1604 "Display a brief summary of all Info commands."
1606 (save-window-excursion
1607 (switch-to-buffer "*Help*")
1608 (setq buffer-read-only nil)
1610 (insert (documentation 'Info-mode))
1612 (goto-char (point-min))
1614 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1615 (message (if flag "Type Space to see more"
1616 "Type Space to return to Info"))
1617 (if (not (eq ?\ (setq ch (read-event))))
1618 (progn (setq unread-command-events (list ch)) nil)
1621 (bury-buffer "*Help*")))
1623 (defun Info-get-token (pos start all &optional errorstring)
1624 "Return the token around POS,
1625 POS must be somewhere inside the token
1626 START is a regular expression which will match the
1627 beginning of the tokens delimited string
1628 ALL is a regular expression with a single
1629 parenthesized subpattern which is the token to be
1630 returned. E.g. '{\(.*\)}' would return any string
1631 enclosed in braces around POS.
1632 SIG optional fourth argument, controls action on no match
1635 a string: signal an error, using that string."
1636 (let ((case-fold-search t))
1639 ;; First look for a match for START that goes across POS.
1640 (while (and (not (bobp)) (> (point) (- pos (length start)))
1641 (not (looking-at start)))
1643 ;; If we did not find one, search back for START
1644 ;; (this finds only matches that end at or before POS).
1645 (or (looking-at start)
1648 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1650 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1651 (not (setq found (and (<= (match-beginning 0) pos)
1652 (> (match-end 0) pos))))))
1653 (if (and found (<= (match-beginning 0) pos)
1654 (> (match-end 0) pos))
1655 (buffer-substring (match-beginning 1) (match-end 1))
1656 (cond ((null errorstring)
1662 (error "No %s around position %d" errorstring pos))))))))
1664 (defun Info-mouse-follow-nearest-node (click)
1665 "\\<Info-mode-map>Follow a node reference near point.
1666 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1667 At end of the node's text, moves to the next node, or up if none."
1669 (let* ((start (event-start click))
1670 (window (car start))
1671 (pos (car (cdr start))))
1672 (select-window window)
1674 (and (not (Info-try-follow-nearest-node))
1675 (save-excursion (forward-line 1) (eobp))
1676 (Info-next-preorder)))
1678 (defun Info-follow-nearest-node ()
1679 "\\<Info-mode-map>Follow a node reference near point.
1680 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1681 If no reference to follow, moves to the next node, or up if none."
1683 (or (Info-try-follow-nearest-node)
1684 (Info-next-preorder)))
1686 ;; Common subroutine.
1687 (defun Info-try-follow-nearest-node ()
1688 "Follow a node reference near point. Return non-nil if successful."
1691 ((setq node (Info-get-token (point) "\\*note[ \n]"
1692 "\\*note[ \n]\\([^:]*\\):"))
1693 (Info-follow-reference node))
1694 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1695 (Info-goto-node node))
1696 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1699 (setq node (Info-extract-menu-node-name))
1700 (Info-goto-node node))
1701 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1702 (Info-goto-node node))
1703 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1704 (Info-goto-node node))
1705 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1706 (Info-goto-node "Top"))
1707 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1708 (Info-goto-node node)))
1711 (defvar Info-mode-map nil
1712 "Keymap containing Info commands.")
1715 (setq Info-mode-map (make-keymap))
1716 (suppress-keymap Info-mode-map)
1717 (define-key Info-mode-map "." 'beginning-of-buffer)
1718 (define-key Info-mode-map " " 'Info-scroll-up)
1719 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1720 (define-key Info-mode-map "\t" 'Info-next-reference)
1721 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1722 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1723 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1724 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1725 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1726 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1727 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1728 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1729 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1730 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1731 (define-key Info-mode-map "0" 'undefined)
1732 (define-key Info-mode-map "?" 'Info-summary)
1733 (define-key Info-mode-map "]" 'Info-forward-node)
1734 (define-key Info-mode-map "[" 'Info-backward-node)
1735 (define-key Info-mode-map "<" 'Info-top-node)
1736 (define-key Info-mode-map ">" 'Info-final-node)
1737 (define-key Info-mode-map "b" 'beginning-of-buffer)
1738 (define-key Info-mode-map "d" 'Info-directory)
1739 (define-key Info-mode-map "e" 'Info-edit)
1740 (define-key Info-mode-map "f" 'Info-follow-reference)
1741 (define-key Info-mode-map "g" 'Info-goto-node)
1742 (define-key Info-mode-map "h" 'Info-help)
1743 (define-key Info-mode-map "i" 'Info-index)
1744 (define-key Info-mode-map "l" 'Info-last)
1745 (define-key Info-mode-map "m" 'Info-menu)
1746 (define-key Info-mode-map "n" 'Info-next)
1747 (define-key Info-mode-map "p" 'Info-prev)
1748 (define-key Info-mode-map "q" 'Info-exit)
1749 (define-key Info-mode-map "s" 'Info-search)
1750 ;; For consistency with Rmail.
1751 (define-key Info-mode-map "\M-s" 'Info-search)
1752 (define-key Info-mode-map "t" 'Info-top-node)
1753 (define-key Info-mode-map "u" 'Info-up)
1754 (define-key Info-mode-map "," 'Info-index-next)
1755 (define-key Info-mode-map "\177" 'Info-scroll-down)
1756 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1759 (defun Info-check-pointer (item)
1760 ;; Non-nil if ITEM is present in this node.
1762 (Info-extract-pointer item)
1765 (easy-menu-define Info-mode-menu Info-mode-map
1766 "Menu for info files."
1768 ["Up" Info-up (Info-check-pointer "up")]
1769 ["Next" Info-next (Info-check-pointer "next")]
1770 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1771 ("Menu item" ["You should never see this" report-emacs-bug t])
1772 ("Reference" ["You should never see this" report-emacs-bug t])
1773 ["Search..." Info-search t]
1774 ["Goto node..." Info-goto-node t]
1775 ["Last" Info-last Info-history]
1776 ["Exit" Info-exit t]))
1778 (defvar Info-menu-last-node nil)
1779 ;; Last node the menu was created for.
1780 ;; Value is a list, (FILE-NAME NODE-NAME).
1782 (defun Info-menu-update ()
1783 ;; Update the Info menu for the current node.
1785 (if (or (not (eq major-mode 'Info-mode))
1786 (equal (list Info-current-file Info-current-node)
1787 Info-menu-last-node))
1789 ;; Update menu menu.
1790 (let* ((Info-complete-menu-buffer (current-buffer))
1791 (items (nreverse (condition-case nil
1792 (Info-complete-menu-item
1793 "" (lambda (e) t) t)
1797 (while (and items (< number 9))
1798 (setq current (car items)
1801 (setq entries (cons `[,current
1802 (Info-menu ,current)
1803 :keys ,(format "%d" number)]
1806 (setq entries (cons ["Other..." Info-menu t] entries)))
1808 (setq entries (list ["No menu" nil nil])))
1809 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1810 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1812 str i entries current
1814 (case-fold-search t))
1816 (goto-char (point-min))
1817 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1818 (setq str (buffer-substring
1822 (while (setq i (string-match "[ \n\t]+" str i))
1823 (setq str (concat (substring str 0 i) " "
1824 (substring str (match-end 0))))
1828 (while (and items (< number 9))
1829 (setq current (car items)
1832 (setq entries (cons `[,current
1833 (Info-follow-reference ,current)
1837 (setq entries (cons ["Other..." Info-follow-reference t]
1840 (setq entries (list ["No references" nil nil])))
1841 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1842 ;; Update last seen node.
1843 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1844 ;; Try to avoid entering infinite beep mode in case of errors.
1848 ;; Info mode is suitable only for specially formatted data.
1849 (put 'info-mode 'mode-class 'special)
1853 Info mode provides commands for browsing through the Info documentation tree.
1854 Documentation in Info is divided into \"nodes\", each of which discusses
1855 one topic and contains references to other nodes which discuss related
1856 topics. Info has commands to follow the references and show you other nodes.
1858 \\[Info-help] Invoke the Info tutorial.
1859 \\[Info-exit] Quit Info: reselect previously selected buffer.
1861 Selecting other nodes:
1862 \\[Info-mouse-follow-nearest-node]
1863 Follow a node reference you click on.
1864 This works with menu items, cross references, and
1865 the \"next\", \"previous\" and \"up\", depending on where you click.
1866 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1867 \\[Info-next] Move to the \"next\" node of this node.
1868 \\[Info-prev] Move to the \"previous\" node of this node.
1869 \\[Info-up] Move \"up\" from this node.
1870 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1871 Picking a menu item causes another node to be selected.
1872 \\[Info-directory] Go to the Info directory node.
1873 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1874 \\[Info-last] Move to the last node you were at.
1875 \\[Info-index] Look up a topic in this file's Index and move to that node.
1876 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1877 \\[Info-top-node] Go to the Top node of this file.
1878 \\[Info-final-node] Go to the final node in this file.
1879 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1880 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1882 Moving within a node:
1883 \\[Info-scroll-up] Normally, scroll forward a full screen.
1884 Once you scroll far enough in a node that its menu appears on the screen
1885 but after point, the next scroll moves into its first subnode.
1886 When after all menu items (or if their is no menu), move up to
1888 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1889 already visible, try to go to the previous menu entry, or up if there is none.
1890 \\[beginning-of-buffer] Go to beginning of node.
1893 \\[Info-exit] Quit Info: reselect previously selected buffer.
1894 \\[Info-edit] Edit contents of selected node.
1895 1 Pick first item in node's menu.
1896 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1897 \\[Info-goto-node] Move to node specified by name.
1898 You may include a filename as well, as (FILENAME)NODENAME.
1899 \\[universal-argument] \\[info] Move to new Info file with completion.
1900 \\[Info-search] Search through this Info file for specified regexp,
1901 and select the node in which the next occurrence is found.
1902 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1903 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1904 (kill-all-local-variables)
1905 (setq major-mode 'Info-mode)
1906 (setq mode-name "Info")
1908 (use-local-map Info-mode-map)
1909 (make-local-hook 'activate-menubar-hook)
1910 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1911 (set-syntax-table text-mode-syntax-table)
1912 (setq local-abbrev-table text-mode-abbrev-table)
1913 (setq case-fold-search t)
1914 (setq buffer-read-only t)
1915 (make-local-variable 'Info-current-file)
1916 (make-local-variable 'Info-current-subfile)
1917 (make-local-variable 'Info-current-node)
1918 (make-local-variable 'Info-tag-table-marker)
1919 (setq Info-tag-table-marker (make-marker))
1920 (make-local-variable 'Info-tag-table-buffer)
1921 (setq Info-tag-table-buffer nil)
1922 (make-local-variable 'Info-history)
1923 (make-local-variable 'Info-index-alternatives)
1924 ;; This is for the sake of the invisible text we use handling titles.
1925 (make-local-variable 'line-move-ignore-invisible)
1926 (setq line-move-ignore-invisible t)
1927 (Info-set-mode-line)
1928 (run-hooks 'Info-mode-hook))
1930 (defvar Info-edit-map nil
1931 "Local keymap used within `e' command of Info.")
1934 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1935 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1937 ;; Info-edit mode is suitable only for specially formatted data.
1938 (put 'info-edit-mode 'mode-class 'special)
1940 (defun Info-edit-mode ()
1941 "Major mode for editing the contents of an Info node.
1942 Like text mode with the addition of `Info-cease-edit'
1943 which returns to Info mode for browsing.
1945 (use-local-map Info-edit-map)
1946 (setq major-mode 'Info-edit-mode)
1947 (setq mode-name "Info Edit")
1948 (kill-local-variable 'mode-line-buffer-identification)
1949 (setq buffer-read-only nil)
1950 (force-mode-line-update)
1951 (buffer-enable-undo (current-buffer))
1952 (run-hooks 'Info-edit-mode-hook))
1955 "Edit the contents of this Info node.
1956 Allowed only if variable `Info-enable-edit' is non-nil."
1958 (or Info-enable-edit
1959 (error "Editing info nodes is not enabled"))
1961 (message "%s" (substitute-command-keys
1962 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1964 (defun Info-cease-edit ()
1965 "Finish editing Info node; switch back to Info proper."
1967 ;; Do this first, so nothing has changed if user C-g's at query.
1968 (and (buffer-modified-p)
1969 (y-or-n-p "Save the file? ")
1971 (use-local-map Info-mode-map)
1972 (setq major-mode 'Info-mode)
1973 (setq mode-name "Info")
1974 (Info-set-mode-line)
1975 (setq buffer-read-only t)
1976 (force-mode-line-update)
1977 (and (marker-position Info-tag-table-marker)
1979 (message "Tags may have changed. Use Info-tagify if necessary")))
1981 (defvar Info-file-list-for-emacs
1982 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1983 "List of Info files that describe Emacs commands.
1984 An element can be a file name, or a list of the form (PREFIX . FILE)
1985 where PREFIX is a name prefix and FILE is the file to look in.
1986 If the element is just a file name, the file name also serves as the prefix.")
1988 (defun Info-find-emacs-command-nodes (command)
1989 "Return a list of locations documenting COMMAND.
1990 The `info-file' property of COMMAND says which Info manual to search.
1991 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1992 defines heuristics for which Info manual to try.
1993 The locations are of the format used in Info-history, i.e.
1994 \(FILENAME NODENAME BUFFERPOS\)."
1996 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
1997 ":\\s *\\(.*\\)\\.$"))
1998 (info-file "emacs")) ;default
1999 ;; Determine which info file this command is documented in.
2000 (if (get command 'info-file)
2001 (setq info-file (get command 'info-file))
2002 ;; If it doesn't say explicitly, test its name against
2003 ;; various prefixes that we know.
2004 (let ((file-list Info-file-list-for-emacs))
2006 (let* ((elt (car file-list))
2007 (name (if (consp elt)
2010 (file (if (consp elt) (cdr elt) elt))
2011 (regexp (concat "\\`" (regexp-quote name)
2013 (if (string-match regexp (symbol-name command))
2014 (setq info-file file file-list nil))
2015 (setq file-list (cdr file-list))))))
2018 (Info-find-node info-file "Command Index")
2019 ;; Some manuals may not have a separate Command Index node,
2020 ;; so try just Index instead.
2022 (Info-find-node info-file "Index")))
2023 ;; Take the index node off the Info history.
2024 (setq Info-history (cdr Info-history))
2025 (goto-char (point-max))
2026 (while (re-search-backward cmd-desc nil t)
2027 (setq where (cons (list Info-current-file
2036 (defun Info-goto-emacs-command-node (command)
2037 "Go to the Info node in the Emacs manual for command COMMAND.
2038 The command is found by looking up in Emacs manual's Command Index
2039 or in another manual found via COMMAND's `info-file' property or
2040 the variable `Info-file-list-for-emacs'."
2041 (interactive "CFind documentation for command: ")
2042 (or (commandp command)
2043 (signal 'wrong-type-argument (list 'commandp command)))
2044 (let ((where (Info-find-emacs-command-nodes command)))
2046 (let ((num-matches (length where)))
2047 ;; Get Info running, and pop to it in another window.
2048 (save-window-excursion
2050 ;; FIXME It would be cool if this could use a buffer other
2052 (pop-to-buffer "*info*")
2053 (Info-find-node (car (car where))
2054 (car (cdr (car where))))
2055 (if (> num-matches 1)
2057 ;; Info-find-node already pushed (car where) onto
2058 ;; Info-history. Put the other nodes that were found on
2060 (setq Info-history (nconc (cdr where) Info-history))
2061 (message "Found %d other entr%s. Use %s to see %s."
2063 (if (> num-matches 2) "ies" "y")
2064 (substitute-command-keys "\\[Info-last]")
2065 (if (> num-matches 2) "them" "it")))))
2066 (error "Couldn't find documentation for %s" command))))
2069 (defun Info-goto-emacs-key-command-node (key)
2070 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2071 Interactively, if the binding is execute-extended-command, a command is read.
2072 The command is found by looking up in Emacs manual's Command Index
2073 or in another manual found via COMMAND's `info-file' property or
2074 the variable `Info-file-list-for-emacs'."
2075 (interactive "kFind documentation for key:")
2076 (let ((command (key-binding key)))
2077 (cond ((null command)
2078 (message "%s is undefined" (key-description key)))
2079 ((and (interactive-p)
2080 (eq command 'execute-extended-command))
2081 (Info-goto-emacs-command-node
2082 (read-command "Find documentation for command: ")))
2084 (Info-goto-emacs-command-node command)))))
2086 (defcustom Info-title-face-alist
2087 '((?* bold underline)
2088 (?= bold-italic underline)
2089 (?- italic underline))
2090 "*Alist of face or list of faces to use for pseudo-underlined titles.
2091 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2092 :type '(repeat (list character face face))
2095 (defun Info-fontify-node ()
2097 (let ((buffer-read-only nil)
2098 (case-fold-search t))
2099 (goto-char (point-min))
2100 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2101 (goto-char (match-end 0))
2103 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2104 (goto-char (match-end 0))
2106 (goto-char (match-beginning 1))
2107 (save-match-data (looking-at "Node:")))
2108 (put-text-property (match-beginning 2) (match-end 2)
2110 (put-text-property (match-beginning 2) (match-end 2)
2112 (put-text-property (match-beginning 2) (match-end 2)
2113 'mouse-face 'highlight))))
2114 (goto-char (point-min))
2115 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2117 (put-text-property (match-beginning 1) (match-end 1)
2119 (cdr (assq (preceding-char) Info-title-face-alist)))
2120 ;; This is a serious problem for trying to handle multiple
2121 ;; frame types at once. We want this text to be invisible
2122 ;; on frames that can display the font above.
2123 (if (memq (framep (selected-frame)) '(x pc w32))
2124 (put-text-property (match-end 1) (match-end 2)
2126 (goto-char (point-min))
2127 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2128 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2130 (put-text-property (match-beginning 1) (match-end 1)
2132 (put-text-property (match-beginning 1) (match-end 1)
2133 'mouse-face 'highlight)))
2134 (goto-char (point-min))
2135 (if (and (search-forward "\n* Menu:" nil t)
2136 (not (string-match "\\<Index\\>" Info-current-node))
2137 ;; Don't take time to annotate huge menus
2138 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2140 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2142 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2143 (put-text-property (match-beginning 0)
2144 (1+ (match-beginning 0))
2145 'face 'info-menu-5))
2146 (put-text-property (match-beginning 1) (match-end 1)
2148 (put-text-property (match-beginning 1) (match-end 1)
2149 'mouse-face 'highlight))))
2150 (set-buffer-modified-p nil))))
2153 ;; When an Info buffer is killed, make sure the associated tags buffer
2155 (defun Info-kill-buffer ()
2156 (and (eq major-mode 'Info-mode)
2157 Info-tag-table-buffer
2158 (kill-buffer Info-tag-table-buffer)))
2160 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2162 ;;; Speedbar support:
2163 ;; These functions permit speedbar to display the "tags" in the
2164 ;; current info node.
2165 (eval-when-compile (require 'speedbar))
2167 (defvar Info-speedbar-key-map nil
2168 "Keymap used when in the info display mode.")
2170 (defun Info-install-speedbar-variables ()
2171 "Install those variables used by speedbar to enhance Info."
2172 (if Info-speedbar-key-map
2174 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2176 ;; Basic tree features
2177 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2178 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2179 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2180 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2183 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2184 Info-speedbar-key-map
2185 Info-speedbar-hierarchy-buttons)))
2187 (defvar Info-speedbar-menu-items
2188 '(["Browse Node" speedbar-edit-line t]
2189 ["Expand Node" speedbar-expand-line
2190 (save-excursion (beginning-of-line)
2191 (looking-at "[0-9]+: *.\\+. "))]
2192 ["Contract Node" speedbar-contract-line
2193 (save-excursion (beginning-of-line)
2194 (looking-at "[0-9]+: *.-. "))]
2196 "Additional menu-items to add to speedbar frame.")
2198 ;; Make sure our special speedbar major mode is loaded
2199 (if (featurep 'speedbar)
2200 (Info-install-speedbar-variables)
2201 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2203 ;;; Info hierarchy display method
2205 (defun Info-speedbar-browser ()
2206 "Initialize speedbar to display an info node browser.
2207 This will add a speedbar major display mode."
2210 ;; Make sure that speedbar is active
2211 (speedbar-frame-mode 1)
2212 ;; Now, throw us into Info mode on speedbar.
2213 (speedbar-change-initial-expansion-list "Info")
2216 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2217 "Display an Info directory hierarchy in speedbar.
2218 DIRECTORY is the current directory in the attached frame.
2219 DEPTH is the current indentation depth.
2220 NODE is an optional argument that is used to represent the
2221 specific node to expand."
2223 (save-excursion (goto-char (point-min))
2224 (let ((case-fold-search t))
2225 (looking-at "Info Nodes:"))))
2226 ;; Update our "current node" maybe?
2228 ;; We cannot use the generic list code, that depends on all leaves
2229 ;; being known at creation time.
2231 (speedbar-with-writable (insert "Info Nodes:\n")))
2232 (let ((completions nil)
2233 (cf (selected-frame)))
2234 (select-frame speedbar-attached-frame)
2235 (save-window-excursion
2237 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2240 (speedbar-with-writable
2242 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2243 (cdr (car completions))
2244 (car (car completions))
2245 'Info-speedbar-goto-node
2246 (cdr (car completions))
2248 (setq completions (cdr completions)))
2252 (defun Info-speedbar-goto-node (text node indent)
2253 "When user clicks on TEXT, goto an info NODE.
2254 The INDENT level is ignored."
2255 (select-frame speedbar-attached-frame)
2256 (let* ((buff (or (get-buffer "*info*")
2257 (progn (info) (get-buffer "*info*"))))
2258 (bwin (get-buffer-window buff 0)))
2261 (select-window bwin)
2262 (raise-frame (window-frame bwin)))
2263 (if speedbar-power-click
2264 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2265 (select-frame speedbar-attached-frame)
2266 (switch-to-buffer buff)))
2267 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2268 (file (match-string 1 node))
2269 (node (match-string 2 node)))
2270 (Info-find-node file node)
2271 ;; If we do a find-node, and we were in info mode, restore
2272 ;; the old default method. Once we are in info mode, it makes
2273 ;; sense to return to whatever method the user was using before.
2274 (if (string= speedbar-initial-expansion-list-name "Info")
2275 (speedbar-change-initial-expansion-list
2276 speedbar-previously-used-expansion-list-name)))))
2278 (defun Info-speedbar-expand-node (text token indent)
2279 "Expand the node the user clicked on.
2280 TEXT is the text of the button we clicked on, a + or - item.
2281 TOKEN is data related to this node (NAME . FILE).
2282 INDENT is the current indentation depth."
2283 (cond ((string-match "+" text) ;we have to expand this file
2284 (speedbar-change-expand-button-char ?-)
2285 (if (speedbar-with-writable
2287 (end-of-line) (forward-char 1)
2288 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2289 (speedbar-change-expand-button-char ?-)
2290 (speedbar-change-expand-button-char ??)))
2291 ((string-match "-" text) ;we have to contract this node
2292 (speedbar-change-expand-button-char ?+)
2293 (speedbar-delete-subblock indent))
2294 (t (error "Ooops... not sure what to do")))
2295 (speedbar-center-buffer-smartly))
2297 (defun Info-speedbar-fetch-file-nodes (nodespec)
2298 "Fetch the subnodes from the info NODESPEC.
2299 NODESPEC is a string of the form: (file)node.
2300 Optional THISFILE represends the filename of"
2302 ;; Set up a buffer we can use to fake-out Info.
2303 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2304 (if (not (equal major-mode 'Info-mode))
2306 ;; Get the node into this buffer
2307 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2308 (file (match-string 1 nodespec))
2309 (node (match-string 2 nodespec)))
2310 (Info-find-node file node))
2311 ;; Scan the created buffer
2312 (goto-char (point-min))
2313 (let ((completions nil)
2314 (case-fold-search t)
2315 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2316 (match-string 1 nodespec))))
2317 ;; Always skip the first one...
2318 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2319 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2320 (let ((name (match-string 1)))
2321 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2322 (setq name (cons name (match-string 1)))
2323 (if (looking-at " *\\(([^)]+)\\)\\.")
2324 (setq name (cons name (concat (match-string 1) "Top")))
2325 (if (looking-at " \\([^.]+\\).")
2327 (cons name (concat "(" thisfile ")" (match-string 1))))
2328 (setq name (cons name (concat "(" thisfile ")" name))))))
2329 (setq completions (cons name completions))))
2330 (nreverse completions))))
2332 ;;; Info mode node listing
2333 (defun Info-speedbar-buttons (buffer)
2334 "Create a speedbar display to help navigation in an Info file.
2335 BUFFER is the buffer speedbar is requesting buttons for."
2336 (if (save-excursion (goto-char (point-min))
2337 (let ((case-fold-search t))
2338 (not (looking-at "Info Nodes:"))))
2340 (Info-speedbar-hierarchy-buttons nil 0)
2345 ;;; info.el ends here