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))))
302 (progn (pop-to-buffer "*info*")
303 (Info-goto-node (concat "(" file ")")))
304 (if (get-buffer "*info*")
305 (pop-to-buffer "*info*")
309 (defun info-standalone ()
310 "Run Emacs as a standalone Info reader.
311 Usage: emacs -f info-standalone [filename]
312 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
313 (setq Info-standalone t)
314 (if (and command-line-args-left
315 (not (string-match "^-" (car command-line-args-left))))
318 (info (car command-line-args-left))
319 (setq command-line-args-left (cdr command-line-args-left)))
320 (error (send-string-to-terminal
321 (format "%s\n" (if (eq (car-safe err) 'error)
323 (save-buffers-kill-emacs)))
326 ;; Go to an info node specified as separate filename and nodename.
327 ;; no-going-back is non-nil if recovering from an error in this function;
328 ;; it says do not attempt further (recursive) error recovery.
329 (defun Info-find-node (filename nodename &optional no-going-back)
330 ;; Convert filename to lower case if not found as specified.
333 (let (temp temp-downcase found)
334 (setq filename (substitute-in-file-name filename))
335 (if (string= (downcase filename) "dir")
337 (let ((dirs (if (string-match "^\\./" filename)
338 ;; If specified name starts with `./'
339 ;; then just try current directory.
341 (if (file-name-absolute-p filename)
342 ;; No point in searching for an
343 ;; absolute file name
345 (if Info-additional-directory-list
346 (append Info-directory-list
347 Info-additional-directory-list)
348 Info-directory-list)))))
349 ;; Search the directory list for file FILENAME.
350 (while (and dirs (not found))
351 (setq temp (expand-file-name filename (car dirs)))
353 (expand-file-name (downcase filename) (car dirs)))
354 ;; Try several variants of specified name.
355 (let ((suffix-list Info-suffix-list))
356 (while (and suffix-list (not found))
357 (cond ((info-file-exists-p
358 (info-insert-file-contents-1
359 temp (car (car suffix-list))))
362 (info-insert-file-contents-1
363 temp-downcase (car (car suffix-list))))
364 (setq found temp-downcase)))
365 (setq suffix-list (cdr suffix-list))))
366 (setq dirs (cdr dirs)))))
368 (setq filename found)
369 (error "Info file %s does not exist" filename))))
370 ;; Record the node we are leaving.
371 (if (and Info-current-file (not no-going-back))
373 (cons (list Info-current-file Info-current-node (point))
375 ;; Go into info buffer.
376 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
377 (buffer-disable-undo (current-buffer))
378 (or (eq major-mode 'Info-mode)
381 (setq Info-current-node nil)
384 ;; Switch files if necessary
386 (equal Info-current-file filename)
387 (let ((buffer-read-only nil))
388 (setq Info-current-file nil
389 Info-current-subfile nil
390 Info-current-file-completions nil
391 buffer-file-name nil)
395 (info-insert-file-contents filename t)
396 (setq default-directory (file-name-directory filename)))
397 (set-buffer-modified-p nil)
398 ;; See whether file has a tag table. Record the location if yes.
399 (goto-char (point-max))
401 ;; Use string-equal, not equal, to ignore text props.
402 (if (not (or (string-equal nodename "*")
404 (search-forward "\^_\nEnd tag table\n" nil t))))
406 ;; We have a tag table. Find its beginning.
407 ;; Is this an indirect file?
408 (search-backward "\nTag table:\n")
412 (looking-at "(Indirect)\n"))
413 ;; It is indirect. Copy it to another buffer
414 ;; and record that the tag table is in that buffer.
415 (let ((buf (current-buffer))
417 (or Info-tag-table-buffer
418 (generate-new-buffer " *info tag table*"))))
419 (setq Info-tag-table-buffer tagbuf)
422 (buffer-disable-undo (current-buffer))
423 (setq case-fold-search t)
425 (insert-buffer-substring buf))
426 (set-marker Info-tag-table-marker
427 (match-end 0) tagbuf))
428 (set-marker Info-tag-table-marker pos)))
429 (set-marker Info-tag-table-marker nil))
430 (setq Info-current-file
431 (if (eq filename t) "dir" filename))))
432 ;; Use string-equal, not equal, to ignore text props.
433 (if (string-equal nodename "*")
434 (progn (setq Info-current-node nodename)
435 (Info-set-mode-line))
438 ;; 1. Anchor found in tag table
439 ;; 2. Anchor *not* in tag table
441 ;; 3. Node found in tag table
442 ;; 4. Node *not* found in tag table, but found in file
443 ;; 5. Node *not* in tag table, and *not* in file
445 ;; *Or* the same, but in an indirect subfile.
447 ;; Search file for a suitable node.
448 (let ((guesspos (point-min))
450 (concat "\\(Node:\\|Ref:\\) *"
451 (regexp-quote nodename)
454 ;; First, search a tag table, if any
455 (if (marker-position Info-tag-table-marker)
457 (let (found-in-tag-table
459 (m Info-tag-table-marker))
461 (set-buffer (marker-buffer m))
463 (beginning-of-line) ; so re-search will work.
466 (setq found-in-tag-table
467 (re-search-forward regexp nil t))
468 (if found-in-tag-table
469 (setq guesspos (read (current-buffer))))
470 (setq found-mode major-mode))
472 ;; Indirect file among split files
473 (if found-in-tag-table
475 ;; If this is an indirect file, determine
476 ;; which file really holds this node and
478 (if (not (eq found-mode 'Info-mode))
479 ;; Note that the current buffer must be
480 ;; the *info* buffer on entry to
481 ;; Info-read-subfile. Thus the hackery
483 (setq guesspos (Info-read-subfile guesspos)))))
486 (if (and found-in-tag-table
487 (string-equal "Ref:" (match-string 1)))
490 ;; Else we may have a node, which we search for:
491 (goto-char (max (point-min) (- guesspos 1000)))
492 ;; Now search from our advised position
493 ;; (or from beg of buffer)
494 ;; to find the actual node.
496 (while (search-forward "\n\^_" nil t)
500 (if (re-search-backward regexp beg t)
505 "No such anchor in tag table or node in tag table or file: %s"
509 (goto-char (point-min))))
510 ;; If we did not finish finding the specified node,
511 ;; go back to the previous one.
512 (or Info-current-node no-going-back (null Info-history)
513 (let ((hist (car Info-history)))
514 (setq Info-history (cdr Info-history))
515 (Info-find-node (nth 0 hist) (nth 1 hist) t)
516 (goto-char (nth 2 hist))))))
518 ;; Cache the contents of the (virtual) dir file, once we have merged
519 ;; it for the first time, so we can save time subsequently.
520 (defvar Info-dir-contents nil)
522 ;; Cache for the directory we decided to use for the default-directory
523 ;; of the merged dir text.
524 (defvar Info-dir-contents-directory nil)
526 ;; Record the file attributes of all the files from which we
527 ;; constructed Info-dir-contents.
528 (defvar Info-dir-file-attributes nil)
530 ;; Construct the Info directory node by merging the files named `dir'
531 ;; from various directories. Set the *info* buffer's
532 ;; default-directory to the first directory we actually get any text
534 (defun Info-insert-dir ()
535 (if (and Info-dir-contents Info-dir-file-attributes
536 ;; Verify that none of the files we used has changed
539 (mapcar '(lambda (elt)
540 (let ((curr (file-attributes (car elt))))
541 ;; Don't compare the access time.
542 (if curr (setcar (nthcdr 4 curr) 0))
543 (setcar (nthcdr 4 (cdr elt)) 0)
544 (equal (cdr elt) curr)))
545 Info-dir-file-attributes))))
546 (insert Info-dir-contents)
547 (let ((dirs Info-directory-list)
548 buffers buffer others nodes dirs-done)
550 (setq Info-dir-file-attributes nil)
552 ;; Search the directory list for the directory file.
554 (let ((truename (file-truename (expand-file-name (car dirs)))))
555 (or (member truename dirs-done)
556 (member (directory-file-name truename) dirs-done)
557 ;; Try several variants of specified name.
558 ;; Try upcasing, appending `.info', or both.
562 (progn (setq file (expand-file-name "dir" truename))
563 (file-attributes file))
564 (progn (setq file (expand-file-name "DIR" truename))
565 (file-attributes file))
566 (progn (setq file (expand-file-name "dir.info" truename))
567 (file-attributes file))
568 (progn (setq file (expand-file-name "DIR.INFO" truename))
569 (file-attributes file)))))
572 (cons (directory-file-name truename)
577 (message "Composing main Info directory..."))
578 (set-buffer (generate-new-buffer " info dir"))
581 (insert-file-contents file)
582 (setq buffers (cons (current-buffer) buffers)
583 Info-dir-file-attributes
584 (cons (cons file attrs)
585 Info-dir-file-attributes)))
586 (error (kill-buffer (current-buffer))))))))
587 (or (cdr dirs) (setq Info-dir-contents-directory
588 (file-name-as-directory (car dirs))))
589 (setq dirs (cdr dirs))))
592 (error "Can't find the Info directory node"))
593 ;; Distinguish the dir file that comes with Emacs from all the
594 ;; others. Yes, that is really what this is supposed to do.
595 ;; If it doesn't work, fix it.
596 (setq buffer (car buffers)
597 others (cdr buffers))
599 ;; Insert the entire original dir file as a start; note that we've
600 ;; already saved its default directory to use as the default
601 ;; directory for the whole concatenation.
602 (insert-buffer buffer)
604 ;; Look at each of the other buffers one by one.
606 (let ((other (car others)))
607 ;; In each, find all the menus.
610 (goto-char (point-min))
611 ;; Find each menu, and add an elt to NODES for it.
612 (while (re-search-forward "^\\* Menu:" nil t)
613 (let (beg nodename end)
616 (search-backward "\n\^_")
617 (search-forward "Node: ")
618 (setq nodename (Info-following-node-name))
619 (search-forward "\n\^_" nil 'move)
622 (setq nodes (cons (list nodename other beg end) nodes))))))
623 (setq others (cdr others)))
624 ;; Add to the main menu a menu item for each other node.
625 (re-search-forward "^\\* Menu:")
627 (let ((menu-items '("top"))
630 (end (save-excursion (search-forward "\^_" nil t) (point))))
632 (let ((nodename (car (car nodes))))
634 (or (member (downcase nodename) menu-items)
635 (re-search-forward (concat "^\\* +"
636 (regexp-quote nodename)
640 (insert "* " nodename "::" "\n")
641 (setq menu-items (cons nodename menu-items))))))
642 (setq nodes (cdr nodes))))
643 ;; Now take each node of each of the other buffers
644 ;; and merge it into the main buffer.
646 (let ((nodename (car (car nodes))))
647 (goto-char (point-min))
648 ;; Find the like-named node in the main buffer.
649 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
650 (regexp-quote nodename)
654 (search-forward "\n\^_" nil 'move)
657 ;; If none exists, add one.
658 (goto-char (point-max))
659 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
660 ;; Merge the text from the other buffer's menu
661 ;; into the menu in the like-named node in the main buffer.
662 (apply 'insert-buffer-substring (cdr (car nodes))))
663 (setq nodes (cdr nodes)))
664 ;; Kill all the buffers we just made.
666 (kill-buffer (car buffers))
667 (setq buffers (cdr buffers)))
668 (message "Composing main Info directory...done"))
669 (setq Info-dir-contents (buffer-string)))
670 (setq default-directory Info-dir-contents-directory))
672 ;; Note that on entry to this function the current-buffer must be the
673 ;; *info* buffer; not the info tags buffer.
674 (defun Info-read-subfile (nodepos)
675 ;; NODEPOS is either a position (in the Info file as a whole,
676 ;; not relative to a subfile) or the name of a subfile.
679 (if (numberp nodepos)
681 (set-buffer (marker-buffer Info-tag-table-marker))
682 (goto-char (point-min))
683 (search-forward "\n\^_")
686 (while (not (looking-at "\^_"))
689 thisfilepos thisfilename)
690 (search-forward ": ")
691 (setq thisfilename (buffer-substring beg (- (point) 2)))
692 (setq thisfilepos (read (current-buffer)))
693 ;; read in version 19 stops at the end of number.
694 ;; Advance to the next line.
696 (if (> thisfilepos nodepos)
698 (setq lastfilename thisfilename)
699 (setq lastfilepos thisfilepos))
701 (setq lastfilename nodepos)
702 (setq lastfilepos 0))
703 ;; Assume previous buffer is in Info-mode.
704 ;; (set-buffer (get-buffer "*info*"))
705 (or (equal Info-current-subfile lastfilename)
706 (let ((buffer-read-only nil))
707 (setq buffer-file-name nil)
710 (info-insert-file-contents lastfilename)
711 (set-buffer-modified-p nil)
712 (setq Info-current-subfile lastfilename)))
713 (goto-char (point-min))
714 (search-forward "\n\^_")
715 (if (numberp nodepos)
716 (+ (- nodepos lastfilepos) (point)))))
718 ;; Select the info node that point is in.
719 (defun Info-select-node ()
721 ;; Find beginning of node.
722 (search-backward "\n\^_")
724 ;; Get nodename spelled as it is in the node.
725 (re-search-forward "Node:[ \t]*")
726 (setq Info-current-node
727 (buffer-substring-no-properties (point)
729 (skip-chars-forward "^,\t\n")
732 ;; Find the end of it, and narrow.
734 (let (active-expression)
735 (narrow-to-region (point)
736 (if (re-search-forward "\n[\^_\f]" nil t)
739 (if (looking-at "[\n\^_\f]*execute: ")
741 (goto-char (match-end 0))
742 (setq active-expression
743 (read (current-buffer))))))
745 (if Info-enable-active-nodes (eval active-expression))
746 (if Info-fontify (Info-fontify-node))
747 (run-hooks 'Info-selection-hook))))
749 (defun Info-set-mode-line ()
750 (setq mode-line-buffer-identification
753 (if Info-current-file
754 (file-name-nondirectory Info-current-file)
757 (or Info-current-node ""))))
759 ;; Go to an info node specified with a filename-and-nodename string
760 ;; of the sort that is found in pointers in nodes.
762 (defun Info-goto-node (nodename)
763 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
764 (interactive (list (Info-read-node-name "Goto node: ")))
766 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
768 (setq filename (if (= (match-beginning 1) (match-end 1))
770 (substring nodename (match-beginning 2) (match-end 2)))
771 nodename (substring nodename (match-beginning 3) (match-end 3)))
772 (let ((trim (string-match "\\s *\\'" filename)))
773 (if trim (setq filename (substring filename 0 trim))))
774 (let ((trim (string-match "\\s *\\'" nodename)))
775 (if trim (setq nodename (substring nodename 0 trim))))
776 (if transient-mark-mode (deactivate-mark))
777 (Info-find-node (if (equal filename "") nil filename)
778 (if (equal nodename "") "Top" nodename))))
780 (defvar Info-read-node-completion-table)
782 ;; This function is used as the "completion table" while reading a node name.
783 ;; It does completion using the alist in Info-read-node-completion-table
784 ;; unless STRING starts with an open-paren.
785 (defun Info-read-node-name-1 (string predicate code)
786 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
790 (try-completion string Info-read-node-completion-table predicate)))
794 (all-completions string Info-read-node-completion-table predicate)))
798 (assoc string Info-read-node-completion-table))))))
800 (defun Info-read-node-name (prompt &optional default)
801 (let* ((completion-ignore-case t)
802 (Info-read-node-completion-table (Info-build-node-completions))
803 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
804 (if (equal nodename "")
806 (Info-read-node-name prompt))
809 (defun Info-build-node-completions ()
810 (or Info-current-file-completions
814 (if (marker-buffer Info-tag-table-marker)
815 (let ((marker Info-tag-table-marker))
816 (set-buffer (marker-buffer marker))
819 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
821 (cons (list (buffer-substring (match-beginning 1)
825 (goto-char (point-min))
826 (while (search-forward "\n\^_" nil t)
830 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
833 (cons (list (buffer-substring (match-beginning 1)
836 (setq Info-current-file-completions compl))))
838 (defun Info-restore-point (hl)
839 "If this node has been visited, restore the point value when we left."
841 (if (and (equal (nth 0 (car hl)) Info-current-file)
842 ;; Use string-equal, not equal, to ignore text props.
843 (string-equal (nth 1 (car hl)) Info-current-node))
845 (goto-char (nth 2 (car hl)))
846 (setq hl nil)) ;terminate the while at next iter
847 (setq hl (cdr hl)))))
849 (defvar Info-last-search nil
850 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
852 (defun Info-search (regexp)
853 "Search for REGEXP, starting from point, and select node it's found in."
854 (interactive "sSearch (regexp): ")
855 (if transient-mark-mode (deactivate-mark))
856 (if (equal regexp "")
857 (setq regexp Info-last-search)
858 (setq Info-last-search regexp))
859 (let ((found ()) current
860 (onode Info-current-node)
861 (ofile Info-current-file)
863 (ostart (window-start))
864 (osubfile Info-current-subfile))
868 (if (null Info-current-subfile)
869 (progn (re-search-forward regexp) (setq found (point)))
871 (progn (re-search-forward regexp) (setq found (point)))
872 (search-failed nil)))))
873 (if (not found) ;can only happen in subfile case -- else would have erred
877 (set-buffer (marker-buffer Info-tag-table-marker))
878 (goto-char (point-min))
879 (search-forward "\n\^_\nIndirect:")
881 (narrow-to-region (point)
882 (progn (search-forward "\n\^_")
884 (goto-char (point-min))
885 (search-forward (concat "\n" osubfile ": "))
888 (re-search-forward "\\(^.*\\): [0-9]+$")
889 (goto-char (+ (match-end 1) 2))
890 (setq list (cons (cons (read (current-buffer))
892 (match-beginning 1) (match-end 1)))
894 (goto-char (1+ (match-end 0))))
895 (setq list (nreverse list)
896 current (car (car list))
899 (message "Searching subfile %s..." (cdr (car list)))
900 (Info-read-subfile (car (car list)))
901 (setq list (cdr list))
902 ;; (goto-char (point-min))
903 (if (re-search-forward regexp nil t)
904 (setq found (point) list ())))
907 (signal 'search-failed (list regexp))))
909 (progn (Info-read-subfile osubfile)
912 (set-window-start (selected-window) ostart)))))
916 ;; Use string-equal, not equal, to ignore text props.
917 (or (and (string-equal onode Info-current-node)
918 (equal ofile Info-current-file))
919 (setq Info-history (cons (list ofile onode opoint)
922 ;; Extract the value of the node-pointer named NAME.
923 ;; If there is none, use ERRORNAME in the error message;
924 ;; if ERRORNAME is nil, just return nil.
925 (defun Info-extract-pointer (name &optional errorname)
927 (goto-char (point-min))
929 (if (re-search-backward (concat name ":") nil t)
931 (goto-char (match-end 0))
932 (Info-following-node-name))
935 (error "Node has no %s" (capitalize (or errorname name)))))))
937 ;; Return the node name in the buffer following point.
938 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
939 ;; saying which chars may appear in the node name.
940 (defun Info-following-node-name (&optional allowedchars)
941 (skip-chars-forward " \t")
942 (buffer-substring-no-properties
945 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
946 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
948 (skip-chars-forward "^)")))
949 (skip-chars-backward " ")
953 "Go to the next node of this node."
955 (Info-goto-node (Info-extract-pointer "next")))
958 "Go to the previous node of this node."
960 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
962 (defun Info-up (&optional same-file)
963 "Go to the superior node of this node.
964 If SAME-FILE is non-nil, do not move to a different Info file."
966 (let ((node (Info-extract-pointer "up")))
968 (string-match "^(" node)
969 (error "Up node is in another Info file"))
970 (Info-goto-node node))
971 (Info-restore-point Info-history))
974 "Go back to the last node visited."
977 (error "This is the first Info node you looked at"))
978 (let (filename nodename opoint)
979 (setq filename (car (car Info-history)))
980 (setq nodename (car (cdr (car Info-history))))
981 (setq opoint (car (cdr (cdr (car Info-history)))))
982 (setq Info-history (cdr Info-history))
983 (Info-find-node filename nodename)
984 (setq Info-history (cdr Info-history))
987 (defun Info-directory ()
988 "Go to the Info directory node."
990 (Info-find-node "dir" "top"))
992 (defun Info-follow-reference (footnotename)
993 "Follow cross reference named NAME to the node it refers to.
994 NAME may be an abbreviation of the reference name."
996 (let ((completion-ignore-case t)
997 completions default alt-default (start-point (point)) str i bol eol)
999 ;; Store end and beginning of line.
1005 (goto-char (point-min))
1006 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1007 (setq str (buffer-substring
1010 ;; See if this one should be the default.
1012 (<= (match-beginning 0) start-point)
1013 (<= start-point (point))
1015 ;; See if this one should be the alternate default.
1016 (and (null alt-default)
1017 (and (<= bol (match-beginning 0))
1019 (setq alt-default t))
1021 (while (setq i (string-match "[ \n\t]+" str i))
1022 (setq str (concat (substring str 0 i) " "
1023 (substring str (match-end 0))))
1025 ;; Record as a completion and perhaps as default.
1026 (if (eq default t) (setq default str))
1027 (if (eq alt-default t) (setq alt-default str))
1028 ;; Don't add this string if it's a duplicate.
1029 ;; We use a loop instead of "(assoc str completions)" because
1030 ;; we want to do a case-insensitive compare.
1031 (let ((tail completions)
1032 (tem (downcase str)))
1034 (not (string-equal tem (downcase (car (car tail))))))
1035 (setq tail (cdr tail)))
1038 (cons (cons str nil)
1040 ;; If no good default was found, try an alternate.
1042 (setq default alt-default))
1043 ;; If only one cross-reference found, then make it default.
1044 (if (eq (length completions) 1)
1045 (setq default (car (car completions))))
1047 (let ((input (completing-read (if default
1048 (concat "Follow reference named: ("
1050 "Follow reference named: ")
1051 completions nil t)))
1052 (list (if (equal input "")
1054 (error "No cross-references in this node"))))
1055 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename))))
1056 (while (setq i (string-match " " str i))
1057 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1060 (goto-char (point-min))
1061 (or (re-search-forward str nil t)
1062 (error "No cross-reference named %s" footnotename))
1063 (goto-char (+ (match-beginning 0) 5))
1065 (Info-extract-menu-node-name "Bad format cross reference" t)))
1066 (while (setq i (string-match "[ \t\n]+" target i))
1067 (setq target (concat (substring target 0 i) " "
1068 (substring target (match-end 0))))
1070 (Info-goto-node target)))
1072 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1073 (skip-chars-forward " \t\n")
1076 (skip-chars-forward "^:")
1079 (if (looking-at ":")
1080 (buffer-substring-no-properties beg (1- (point)))
1081 (skip-chars-forward " \t\n")
1082 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1083 (while (setq i (string-match "\n" str i))
1085 ;; Collapse multiple spaces.
1086 (while (string-match " +" str)
1087 (setq str (replace-match " " t t str)))
1090 ;; No one calls this.
1091 ;;(defun Info-menu-item-sequence (list)
1093 ;; (Info-menu (car list))
1094 ;; (setq list (cdr list))))
1096 (defvar Info-complete-menu-buffer)
1098 (defun Info-complete-menu-item (string predicate action)
1099 (let ((case-fold-search t))
1100 (cond ((eq action nil)
1102 (pattern (concat "\n\\* +\\("
1103 (regexp-quote string)
1106 (set-buffer Info-complete-menu-buffer)
1107 (goto-char (point-min))
1108 (search-forward "\n* Menu:")
1109 (while (re-search-forward pattern nil t)
1110 (setq completions (cons (cons (format "%s"
1114 (match-beginning 1))
1116 (try-completion string completions predicate)))
1119 (pattern (concat "\n\\* +\\("
1120 (regexp-quote string)
1123 (set-buffer Info-complete-menu-buffer)
1124 (goto-char (point-min))
1125 (search-forward "\n* Menu:")
1126 (while (re-search-forward pattern nil t)
1127 (setq completions (cons (cons (format "%s"
1131 (match-beginning 1))
1133 (all-completions string completions predicate)))
1136 (set-buffer Info-complete-menu-buffer)
1137 (goto-char (point-min))
1138 (search-forward "\n* Menu:")
1139 (re-search-forward (concat "\n\\* +"
1140 (regexp-quote string)
1145 (defun Info-menu (menu-item)
1146 "Go to node for menu item named (or abbreviated) NAME.
1147 Completion is allowed, and the menu item point is on is the default."
1149 (let ((completions '())
1150 ;; If point is within a menu item, use that item as the default
1156 (goto-char (point-min))
1157 (if (not (search-forward "\n* menu:" nil t))
1158 (error "No menu in this node"))
1164 (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1165 (setq default (format "%s" (buffer-substring
1170 (setq item (let ((completion-ignore-case t)
1171 (Info-complete-menu-buffer (current-buffer)))
1172 (completing-read (if default
1173 (format "Menu item (default %s): "
1176 'Info-complete-menu-item nil t)))
1177 ;; we rely on the fact that completing-read accepts an input
1178 ;; of "" even when the require-match argument is true and ""
1179 ;; is not a valid possibility
1180 (if (string= item "")
1186 ;; there is a problem here in that if several menu items have the same
1187 ;; name you can only go to the node of the first with this command.
1188 (Info-goto-node (Info-extract-menu-item menu-item)))
1190 (defun Info-extract-menu-item (menu-item)
1191 (setq menu-item (regexp-quote menu-item))
1193 (goto-char (point-min))
1194 (or (search-forward "\n* menu:" nil t)
1195 (error "No menu in this node"))
1196 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1197 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1198 (error "No such item in menu"))
1201 (Info-extract-menu-node-name)))
1203 ;; If COUNT is nil, use the last item in the menu.
1204 (defun Info-extract-menu-counting (count)
1206 (goto-char (point-min))
1207 (or (search-forward "\n* menu:" nil t)
1208 (error "No menu in this node"))
1210 (or (search-forward "\n* " nil t count)
1211 (error "Too few items in menu"))
1212 (while (search-forward "\n* " nil t)
1214 (Info-extract-menu-node-name)))
1216 (defun Info-nth-menu-item ()
1217 "Go to the node of the Nth menu item.
1218 N is the digit argument used to invoke this command."
1221 (Info-extract-menu-counting
1222 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1224 (defun Info-top-node ()
1225 "Go to the Top node of this file."
1227 (Info-goto-node "Top"))
1229 (defun Info-final-node ()
1230 "Go to the final node in this file."
1232 (Info-goto-node "Top")
1234 ;; Go to the last node in the menu of Top.
1235 (Info-goto-node (Info-extract-menu-counting nil))
1236 ;; If the last node in the menu is not last in pointer structure,
1237 ;; move forward until we can't go any farther.
1238 (while (Info-forward-node t t) nil)
1239 ;; Then keep moving down to last subnode, unless we reach an index.
1240 (while (and (not (string-match "\\<index\\>" Info-current-node))
1241 (save-excursion (search-forward "\n* Menu:" nil t)))
1242 (Info-goto-node (Info-extract-menu-counting nil)))))
1244 (defun Info-forward-node (&optional not-down no-error)
1245 "Go forward one node, considering all nodes as forming one sequence."
1247 (goto-char (point-min))
1249 ;; three possibilities, in order of priority:
1250 ;; 1. next node is in a menu in this node (but not in an index)
1251 ;; 2. next node is next at same level
1252 ;; 3. next node is up and next
1253 (cond ((and (not not-down)
1254 (save-excursion (search-forward "\n* menu:" nil t))
1255 (not (string-match "\\<index\\>" Info-current-node)))
1256 (Info-goto-node (Info-extract-menu-counting 1))
1258 ((save-excursion (search-backward "next:" nil t))
1261 ((and (save-excursion (search-backward "up:" nil t))
1262 ;; Use string-equal, not equal, to ignore text props.
1263 (not (string-equal (downcase (Info-extract-pointer "up"))
1265 (let ((old-node Info-current-node))
1267 (let (Info-history success)
1269 (setq success (Info-forward-node t no-error))
1270 (or success (Info-goto-node old-node))))))
1272 (t (error "No pointer forward from this node"))))
1274 (defun Info-backward-node ()
1275 "Go backward one node, considering all nodes as forming one sequence."
1277 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1278 (upnode (Info-extract-pointer "up" t)))
1279 (cond ((and upnode (string-match "(" upnode))
1280 (error "First node in file"))
1281 ((and upnode (or (null prevnode)
1282 ;; Use string-equal, not equal,
1283 ;; to ignore text properties.
1284 (string-equal (downcase prevnode)
1285 (downcase upnode))))
1288 ;; If we move back at the same level,
1289 ;; go down to find the last subnode*.
1292 (while (and (not (string-match "\\<index\\>" Info-current-node))
1293 (save-excursion (search-forward "\n* Menu:" nil t)))
1294 (Info-goto-node (Info-extract-menu-counting nil)))))
1296 (error "No pointer backward from this node")))))
1299 "Exit Info by selecting some other buffer."
1302 (save-buffers-kill-emacs)
1305 (defun Info-next-menu-item ()
1309 (search-forward "\n* menu:" nil t)
1310 (or (search-forward "\n* " nil t)
1311 (error "No more items in menu"))
1312 (Info-goto-node (Info-extract-menu-node-name))))
1314 (defun Info-last-menu-item ()
1318 (let ((beg (save-excursion
1319 (and (search-backward "\n* menu:" nil t)
1321 (or (and beg (search-backward "\n* " beg t))
1322 (error "No previous items in menu")))
1323 (Info-goto-node (save-excursion
1324 (goto-char (match-end 0))
1325 (Info-extract-menu-node-name)))))
1327 (defmacro Info-no-error (&rest body)
1328 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1330 (defun Info-next-preorder ()
1331 "Go to the next subnode or the next node, or go up a level."
1333 (cond ((Info-no-error (Info-next-menu-item)))
1334 ((Info-no-error (Info-next)))
1335 ((Info-no-error (Info-up t))
1336 ;; Since we have already gone thru all the items in this menu,
1337 ;; go up to the end of this node.
1338 (goto-char (point-max))
1339 ;; Since logically we are done with the node with that menu,
1341 (Info-next-preorder))
1343 (error "No more nodes"))))
1345 (defun Info-last-preorder ()
1346 "Go to the last node, popping up a level if there is none."
1348 (cond ((Info-no-error
1349 (Info-last-menu-item)
1350 ;; If we go down a menu item, go to the end of the node
1351 ;; so we can scroll back through it.
1352 (goto-char (point-max)))
1353 ;; Keep going down, as long as there are nested menu nodes.
1354 (while (Info-no-error
1355 (Info-last-menu-item)
1356 ;; If we go down a menu item, go to the end of the node
1357 ;; so we can scroll back through it.
1358 (goto-char (point-max))))
1360 ((and (not (equal (Info-extract-pointer "up")
1361 (Info-extract-pointer "prev"))))
1362 (Info-no-error (Info-prev))
1363 (goto-char (point-max))
1364 (while (Info-no-error
1365 (Info-last-menu-item)
1366 ;; If we go down a menu item, go to the end of the node
1367 ;; so we can scroll back through it.
1368 (goto-char (point-max))))
1370 ((Info-no-error (Info-up t))
1371 (goto-char (point-min))
1372 (or (search-forward "\n* Menu:" nil t)
1373 (goto-char (point-max))))
1374 (t (error "No previous nodes"))))
1376 (defun Info-scroll-up ()
1377 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1378 Once you scroll far enough in a node that its menu appears on the screen
1379 but after point, the next scroll moves into its first subnode.
1381 When you scroll past the end of a node, that goes to the next node; if
1382 this node has no successor, it moves to the parent node's successor,
1383 and so on. If point is inside the menu of a node, it moves to
1384 subnode indicated by the following menu item. (That case won't
1385 normally result from this command, but can happen in other ways.)"
1388 (if (or (< (window-start) (point-min))
1389 (> (window-start) (point-max)))
1390 (set-window-start (selected-window) (point)))
1391 (let ((virtual-end (save-excursion
1392 (goto-char (point-min))
1393 (if (search-forward "\n* Menu:" nil t)
1396 (if (or (< virtual-end (window-start))
1397 (pos-visible-in-window-p virtual-end))
1398 (Info-next-preorder)
1401 (defun Info-scroll-down ()
1402 "Scroll one screenful back in Info, considering all nodes as one sequence.
1403 Within the menu of a node, this goes to its last subnode.
1404 When you scroll past the beginning of a node, that goes to the
1405 previous node or back up to the parent node."
1407 (if (or (< (window-start) (point-min))
1408 (> (window-start) (point-max)))
1409 (set-window-start (selected-window) (point)))
1410 (let* ((current-point (point))
1411 (virtual-end (save-excursion
1413 (setq current-point (point))
1414 (goto-char (point-min))
1415 (search-forward "\n* Menu:"
1418 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1419 (Info-last-preorder)
1422 (defun Info-next-reference (&optional recur)
1423 "Move cursor to the next cross-reference or menu item in the node."
1425 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1427 (or (eobp) (forward-char 1))
1428 (or (re-search-forward pat nil t)
1430 (goto-char (point-min))
1431 (or (re-search-forward pat nil t)
1434 (error "No cross references in this node")))))
1435 (goto-char (match-beginning 0))
1436 (if (looking-at "\\* Menu:")
1438 (error "No cross references in this node")
1439 (Info-next-reference t)))))
1441 (defun Info-prev-reference (&optional recur)
1442 "Move cursor to the previous cross-reference or menu item in the node."
1444 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1446 (or (re-search-backward pat nil t)
1448 (goto-char (point-max))
1449 (or (re-search-backward pat nil t)
1452 (error "No cross references in this node")))))
1453 (goto-char (match-beginning 0))
1454 (if (looking-at "\\* Menu:")
1456 (error "No cross references in this node")
1457 (Info-prev-reference t)))))
1459 (defun Info-index (topic)
1460 "Look up a string in the index for this file.
1461 The index is defined as the first node in the top-level menu whose
1462 name contains the word \"Index\", plus any immediately following
1463 nodes whose names also contain the word \"Index\".
1464 If there are no exact matches to the specified topic, this chooses
1465 the first match which is a case-insensitive substring of a topic.
1466 Use the `,' command to see the other matches.
1467 Give a blank topic name to go to the Index node itself."
1468 (interactive "sIndex topic: ")
1469 (let ((orignode Info-current-node)
1471 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1472 (regexp-quote topic)))
1474 (Info-goto-node "Top")
1475 (or (search-forward "\n* menu:" nil t)
1477 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1479 (goto-char (match-beginning 1))
1480 ;; Here, and subsequently in this function,
1481 ;; we bind Info-history to nil for internal node-switches
1482 ;; so that we don't put junk in the history.
1483 ;; In the first Info-goto-node call, above, we do update the history
1484 ;; because that is what the user's previous node choice into it.
1485 (let ((Info-history nil))
1486 (Info-goto-node (Info-extract-menu-node-name)))
1487 (or (equal topic "")
1494 (goto-char (point-min))
1495 (while (re-search-forward pattern nil t)
1497 (cons (list (buffer-substring (match-beginning 1)
1499 (buffer-substring (match-beginning 2)
1502 (string-to-int (concat "0"
1507 (and (setq node (Info-extract-pointer "next" t))
1508 (string-match "\\<Index\\>" node)))
1509 (Info-goto-node node))
1512 (Info-goto-node orignode)
1513 (error "No `%s' in index" topic)))
1514 ;; Here it is a feature that assoc is case-sensitive.
1515 (while (setq found (assoc topic matches))
1516 (setq exact (cons found exact)
1517 matches (delq found matches)))
1518 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1519 (Info-index-next 0)))))
1521 (defun Info-index-next (num)
1522 "Go to the next matching index item from the last `i' command."
1524 (or Info-index-alternatives
1525 (error "No previous `i' command"))
1527 (setq num (+ num (length Info-index-alternatives))))
1529 (setq Info-index-alternatives
1530 (nconc (cdr Info-index-alternatives)
1531 (list (car Info-index-alternatives)))
1533 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1534 (if (> (nth 3 (car Info-index-alternatives)) 0)
1535 (forward-line (nth 3 (car Info-index-alternatives)))
1536 (forward-line 3) ; don't search in headers
1537 (let ((name (car (car Info-index-alternatives))))
1538 (Info-find-index-name name)))
1539 (message "Found `%s' in %s. %s"
1540 (car (car Info-index-alternatives))
1541 (nth 2 (car Info-index-alternatives))
1542 (if (cdr Info-index-alternatives)
1543 "(Press `,' for more)"
1546 (defun Info-find-index-name (name)
1547 "Move point to the place within the current node where NAME is defined."
1548 (if (or (re-search-forward (format
1549 "[a-zA-Z]+: %s\\( \\|$\\)"
1550 (regexp-quote name)) nil t)
1551 (search-forward (format "`%s'" name) nil t)
1552 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1554 (format "`%s'" (substring name 0 (match-beginning 1)))
1556 (search-forward name nil t))
1558 (goto-char (point-min))))
1560 (defun Info-undefined ()
1561 "Make command be undefined in Info."
1566 "Enter the Info tutorial."
1568 (delete-other-windows)
1569 (Info-find-node "info"
1570 (if (< (window-height) 23)
1574 (defun Info-summary ()
1575 "Display a brief summary of all Info commands."
1577 (save-window-excursion
1578 (switch-to-buffer "*Help*")
1579 (setq buffer-read-only nil)
1581 (insert (documentation 'Info-mode))
1583 (goto-char (point-min))
1585 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1586 (message (if flag "Type Space to see more"
1587 "Type Space to return to Info"))
1588 (if (not (eq ?\ (setq ch (read-event))))
1589 (progn (setq unread-command-events (list ch)) nil)
1592 (bury-buffer "*Help*")))
1594 (defun Info-get-token (pos start all &optional errorstring)
1595 "Return the token around POS,
1596 POS must be somewhere inside the token
1597 START is a regular expression which will match the
1598 beginning of the tokens delimited string
1599 ALL is a regular expression with a single
1600 parenthesized subpattern which is the token to be
1601 returned. E.g. '{\(.*\)}' would return any string
1602 enclosed in braces around POS.
1603 SIG optional fourth argument, controls action on no match
1606 a string: signal an error, using that string."
1609 ;; First look for a match for START that goes across POS.
1610 (while (and (not (bobp)) (> (point) (- pos (length start)))
1611 (not (looking-at start)))
1613 ;; If we did not find one, search back for START
1614 ;; (this finds only matches that end at or before POS).
1615 (or (looking-at start)
1618 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1620 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1621 (not (setq found (and (<= (match-beginning 0) pos)
1622 (> (match-end 0) pos))))))
1623 (if (and found (<= (match-beginning 0) pos)
1624 (> (match-end 0) pos))
1625 (buffer-substring (match-beginning 1) (match-end 1))
1626 (cond ((null errorstring)
1632 (error "No %s around position %d" errorstring pos)))))))
1634 (defun Info-mouse-follow-nearest-node (click)
1635 "\\<Info-mode-map>Follow a node reference near point.
1636 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1637 At end of the node's text, moves to the next node, or up if none."
1639 (let* ((start (event-start click))
1640 (window (car start))
1641 (pos (car (cdr start))))
1642 (select-window window)
1644 (and (not (Info-try-follow-nearest-node))
1645 (save-excursion (forward-line 1) (eobp))
1646 (Info-next-preorder)))
1648 (defun Info-follow-nearest-node ()
1649 "\\<Info-mode-map>Follow a node reference near point.
1650 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1651 If no reference to follow, moves to the next node, or up if none."
1653 (or (Info-try-follow-nearest-node)
1654 (Info-next-preorder)))
1656 ;; Common subroutine.
1657 (defun Info-try-follow-nearest-node ()
1658 "Follow a node reference near point. Return non-nil if successful."
1661 ((setq node (Info-get-token (point) "\\*note[ \n]"
1662 "\\*note[ \n]\\([^:]*\\):"))
1663 (Info-follow-reference node))
1664 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1665 (Info-goto-node node))
1666 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):"))
1668 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1669 (Info-goto-node node))
1670 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1671 (Info-goto-node node))
1672 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1673 (Info-goto-node "Top"))
1674 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1675 (Info-goto-node node)))
1678 (defvar Info-mode-map nil
1679 "Keymap containing Info commands.")
1682 (setq Info-mode-map (make-keymap))
1683 (suppress-keymap Info-mode-map)
1684 (define-key Info-mode-map "." 'beginning-of-buffer)
1685 (define-key Info-mode-map " " 'Info-scroll-up)
1686 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1687 (define-key Info-mode-map "\t" 'Info-next-reference)
1688 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1689 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1690 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1691 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1692 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1693 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1694 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1695 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1696 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1697 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1698 (define-key Info-mode-map "0" 'undefined)
1699 (define-key Info-mode-map "?" 'Info-summary)
1700 (define-key Info-mode-map "]" 'Info-forward-node)
1701 (define-key Info-mode-map "[" 'Info-backward-node)
1702 (define-key Info-mode-map "<" 'Info-top-node)
1703 (define-key Info-mode-map ">" 'Info-final-node)
1704 (define-key Info-mode-map "b" 'beginning-of-buffer)
1705 (define-key Info-mode-map "d" 'Info-directory)
1706 (define-key Info-mode-map "e" 'Info-edit)
1707 (define-key Info-mode-map "f" 'Info-follow-reference)
1708 (define-key Info-mode-map "g" 'Info-goto-node)
1709 (define-key Info-mode-map "h" 'Info-help)
1710 (define-key Info-mode-map "i" 'Info-index)
1711 (define-key Info-mode-map "l" 'Info-last)
1712 (define-key Info-mode-map "m" 'Info-menu)
1713 (define-key Info-mode-map "n" 'Info-next)
1714 (define-key Info-mode-map "p" 'Info-prev)
1715 (define-key Info-mode-map "q" 'Info-exit)
1716 (define-key Info-mode-map "s" 'Info-search)
1717 ;; For consistency with Rmail.
1718 (define-key Info-mode-map "\M-s" 'Info-search)
1719 (define-key Info-mode-map "t" 'Info-top-node)
1720 (define-key Info-mode-map "u" 'Info-up)
1721 (define-key Info-mode-map "," 'Info-index-next)
1722 (define-key Info-mode-map "\177" 'Info-scroll-down)
1723 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1726 (defun Info-check-pointer (item)
1727 ;; Non-nil if ITEM is present in this node.
1729 (Info-extract-pointer item)
1732 (easy-menu-define Info-mode-menu Info-mode-map
1733 "Menu for info files."
1735 ["Up" Info-up (Info-check-pointer "up")]
1736 ["Next" Info-next (Info-check-pointer "next")]
1737 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1738 ("Menu item" ["You should never see this" report-emacs-bug t])
1739 ("Reference" ["You should never see this" report-emacs-bug t])
1740 ["Search..." Info-search t]
1741 ["Goto node..." Info-goto-node t]
1742 ["Last" Info-last Info-history]
1743 ["Exit" Info-exit t]))
1745 (defvar Info-menu-last-node nil)
1746 ;; Last node the menu was created for.
1747 ;; Value is a list, (FILE-NAME NODE-NAME).
1749 (defun Info-menu-update ()
1750 ;; Update the Info menu for the current node.
1752 (if (or (not (eq major-mode 'Info-mode))
1753 (equal (list Info-current-file Info-current-node)
1754 Info-menu-last-node))
1756 ;; Update menu menu.
1757 (let* ((Info-complete-menu-buffer (current-buffer))
1758 (items (nreverse (condition-case nil
1759 (Info-complete-menu-item
1760 "" (lambda (e) t) t)
1764 (while (and items (< number 9))
1765 (setq current (car items)
1768 (setq entries (cons `[,current
1769 (Info-menu ,current)
1770 :keys ,(format "%d" number)]
1773 (setq entries (cons ["Other..." Info-menu t] entries)))
1775 (setq entries (list ["No menu" nil nil])))
1776 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1777 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1779 str i entries current
1782 (goto-char (point-min))
1783 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1784 (setq str (buffer-substring
1788 (while (setq i (string-match "[ \n\t]+" str i))
1789 (setq str (concat (substring str 0 i) " "
1790 (substring str (match-end 0))))
1794 (while (and items (< number 9))
1795 (setq current (car items)
1798 (setq entries (cons `[,current
1799 (Info-follow-reference ,current)
1803 (setq entries (cons ["Other..." Info-follow-reference t]
1806 (setq entries (list ["No references" nil nil])))
1807 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1808 ;; Update last seen node.
1809 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1810 ;; Try to avoid entering infinite beep mode in case of errors.
1814 ;; Info mode is suitable only for specially formatted data.
1815 (put 'info-mode 'mode-class 'special)
1819 Info mode provides commands for browsing through the Info documentation tree.
1820 Documentation in Info is divided into \"nodes\", each of which discusses
1821 one topic and contains references to other nodes which discuss related
1822 topics. Info has commands to follow the references and show you other nodes.
1824 \\[Info-help] Invoke the Info tutorial.
1825 \\[Info-exit] Quit Info: reselect previously selected buffer.
1827 Selecting other nodes:
1828 \\[Info-mouse-follow-nearest-node]
1829 Follow a node reference you click on.
1830 This works with menu items, cross references, and
1831 the \"next\", \"previous\" and \"up\", depending on where you click.
1832 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1833 \\[Info-next] Move to the \"next\" node of this node.
1834 \\[Info-prev] Move to the \"previous\" node of this node.
1835 \\[Info-up] Move \"up\" from this node.
1836 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1837 Picking a menu item causes another node to be selected.
1838 \\[Info-directory] Go to the Info directory node.
1839 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1840 \\[Info-last] Move to the last node you were at.
1841 \\[Info-index] Look up a topic in this file's Index and move to that node.
1842 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1843 \\[Info-top-node] Go to the Top node of this file.
1844 \\[Info-final-node] Go to the final node in this file.
1845 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1846 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1848 Moving within a node:
1849 \\[Info-scroll-up] Normally, scroll forward a full screen.
1850 Once you scroll far enough in a node that its menu appears on the screen
1851 but after point, the next scroll moves into its first subnode.
1852 When after all menu items (or if their is no menu), move up to
1854 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1855 already visible, try to go to the previous menu entry, or up if there is none.
1856 \\[beginning-of-buffer] Go to beginning of node.
1859 \\[Info-exit] Quit Info: reselect previously selected buffer.
1860 \\[Info-edit] Edit contents of selected node.
1861 1 Pick first item in node's menu.
1862 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1863 \\[Info-goto-node] Move to node specified by name.
1864 You may include a filename as well, as (FILENAME)NODENAME.
1865 \\[universal-argument] \\[info] Move to new Info file with completion.
1866 \\[Info-search] Search through this Info file for specified regexp,
1867 and select the node in which the next occurrence is found.
1868 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1869 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1870 (kill-all-local-variables)
1871 (setq major-mode 'Info-mode)
1872 (setq mode-name "Info")
1874 (use-local-map Info-mode-map)
1875 (make-local-hook 'activate-menubar-hook)
1876 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1877 (set-syntax-table text-mode-syntax-table)
1878 (setq local-abbrev-table text-mode-abbrev-table)
1879 (setq case-fold-search t)
1880 (setq buffer-read-only t)
1881 (make-local-variable 'Info-current-file)
1882 (make-local-variable 'Info-current-subfile)
1883 (make-local-variable 'Info-current-node)
1884 (make-local-variable 'Info-tag-table-marker)
1885 (setq Info-tag-table-marker (make-marker))
1886 (make-local-variable 'Info-tag-table-buffer)
1887 (setq Info-tag-table-buffer nil)
1888 (make-local-variable 'Info-history)
1889 (make-local-variable 'Info-index-alternatives)
1890 ;; This is for the sake of the invisible text we use handling titles.
1891 (make-local-variable 'line-move-ignore-invisible)
1892 (setq line-move-ignore-invisible t)
1893 (Info-set-mode-line)
1894 (run-hooks 'Info-mode-hook))
1896 (defvar Info-edit-map nil
1897 "Local keymap used within `e' command of Info.")
1900 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1901 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1903 ;; Info-edit mode is suitable only for specially formatted data.
1904 (put 'info-edit-mode 'mode-class 'special)
1906 (defun Info-edit-mode ()
1907 "Major mode for editing the contents of an Info node.
1908 Like text mode with the addition of `Info-cease-edit'
1909 which returns to Info mode for browsing.
1911 (use-local-map Info-edit-map)
1912 (setq major-mode 'Info-edit-mode)
1913 (setq mode-name "Info Edit")
1914 (kill-local-variable 'mode-line-buffer-identification)
1915 (setq buffer-read-only nil)
1916 (force-mode-line-update)
1917 (buffer-enable-undo (current-buffer))
1918 (run-hooks 'Info-edit-mode-hook))
1921 "Edit the contents of this Info node.
1922 Allowed only if variable `Info-enable-edit' is non-nil."
1924 (or Info-enable-edit
1925 (error "Editing info nodes is not enabled"))
1927 (message "%s" (substitute-command-keys
1928 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1930 (defun Info-cease-edit ()
1931 "Finish editing Info node; switch back to Info proper."
1933 ;; Do this first, so nothing has changed if user C-g's at query.
1934 (and (buffer-modified-p)
1935 (y-or-n-p "Save the file? ")
1937 (use-local-map Info-mode-map)
1938 (setq major-mode 'Info-mode)
1939 (setq mode-name "Info")
1940 (Info-set-mode-line)
1941 (setq buffer-read-only t)
1942 (force-mode-line-update)
1943 (and (marker-position Info-tag-table-marker)
1945 (message "Tags may have changed. Use Info-tagify if necessary")))
1947 (defvar Info-file-list-for-emacs
1948 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1949 "List of Info files that describe Emacs commands.
1950 An element can be a file name, or a list of the form (PREFIX . FILE)
1951 where PREFIX is a name prefix and FILE is the file to look in.
1952 If the element is just a file name, the file name also serves as the prefix.")
1954 (defun Info-find-emacs-command-nodes (command)
1955 "Return a list of locations documenting COMMAND.
1956 The `info-file' property of COMMAND says which Info manual to search.
1957 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1958 defines heuristics for which Info manual to try.
1959 The locations are of the format used in Info-history, i.e.
1960 \(FILENAME NODENAME BUFFERPOS\)."
1962 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
1963 ":\\s *\\(.*\\)\\.$"))
1964 (info-file "emacs")) ;default
1965 ;; Determine which info file this command is documented in.
1966 (if (get command 'info-file)
1967 (setq info-file (get command 'info-file))
1968 ;; If it doesn't say explicitly, test its name against
1969 ;; various prefixes that we know.
1970 (let ((file-list Info-file-list-for-emacs))
1972 (let* ((elt (car file-list))
1973 (name (if (consp elt)
1976 (file (if (consp elt) (cdr elt) elt))
1977 (regexp (concat "\\`" (regexp-quote name)
1979 (if (string-match regexp (symbol-name command))
1980 (setq info-file file file-list nil))
1981 (setq file-list (cdr file-list))))))
1984 (Info-find-node info-file "Command Index")
1985 ;; Some manuals may not have a separate Command Index node,
1986 ;; so try just Index instead.
1988 (Info-find-node info-file "Index")))
1989 ;; Take the index node off the Info history.
1990 (setq Info-history (cdr Info-history))
1991 (goto-char (point-max))
1992 (while (re-search-backward cmd-desc nil t)
1993 (setq where (cons (list Info-current-file
2002 (defun Info-goto-emacs-command-node (command)
2003 "Go to the Info node in the Emacs manual for command COMMAND.
2004 The command is found by looking up in Emacs manual's Command Index
2005 or in another manual found via COMMAND's `info-file' property or
2006 the variable `Info-file-list-for-emacs'."
2007 (interactive "CFind documentation for command: ")
2008 (or (commandp command)
2009 (signal 'wrong-type-argument (list 'commandp command)))
2010 (let ((where (Info-find-emacs-command-nodes command)))
2012 (let ((num-matches (length where)))
2013 ;; Get Info running, and pop to it in another window.
2014 (save-window-excursion
2016 ;; FIXME It would be cool if this could use a buffer other
2018 (pop-to-buffer "*info*")
2019 (Info-find-node (car (car where))
2020 (car (cdr (car where))))
2021 (if (> num-matches 1)
2023 ;; Info-find-node already pushed (car where) onto
2024 ;; Info-history. Put the other nodes that were found on
2026 (setq Info-history (nconc (cdr where) Info-history))
2027 (message "Found %d other entr%s. Use %s to see %s."
2029 (if (> num-matches 2) "ies" "y")
2030 (substitute-command-keys "\\[Info-last]")
2031 (if (> num-matches 2) "them" "it")))))
2032 (error "Couldn't find documentation for %s" command))))
2035 (defun Info-goto-emacs-key-command-node (key)
2036 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2037 Interactively, if the binding is execute-extended-command, a command is read.
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 "kFind documentation for key:")
2042 (let ((command (key-binding key)))
2043 (cond ((null command)
2044 (message "%s is undefined" (key-description key)))
2045 ((and (interactive-p)
2046 (eq command 'execute-extended-command))
2047 (Info-goto-emacs-command-node
2048 (read-command "Find documentation for command: ")))
2050 (Info-goto-emacs-command-node command)))))
2052 (defcustom Info-title-face-alist
2053 '((?* bold underline)
2054 (?= bold-italic underline)
2055 (?- italic underline))
2056 "*Alist of face or list of faces to use for pseudo-underlined titles.
2057 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2058 :type '(repeat (list character face face))
2061 (defun Info-fontify-node ()
2063 (let ((buffer-read-only nil))
2064 (goto-char (point-min))
2065 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2066 (goto-char (match-end 0))
2068 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2069 (goto-char (match-end 0))
2071 (goto-char (match-beginning 1))
2072 (save-match-data (looking-at "Node:")))
2073 (put-text-property (match-beginning 2) (match-end 2)
2075 (put-text-property (match-beginning 2) (match-end 2)
2077 (put-text-property (match-beginning 2) (match-end 2)
2078 'mouse-face 'highlight))))
2079 (goto-char (point-min))
2080 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2082 (put-text-property (match-beginning 1) (match-end 1)
2084 (cdr (assq (preceding-char) Info-title-face-alist)))
2085 ;; This is a serious problem for trying to handle multiple
2086 ;; frame types at once. We want this text to be invisible
2087 ;; on frames that can display the font above.
2088 (if (memq (framep (selected-frame)) '(x pc w32))
2089 (put-text-property (match-end 1) (match-end 2)
2091 (goto-char (point-min))
2092 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2093 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2095 (put-text-property (match-beginning 1) (match-end 1)
2097 (put-text-property (match-beginning 1) (match-end 1)
2098 'mouse-face 'highlight)))
2099 (goto-char (point-min))
2100 (if (and (search-forward "\n* Menu:" nil t)
2101 (not (string-match "\\<Index\\>" Info-current-node))
2102 ;; Don't take time to annotate huge menus
2103 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2105 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2107 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2108 (put-text-property (match-beginning 0)
2109 (1+ (match-beginning 0))
2110 'face 'info-menu-5))
2111 (put-text-property (match-beginning 1) (match-end 1)
2113 (put-text-property (match-beginning 1) (match-end 1)
2114 'mouse-face 'highlight))))
2115 (set-buffer-modified-p nil))))
2118 ;; When an Info buffer is killed, make sure the associated tags buffer
2120 (defun Info-kill-buffer ()
2121 (and (eq major-mode 'Info-mode)
2122 Info-tag-table-buffer
2123 (kill-buffer Info-tag-table-buffer)))
2125 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2127 ;;; Speedbar support:
2128 ;; These functions permit speedbar to display the "tags" in the
2129 ;; current info node.
2130 (eval-when-compile (require 'speedbar))
2132 (defvar Info-speedbar-key-map nil
2133 "Keymap used when in the info display mode.")
2135 (defun Info-install-speedbar-variables ()
2136 "Install those variables used by speedbar to enhance Info."
2137 (if Info-speedbar-key-map
2139 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2141 ;; Basic tree features
2142 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2143 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2144 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2145 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2148 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2149 Info-speedbar-key-map
2150 Info-speedbar-hierarchy-buttons)))
2152 (defvar Info-speedbar-menu-items
2153 '(["Browse Node" speedbar-edit-line t]
2154 ["Expand Node" speedbar-expand-line
2155 (save-excursion (beginning-of-line)
2156 (looking-at "[0-9]+: *.\\+. "))]
2157 ["Contract Node" speedbar-contract-line
2158 (save-excursion (beginning-of-line)
2159 (looking-at "[0-9]+: *.-. "))]
2161 "Additional menu-items to add to speedbar frame.")
2163 ;; Make sure our special speedbar major mode is loaded
2164 (if (featurep 'speedbar)
2165 (Info-install-speedbar-variables)
2166 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2168 ;;; Info hierarchy display method
2170 (defun Info-speedbar-browser ()
2171 "Initialize speedbar to display an info node browser.
2172 This will add a speedbar major display mode."
2175 ;; Make sure that speedbar is active
2176 (speedbar-frame-mode 1)
2177 ;; Now, throw us into Info mode on speedbar.
2178 (speedbar-change-initial-expansion-list "Info")
2181 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2182 "Display an Info directory hierarchy in speedbar.
2183 DIRECTORY is the current directory in the attached frame.
2184 DEPTH is the current indentation depth.
2185 NODE is an optional argument that is used to represent the
2186 specific node to expand."
2188 (save-excursion (goto-char (point-min))
2189 (looking-at "Info Nodes:")))
2190 ;; Update our "current node" maybe?
2192 ;; We cannot use the generic list code, that depends on all leaves
2193 ;; being known at creation time.
2195 (speedbar-with-writable (insert "Info Nodes:\n")))
2196 (let ((completions nil))
2198 (Info-speedbar-fetch-file-nodes (or node '"(dir)top")))
2200 (speedbar-with-writable
2202 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2203 (cdr (car completions))
2204 (car (car completions))
2205 'Info-speedbar-goto-node
2206 (cdr (car completions))
2208 (setq completions (cdr completions)))
2212 (defun Info-speedbar-goto-node (text node indent)
2213 "When user clicks on TEXT, goto an info NODE.
2214 The INDENT level is ignored."
2215 (select-frame speedbar-attached-frame)
2216 (let* ((buff (or (get-buffer "*info*")
2217 (progn (info) (get-buffer "*info*"))))
2218 (bwin (get-buffer-window buff 0)))
2221 (select-window bwin)
2222 (raise-frame (window-frame bwin)))
2223 (if speedbar-power-click
2224 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2225 (select-frame speedbar-attached-frame)
2226 (switch-to-buffer buff)))
2227 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2228 (file (match-string 1 node))
2229 (node (match-string 2 node)))
2230 (Info-find-node file node)
2231 ;; If we do a find-node, and we were in info mode, restore
2232 ;; the old default method. Once we are in info mode, it makes
2233 ;; sense to return to whatever method the user was using before.
2234 (if (string= speedbar-initial-expansion-list-name "Info")
2235 (speedbar-change-initial-expansion-list
2236 speedbar-previously-used-expansion-list-name)))))
2238 (defun Info-speedbar-expand-node (text token indent)
2239 "Expand the node the user clicked on.
2240 TEXT is the text of the button we clicked on, a + or - item.
2241 TOKEN is data related to this node (NAME . FILE).
2242 INDENT is the current indentation depth."
2243 (cond ((string-match "+" text) ;we have to expand this file
2244 (speedbar-change-expand-button-char ?-)
2245 (if (speedbar-with-writable
2247 (end-of-line) (forward-char 1)
2248 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2249 (speedbar-change-expand-button-char ?-)
2250 (speedbar-change-expand-button-char ??)))
2251 ((string-match "-" text) ;we have to contract this node
2252 (speedbar-change-expand-button-char ?+)
2253 (speedbar-delete-subblock indent))
2254 (t (error "Ooops... not sure what to do")))
2255 (speedbar-center-buffer-smartly))
2257 (defun Info-speedbar-fetch-file-nodes (nodespec)
2258 "Fetch the subnodes from the info NODESPEC.
2259 NODESPEC is a string of the form: (file)node.
2260 Optional THISFILE represends the filename of"
2262 ;; Set up a buffer we can use to fake-out Info.
2263 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2264 (if (not (equal major-mode 'Info-mode))
2266 ;; Get the node into this buffer
2267 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2268 (file (match-string 1 nodespec))
2269 (node (match-string 2 nodespec)))
2270 (Info-find-node file node))
2271 ;; Scan the created buffer
2272 (goto-char (point-min))
2273 (let ((completions nil)
2274 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2275 (match-string 1 nodespec))))
2276 ;; Always skip the first one...
2277 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2278 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2279 (let ((name (match-string 1)))
2280 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2281 (setq name (cons name (match-string 1)))
2282 (if (looking-at " *\\(([^)]+)\\)\\.")
2283 (setq name (cons name (concat (match-string 1) "Top")))
2284 (if (looking-at " \\([^.]+\\).")
2286 (cons name (concat "(" thisfile ")" (match-string 1))))
2287 (setq name (cons name (concat "(" thisfile ")" name))))))
2288 (setq completions (cons name completions))))
2289 (nreverse completions))))
2291 ;;; Info mode node listing
2292 (defun Info-speedbar-buttons (buffer)
2293 "Create a speedbar display to help navigation in an Info file.
2294 BUFFER is the buffer speedbar is requesting buttons for."
2295 (if (save-excursion (goto-char (point-min))
2296 (not (looking-at "Info Nodes:")))
2298 (Info-speedbar-hierarchy-buttons nil 0)
2303 ;;; info.el ends here