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"
516 (goto-char (max (point-min) (- guesspos 1000)))
517 ;; Now search from our advised position (or from beg of buffer)
518 ;; to find the actual node.
520 (while (search-forward "\n\^_" nil t)
524 (if (re-search-backward regexp beg t)
526 (error "No such node: %s" nodename))))
528 (goto-char (point-min))))
529 ;; If we did not finish finding the specified node,
530 ;; go back to the previous one.
531 (or Info-current-node no-going-back (null Info-history)
532 (let ((hist (car Info-history)))
533 (setq Info-history (cdr Info-history))
534 (Info-find-node (nth 0 hist) (nth 1 hist) t)
535 (goto-char (nth 2 hist))))))
537 ;; Cache the contents of the (virtual) dir file, once we have merged
538 ;; it for the first time, so we can save time subsequently.
539 (defvar Info-dir-contents nil)
541 ;; Cache for the directory we decided to use for the default-directory
542 ;; of the merged dir text.
543 (defvar Info-dir-contents-directory nil)
545 ;; Record the file attributes of all the files from which we
546 ;; constructed Info-dir-contents.
547 (defvar Info-dir-file-attributes nil)
549 (defvar Info-dir-file-name nil)
551 ;; Construct the Info directory node by merging the files named `dir'
552 ;; from various directories. Set the *info* buffer's
553 ;; default-directory to the first directory we actually get any text
555 (defun Info-insert-dir ()
556 (if (and Info-dir-contents Info-dir-file-attributes
557 ;; Verify that none of the files we used has changed
560 (mapcar '(lambda (elt)
561 (let ((curr (file-attributes (car elt))))
562 ;; Don't compare the access time.
563 (if curr (setcar (nthcdr 4 curr) 0))
564 (setcar (nthcdr 4 (cdr elt)) 0)
565 (equal (cdr elt) curr)))
566 Info-dir-file-attributes))))
568 (insert Info-dir-contents)
569 (goto-char (point-min)))
570 (let ((dirs Info-directory-list)
571 ;; Bind this in case the user sets it to nil.
573 ;; This is set non-nil if we find a problem in some input files.
575 buffers buffer others nodes dirs-done)
577 (setq Info-dir-file-attributes nil)
579 ;; Search the directory list for the directory file.
581 (let ((truename (file-truename (expand-file-name (car dirs)))))
582 (or (member truename dirs-done)
583 (member (directory-file-name truename) dirs-done)
584 ;; Try several variants of specified name.
585 ;; Try upcasing, appending `.info', or both.
589 (progn (setq file (expand-file-name "dir" truename))
590 (file-attributes file))
591 (progn (setq file (expand-file-name "DIR" truename))
592 (file-attributes file))
593 (progn (setq file (expand-file-name "dir.info" truename))
594 (file-attributes file))
595 (progn (setq file (expand-file-name "DIR.INFO" truename))
596 (file-attributes file)))))
599 (cons (directory-file-name truename)
604 (message "Composing main Info directory..."))
605 (set-buffer (generate-new-buffer " info dir"))
608 (insert-file-contents file)
609 (make-local-variable 'Info-dir-file-name)
610 (setq Info-dir-file-name file)
611 (setq buffers (cons (current-buffer) buffers)
612 Info-dir-file-attributes
613 (cons (cons file attrs)
614 Info-dir-file-attributes)))
615 (error (kill-buffer (current-buffer))))))))
616 (or (cdr dirs) (setq Info-dir-contents-directory
617 (file-name-as-directory (car dirs))))
618 (setq dirs (cdr dirs))))
621 (error "Can't find the Info directory node"))
622 ;; Distinguish the dir file that comes with Emacs from all the
623 ;; others. Yes, that is really what this is supposed to do.
624 ;; If it doesn't work, fix it.
625 (setq buffer (car buffers)
626 others (cdr buffers))
628 ;; Insert the entire original dir file as a start; note that we've
629 ;; already saved its default directory to use as the default
630 ;; directory for the whole concatenation.
631 (insert-buffer buffer)
633 ;; Look at each of the other buffers one by one.
635 (let ((other (car others))
637 ;; In each, find all the menus.
640 (goto-char (point-min))
641 ;; Find each menu, and add an elt to NODES for it.
642 (while (re-search-forward "^\\* Menu:" nil t)
643 (let (beg nodename end)
646 (search-backward "\n\^_")
647 (search-forward "Node: ")
648 (setq nodename (Info-following-node-name))
649 (search-forward "\n\^_" nil 'move)
652 (setq this-buffer-nodes
653 (cons (list nodename other beg end)
654 this-buffer-nodes))))
655 (if (assoc-ignore-case "top" this-buffer-nodes)
656 (setq nodes (nconc this-buffer-nodes nodes))
658 (message "No `top' node in %s" Info-dir-file-name))))
659 (setq others (cdr others)))
660 ;; Add to the main menu a menu item for each other node.
661 (re-search-forward "^\\* Menu:")
663 (let ((menu-items '("top"))
666 (end (save-excursion (search-forward "\^_" nil t) (point))))
668 (let ((nodename (car (car nodes))))
670 (or (member (downcase nodename) menu-items)
671 (re-search-forward (concat "^\\* +"
672 (regexp-quote nodename)
676 (insert "* " nodename "::" "\n")
677 (setq menu-items (cons nodename menu-items))))))
678 (setq nodes (cdr nodes))))
679 ;; Now take each node of each of the other buffers
680 ;; and merge it into the main buffer.
682 (let ((nodename (car (car nodes))))
683 (goto-char (point-min))
684 ;; Find the like-named node in the main buffer.
685 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
686 (regexp-quote nodename)
690 (search-forward "\n\^_" nil 'move)
693 ;; If none exists, add one.
694 (goto-char (point-max))
695 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
696 ;; Merge the text from the other buffer's menu
697 ;; into the menu in the like-named node in the main buffer.
698 (apply 'insert-buffer-substring (cdr (car nodes))))
699 (setq nodes (cdr nodes)))
700 ;; Kill all the buffers we just made.
702 (kill-buffer (car buffers))
703 (setq buffers (cdr buffers)))
704 (goto-char (point-min))
706 (message "Composing main Info directory...problems encountered, see `*Messages*'")
707 (message "Composing main Info directory...done")))
708 (setq Info-dir-contents (buffer-string)))
709 (setq default-directory Info-dir-contents-directory))
711 ;; Note that on entry to this function the current-buffer must be the
712 ;; *info* buffer; not the info tags buffer.
713 (defun Info-read-subfile (nodepos)
714 ;; NODEPOS is either a position (in the Info file as a whole,
715 ;; not relative to a subfile) or the name of a subfile.
718 (if (numberp nodepos)
720 (set-buffer (marker-buffer Info-tag-table-marker))
721 (goto-char (point-min))
722 (search-forward "\n\^_")
725 (while (not (looking-at "\^_"))
728 thisfilepos thisfilename)
729 (search-forward ": ")
730 (setq thisfilename (buffer-substring beg (- (point) 2)))
731 (setq thisfilepos (read (current-buffer)))
732 ;; read in version 19 stops at the end of number.
733 ;; Advance to the next line.
735 (if (> thisfilepos nodepos)
737 (setq lastfilename thisfilename)
738 (setq lastfilepos thisfilepos))
740 (setq lastfilename nodepos)
741 (setq lastfilepos 0))
742 ;; Assume previous buffer is in Info-mode.
743 ;; (set-buffer (get-buffer "*info*"))
744 (or (equal Info-current-subfile lastfilename)
745 (let ((buffer-read-only nil))
746 (setq buffer-file-name nil)
749 (info-insert-file-contents lastfilename)
750 (set-buffer-modified-p nil)
751 (setq Info-current-subfile lastfilename)))
752 (goto-char (point-min))
753 (search-forward "\n\^_")
754 (if (numberp nodepos)
755 (+ (- nodepos lastfilepos) (point)))))
757 ;; Select the info node that point is in.
758 (defun Info-select-node ()
759 ;; Bind this in case the user sets it to nil.
760 (let ((case-fold-search t))
762 ;; Find beginning of node.
763 (search-backward "\n\^_")
765 ;; Get nodename spelled as it is in the node.
766 (re-search-forward "Node:[ \t]*")
767 (setq Info-current-node
768 (buffer-substring-no-properties (point)
770 (skip-chars-forward "^,\t\n")
773 ;; Find the end of it, and narrow.
775 (let (active-expression)
776 (narrow-to-region (point)
777 (if (re-search-forward "\n[\^_\f]" nil t)
780 (if (looking-at "[\n\^_\f]*execute: ")
782 (goto-char (match-end 0))
783 (setq active-expression
784 (read (current-buffer))))))
786 (if Info-enable-active-nodes (eval active-expression))
787 (if Info-fontify (Info-fontify-node))
788 (run-hooks 'Info-selection-hook)))))
790 (defun Info-set-mode-line ()
791 (setq mode-line-buffer-identification
794 (if Info-current-file
795 (file-name-nondirectory Info-current-file)
798 (or Info-current-node ""))))
800 ;; Go to an info node specified with a filename-and-nodename string
801 ;; of the sort that is found in pointers in nodes.
803 (defun Info-goto-node (nodename)
804 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
805 (interactive (list (Info-read-node-name "Goto node: ")))
807 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
809 (setq filename (if (= (match-beginning 1) (match-end 1))
811 (substring nodename (match-beginning 2) (match-end 2)))
812 nodename (substring nodename (match-beginning 3) (match-end 3)))
813 (let ((trim (string-match "\\s *\\'" filename)))
814 (if trim (setq filename (substring filename 0 trim))))
815 (let ((trim (string-match "\\s *\\'" nodename)))
816 (if trim (setq nodename (substring nodename 0 trim))))
817 (if transient-mark-mode (deactivate-mark))
818 (Info-find-node (if (equal filename "") nil filename)
819 (if (equal nodename "") "Top" nodename))))
821 (defvar Info-read-node-completion-table)
823 ;; This function is used as the "completion table" while reading a node name.
824 ;; It does completion using the alist in Info-read-node-completion-table
825 ;; unless STRING starts with an open-paren.
826 (defun Info-read-node-name-1 (string predicate code)
827 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
831 (try-completion string Info-read-node-completion-table predicate)))
835 (all-completions string Info-read-node-completion-table predicate)))
839 (assoc string Info-read-node-completion-table))))))
841 (defun Info-read-node-name (prompt &optional default)
842 (let* ((completion-ignore-case t)
843 (Info-read-node-completion-table (Info-build-node-completions))
844 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
845 (if (equal nodename "")
847 (Info-read-node-name prompt))
850 (defun Info-build-node-completions ()
851 (or Info-current-file-completions
853 ;; Bind this in case the user sets it to nil.
854 (case-fold-search t))
857 (if (marker-buffer Info-tag-table-marker)
858 (let ((marker Info-tag-table-marker))
859 (set-buffer (marker-buffer marker))
862 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
864 (cons (list (buffer-substring (match-beginning 1)
868 (goto-char (point-min))
869 (while (search-forward "\n\^_" nil t)
873 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
876 (cons (list (buffer-substring (match-beginning 1)
879 (setq Info-current-file-completions compl))))
881 (defun Info-restore-point (hl)
882 "If this node has been visited, restore the point value when we left."
884 (if (and (equal (nth 0 (car hl)) Info-current-file)
885 ;; Use string-equal, not equal, to ignore text props.
886 (string-equal (nth 1 (car hl)) Info-current-node))
888 (goto-char (nth 2 (car hl)))
889 (setq hl nil)) ;terminate the while at next iter
890 (setq hl (cdr hl)))))
892 (defvar Info-last-search nil
893 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
895 (defun Info-search (regexp)
896 "Search for REGEXP, starting from point, and select node it's found in."
897 (interactive "sSearch (regexp): ")
898 (if transient-mark-mode (deactivate-mark))
899 (if (equal regexp "")
900 (setq regexp Info-last-search)
901 (setq Info-last-search regexp))
902 (let ((found ()) current
903 (onode Info-current-node)
904 (ofile Info-current-file)
906 (ostart (window-start))
907 (osubfile Info-current-subfile))
911 (if (null Info-current-subfile)
912 (progn (re-search-forward regexp) (setq found (point)))
914 (progn (re-search-forward regexp) (setq found (point)))
915 (search-failed nil)))))
916 (if (not found) ;can only happen in subfile case -- else would have erred
920 (set-buffer (marker-buffer Info-tag-table-marker))
921 (goto-char (point-min))
922 (search-forward "\n\^_\nIndirect:")
924 (narrow-to-region (point)
925 (progn (search-forward "\n\^_")
927 (goto-char (point-min))
928 (search-forward (concat "\n" osubfile ": "))
931 (re-search-forward "\\(^.*\\): [0-9]+$")
932 (goto-char (+ (match-end 1) 2))
933 (setq list (cons (cons (read (current-buffer))
935 (match-beginning 1) (match-end 1)))
937 (goto-char (1+ (match-end 0))))
938 (setq list (nreverse list)
939 current (car (car list))
942 (message "Searching subfile %s..." (cdr (car list)))
943 (Info-read-subfile (car (car list)))
944 (setq list (cdr list))
945 ;; (goto-char (point-min))
946 (if (re-search-forward regexp nil t)
947 (setq found (point) list ())))
950 (signal 'search-failed (list regexp))))
952 (progn (Info-read-subfile osubfile)
955 (set-window-start (selected-window) ostart)))))
959 ;; Use string-equal, not equal, to ignore text props.
960 (or (and (string-equal onode Info-current-node)
961 (equal ofile Info-current-file))
962 (setq Info-history (cons (list ofile onode opoint)
965 ;; Extract the value of the node-pointer named NAME.
966 ;; If there is none, use ERRORNAME in the error message;
967 ;; if ERRORNAME is nil, just return nil.
968 (defun Info-extract-pointer (name &optional errorname)
969 ;; Bind this in case the user sets it to nil.
970 (let ((case-fold-search t))
972 (goto-char (point-min))
974 (if (re-search-backward (concat name ":") nil t)
976 (goto-char (match-end 0))
977 (Info-following-node-name))
980 (error "Node has no %s" (capitalize (or errorname name))))))))
982 ;; Return the node name in the buffer following point.
983 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
984 ;; saying which chars may appear in the node name.
985 (defun Info-following-node-name (&optional allowedchars)
986 (skip-chars-forward " \t")
987 (buffer-substring-no-properties
990 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
991 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
993 (skip-chars-forward "^)")))
994 (skip-chars-backward " ")
998 "Go to the next node of this node."
1000 (Info-goto-node (Info-extract-pointer "next")))
1003 "Go to the previous node of this node."
1005 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1007 (defun Info-up (&optional same-file)
1008 "Go to the superior node of this node.
1009 If SAME-FILE is non-nil, do not move to a different Info file."
1011 (let ((node (Info-extract-pointer "up")))
1013 (string-match "^(" node)
1014 (error "Up node is in another Info file"))
1015 (Info-goto-node node))
1016 (Info-restore-point Info-history))
1019 "Go back to the last node visited."
1022 (error "This is the first Info node you looked at"))
1023 (let (filename nodename opoint)
1024 (setq filename (car (car Info-history)))
1025 (setq nodename (car (cdr (car Info-history))))
1026 (setq opoint (car (cdr (cdr (car Info-history)))))
1027 (setq Info-history (cdr Info-history))
1028 (Info-find-node filename nodename)
1029 (setq Info-history (cdr Info-history))
1030 (goto-char opoint)))
1032 (defun Info-directory ()
1033 "Go to the Info directory node."
1035 (Info-find-node "dir" "top"))
1037 (defun Info-follow-reference (footnotename)
1038 "Follow cross reference named NAME to the node it refers to.
1039 NAME may be an abbreviation of the reference name."
1041 (let ((completion-ignore-case t)
1042 (case-fold-search t)
1043 completions default alt-default (start-point (point)) str i bol eol)
1045 ;; Store end and beginning of line.
1051 (goto-char (point-min))
1052 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1053 (setq str (buffer-substring
1056 ;; See if this one should be the default.
1058 (<= (match-beginning 0) start-point)
1059 (<= start-point (point))
1061 ;; See if this one should be the alternate default.
1062 (and (null alt-default)
1063 (and (<= bol (match-beginning 0))
1065 (setq alt-default t))
1067 (while (setq i (string-match "[ \n\t]+" str i))
1068 (setq str (concat (substring str 0 i) " "
1069 (substring str (match-end 0))))
1071 ;; Record as a completion and perhaps as default.
1072 (if (eq default t) (setq default str))
1073 (if (eq alt-default t) (setq alt-default str))
1074 ;; Don't add this string if it's a duplicate.
1075 ;; We use a loop instead of "(assoc str completions)" because
1076 ;; we want to do a case-insensitive compare.
1077 (let ((tail completions)
1078 (tem (downcase str)))
1080 (not (string-equal tem (downcase (car (car tail))))))
1081 (setq tail (cdr tail)))
1084 (cons (cons str nil)
1086 ;; If no good default was found, try an alternate.
1088 (setq default alt-default))
1089 ;; If only one cross-reference found, then make it default.
1090 (if (eq (length completions) 1)
1091 (setq default (car (car completions))))
1093 (let ((input (completing-read (if default
1094 (concat "Follow reference named: ("
1096 "Follow reference named: ")
1097 completions nil t)))
1098 (list (if (equal input "")
1100 (error "No cross-references in this node"))))
1102 (unless footnotename
1103 (error "No reference was specified"))
1105 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1106 (case-fold-search t))
1107 (while (setq i (string-match " " str i))
1108 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1111 (goto-char (point-min))
1112 (or (re-search-forward str nil t)
1113 (error "No cross-reference named %s" footnotename))
1114 (goto-char (+ (match-beginning 0) 5))
1116 (Info-extract-menu-node-name "Bad format cross reference" t)))
1117 (while (setq i (string-match "[ \t\n]+" target i))
1118 (setq target (concat (substring target 0 i) " "
1119 (substring target (match-end 0))))
1121 (Info-goto-node target)))
1123 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1124 (skip-chars-forward " \t\n")
1127 (skip-chars-forward "^:")
1130 (if (looking-at ":")
1131 (buffer-substring-no-properties beg (1- (point)))
1132 (skip-chars-forward " \t\n")
1133 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1134 (while (setq i (string-match "\n" str i))
1136 ;; Collapse multiple spaces.
1137 (while (string-match " +" str)
1138 (setq str (replace-match " " t t str)))
1141 ;; No one calls this.
1142 ;;(defun Info-menu-item-sequence (list)
1144 ;; (Info-menu (car list))
1145 ;; (setq list (cdr list))))
1147 (defvar Info-complete-menu-buffer)
1149 (defun Info-complete-menu-item (string predicate action)
1150 (let ((case-fold-search t))
1151 (cond ((eq action nil)
1153 (pattern (concat "\n\\* +\\("
1154 (regexp-quote string)
1157 (set-buffer Info-complete-menu-buffer)
1158 (goto-char (point-min))
1159 (search-forward "\n* Menu:")
1160 (while (re-search-forward pattern nil t)
1161 (setq completions (cons (cons (format "%s"
1165 (match-beginning 1))
1167 (try-completion string completions predicate)))
1170 (pattern (concat "\n\\* +\\("
1171 (regexp-quote string)
1174 (set-buffer Info-complete-menu-buffer)
1175 (goto-char (point-min))
1176 (search-forward "\n* Menu:")
1177 (while (re-search-forward pattern nil t)
1178 (setq completions (cons (cons (format "%s"
1182 (match-beginning 1))
1184 (all-completions string completions predicate)))
1187 (set-buffer Info-complete-menu-buffer)
1188 (goto-char (point-min))
1189 (search-forward "\n* Menu:")
1190 (re-search-forward (concat "\n\\* +"
1191 (regexp-quote string)
1196 (defun Info-menu (menu-item)
1197 "Go to node for menu item named (or abbreviated) NAME.
1198 Completion is allowed, and the menu item point is on is the default."
1200 (let ((completions '())
1201 ;; If point is within a menu item, use that item as the default
1207 (goto-char (point-min))
1208 (if (not (search-forward "\n* menu:" nil t))
1209 (error "No menu in this node"))
1215 (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1216 (setq default (format "%s" (buffer-substring
1221 (setq item (let ((completion-ignore-case t)
1222 (Info-complete-menu-buffer (current-buffer)))
1223 (completing-read (if default
1224 (format "Menu item (default %s): "
1227 'Info-complete-menu-item nil t)))
1228 ;; we rely on the fact that completing-read accepts an input
1229 ;; of "" even when the require-match argument is true and ""
1230 ;; is not a valid possibility
1231 (if (string= item "")
1237 ;; there is a problem here in that if several menu items have the same
1238 ;; name you can only go to the node of the first with this command.
1239 (Info-goto-node (Info-extract-menu-item menu-item)))
1241 (defun Info-extract-menu-item (menu-item)
1242 (setq menu-item (regexp-quote menu-item))
1243 (let ((case-fold-search t))
1245 (goto-char (point-min))
1246 (or (search-forward "\n* menu:" nil t)
1247 (error "No menu in this node"))
1248 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1249 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1250 (error "No such item in menu"))
1253 (Info-extract-menu-node-name))))
1255 ;; If COUNT is nil, use the last item in the menu.
1256 (defun Info-extract-menu-counting (count)
1257 (let ((case-fold-search t))
1259 (goto-char (point-min))
1260 (or (search-forward "\n* menu:" nil t)
1261 (error "No menu in this node"))
1263 (or (search-forward "\n* " nil t count)
1264 (error "Too few items in menu"))
1265 (while (search-forward "\n* " nil t)
1267 (Info-extract-menu-node-name))))
1269 (defun Info-nth-menu-item ()
1270 "Go to the node of the Nth menu item.
1271 N is the digit argument used to invoke this command."
1274 (Info-extract-menu-counting
1275 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1277 (defun Info-top-node ()
1278 "Go to the Top node of this file."
1280 (Info-goto-node "Top"))
1282 (defun Info-final-node ()
1283 "Go to the final node in this file."
1285 (Info-goto-node "Top")
1287 ;; Go to the last node in the menu of Top.
1288 (Info-goto-node (Info-extract-menu-counting nil))
1289 ;; If the last node in the menu is not last in pointer structure,
1290 ;; move forward until we can't go any farther.
1291 (while (Info-forward-node t t) nil)
1292 ;; Then keep moving down to last subnode, unless we reach an index.
1293 (while (and (not (string-match "\\<index\\>" Info-current-node))
1294 (save-excursion (search-forward "\n* Menu:" nil t)))
1295 (Info-goto-node (Info-extract-menu-counting nil)))))
1297 (defun Info-forward-node (&optional not-down no-error)
1298 "Go forward one node, considering all nodes as forming one sequence."
1300 (goto-char (point-min))
1302 ;; three possibilities, in order of priority:
1303 ;; 1. next node is in a menu in this node (but not in an index)
1304 ;; 2. next node is next at same level
1305 ;; 3. next node is up and next
1306 (cond ((and (not not-down)
1307 (save-excursion (search-forward "\n* menu:" nil t))
1308 (not (string-match "\\<index\\>" Info-current-node)))
1309 (Info-goto-node (Info-extract-menu-counting 1))
1311 ((save-excursion (search-backward "next:" nil t))
1314 ((and (save-excursion (search-backward "up:" nil t))
1315 ;; Use string-equal, not equal, to ignore text props.
1316 (not (string-equal (downcase (Info-extract-pointer "up"))
1318 (let ((old-node Info-current-node))
1320 (let (Info-history success)
1322 (setq success (Info-forward-node t no-error))
1323 (or success (Info-goto-node old-node))))))
1325 (t (error "No pointer forward from this node"))))
1327 (defun Info-backward-node ()
1328 "Go backward one node, considering all nodes as forming one sequence."
1330 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1331 (upnode (Info-extract-pointer "up" t)))
1332 (cond ((and upnode (string-match "(" upnode))
1333 (error "First node in file"))
1334 ((and upnode (or (null prevnode)
1335 ;; Use string-equal, not equal,
1336 ;; to ignore text properties.
1337 (string-equal (downcase prevnode)
1338 (downcase upnode))))
1341 ;; If we move back at the same level,
1342 ;; go down to find the last subnode*.
1345 (while (and (not (string-match "\\<index\\>" Info-current-node))
1346 (save-excursion (search-forward "\n* Menu:" nil t)))
1347 (Info-goto-node (Info-extract-menu-counting nil)))))
1349 (error "No pointer backward from this node")))))
1352 "Exit Info by selecting some other buffer."
1355 (save-buffers-kill-emacs)
1358 (defun Info-next-menu-item ()
1363 (search-forward "\n* menu:" nil t)
1364 (and (search-forward "\n* " nil t)
1365 (Info-extract-menu-node-name)))))
1366 (if node (Info-goto-node node)
1367 (error "No more items in menu"))))
1369 (defun Info-last-menu-item ()
1373 (let ((beg (save-excursion
1374 (and (search-backward "\n* menu:" nil t)
1376 (or (and beg (search-backward "\n* " beg t))
1377 (error "No previous items in menu")))
1378 (Info-goto-node (save-excursion
1379 (goto-char (match-end 0))
1380 (Info-extract-menu-node-name)))))
1382 (defmacro Info-no-error (&rest body)
1383 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1385 (defun Info-next-preorder ()
1386 "Go to the next subnode or the next node, or go up a level."
1388 (cond ((Info-no-error (Info-next-menu-item)))
1389 ((Info-no-error (Info-next)))
1390 ((Info-no-error (Info-up t))
1391 ;; Since we have already gone thru all the items in this menu,
1392 ;; go up to the end of this node.
1393 (goto-char (point-max))
1394 ;; Since logically we are done with the node with that menu,
1396 (Info-next-preorder))
1398 (error "No more nodes"))))
1400 (defun Info-last-preorder ()
1401 "Go to the last node, popping up a level if there is none."
1403 (cond ((Info-no-error
1404 (Info-last-menu-item)
1405 ;; If we go down a menu item, go to the end of the node
1406 ;; so we can scroll back through it.
1407 (goto-char (point-max)))
1408 ;; Keep going down, as long as there are nested menu nodes.
1409 (while (Info-no-error
1410 (Info-last-menu-item)
1411 ;; If we go down a menu item, go to the end of the node
1412 ;; so we can scroll back through it.
1413 (goto-char (point-max))))
1415 ((and (not (equal (Info-extract-pointer "up")
1416 (Info-extract-pointer "prev"))))
1417 (Info-no-error (Info-prev))
1418 (goto-char (point-max))
1419 (while (Info-no-error
1420 (Info-last-menu-item)
1421 ;; If we go down a menu item, go to the end of the node
1422 ;; so we can scroll back through it.
1423 (goto-char (point-max))))
1425 ((Info-no-error (Info-up t))
1426 (goto-char (point-min))
1427 (or (search-forward "\n* Menu:" nil t)
1428 (goto-char (point-max))))
1429 (t (error "No previous nodes"))))
1431 (defun Info-scroll-up ()
1432 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1433 Once you scroll far enough in a node that its menu appears on the screen
1434 but after point, the next scroll moves into its first subnode.
1436 When you scroll past the end of a node, that goes to the next node; if
1437 this node has no successor, it moves to the parent node's successor,
1438 and so on. If point is inside the menu of a node, it moves to
1439 subnode indicated by the following menu item. (That case won't
1440 normally result from this command, but can happen in other ways.)"
1443 (if (or (< (window-start) (point-min))
1444 (> (window-start) (point-max)))
1445 (set-window-start (selected-window) (point)))
1446 (let ((virtual-end (save-excursion
1447 (goto-char (point-min))
1448 (if (search-forward "\n* Menu:" nil t)
1451 (if (or (< virtual-end (window-start))
1452 (pos-visible-in-window-p virtual-end))
1453 (Info-next-preorder)
1456 (defun Info-scroll-down ()
1457 "Scroll one screenful back in Info, considering all nodes as one sequence.
1458 Within the menu of a node, this goes to its last subnode.
1459 When you scroll past the beginning of a node, that goes to the
1460 previous node or back up to the parent node."
1462 (if (or (< (window-start) (point-min))
1463 (> (window-start) (point-max)))
1464 (set-window-start (selected-window) (point)))
1465 (let* ((current-point (point))
1466 (virtual-end (save-excursion
1468 (setq current-point (point))
1469 (goto-char (point-min))
1470 (search-forward "\n* Menu:"
1473 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1474 (Info-last-preorder)
1477 (defun Info-next-reference (&optional recur)
1478 "Move cursor to the next cross-reference or menu item in the node."
1480 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1482 (case-fold-search t))
1483 (or (eobp) (forward-char 1))
1484 (or (re-search-forward pat nil t)
1486 (goto-char (point-min))
1487 (or (re-search-forward pat nil t)
1490 (error "No cross references in this node")))))
1491 (goto-char (match-beginning 0))
1492 (if (looking-at "\\* Menu:")
1494 (error "No cross references in this node")
1495 (Info-next-reference t)))))
1497 (defun Info-prev-reference (&optional recur)
1498 "Move cursor to the previous cross-reference or menu item in the node."
1500 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1502 (case-fold-search t))
1503 (or (re-search-backward pat nil t)
1505 (goto-char (point-max))
1506 (or (re-search-backward pat nil t)
1509 (error "No cross references in this node")))))
1510 (goto-char (match-beginning 0))
1511 (if (looking-at "\\* Menu:")
1513 (error "No cross references in this node")
1514 (Info-prev-reference t)))))
1516 (defun Info-index (topic)
1517 "Look up a string in the index for this file.
1518 The index is defined as the first node in the top-level menu whose
1519 name contains the word \"Index\", plus any immediately following
1520 nodes whose names also contain the word \"Index\".
1521 If there are no exact matches to the specified topic, this chooses
1522 the first match which is a case-insensitive substring of a topic.
1523 Use the `,' command to see the other matches.
1524 Give a blank topic name to go to the Index node itself."
1525 (interactive "sIndex topic: ")
1526 (let ((orignode Info-current-node)
1528 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1529 (regexp-quote topic)))
1531 (case-fold-search t))
1532 (Info-goto-node "Top")
1533 (or (search-forward "\n* menu:" nil t)
1535 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1537 (goto-char (match-beginning 1))
1538 ;; Here, and subsequently in this function,
1539 ;; we bind Info-history to nil for internal node-switches
1540 ;; so that we don't put junk in the history.
1541 ;; In the first Info-goto-node call, above, we do update the history
1542 ;; because that is what the user's previous node choice into it.
1543 (let ((Info-history nil))
1544 (Info-goto-node (Info-extract-menu-node-name)))
1545 (or (equal topic "")
1552 (goto-char (point-min))
1553 (while (re-search-forward pattern nil t)
1555 (cons (list (buffer-substring (match-beginning 1)
1557 (buffer-substring (match-beginning 2)
1560 (string-to-int (concat "0"
1565 (and (setq node (Info-extract-pointer "next" t))
1566 (string-match "\\<Index\\>" node)))
1567 (Info-goto-node node))
1570 (Info-goto-node orignode)
1571 (error "No `%s' in index" topic)))
1572 ;; Here it is a feature that assoc is case-sensitive.
1573 (while (setq found (assoc topic matches))
1574 (setq exact (cons found exact)
1575 matches (delq found matches)))
1576 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1577 (Info-index-next 0)))))
1579 (defun Info-index-next (num)
1580 "Go to the next matching index item from the last `i' command."
1582 (or Info-index-alternatives
1583 (error "No previous `i' command"))
1585 (setq num (+ num (length Info-index-alternatives))))
1587 (setq Info-index-alternatives
1588 (nconc (cdr Info-index-alternatives)
1589 (list (car Info-index-alternatives)))
1591 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1592 (if (> (nth 3 (car Info-index-alternatives)) 0)
1593 (forward-line (nth 3 (car Info-index-alternatives)))
1594 (forward-line 3) ; don't search in headers
1595 (let ((name (car (car Info-index-alternatives))))
1596 (Info-find-index-name name)))
1597 (message "Found `%s' in %s. %s"
1598 (car (car Info-index-alternatives))
1599 (nth 2 (car Info-index-alternatives))
1600 (if (cdr Info-index-alternatives)
1601 "(Press `,' for more)"
1604 (defun Info-find-index-name (name)
1605 "Move point to the place within the current node where NAME is defined."
1606 (let ((case-fold-search t))
1607 (if (or (re-search-forward (format
1608 "[a-zA-Z]+: %s\\( \\|$\\)"
1609 (regexp-quote name)) nil t)
1610 (search-forward (format "`%s'" name) nil t)
1611 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1613 (format "`%s'" (substring name 0 (match-beginning 1)))
1615 (search-forward name nil t))
1617 (goto-char (point-min)))))
1619 (defun Info-undefined ()
1620 "Make command be undefined in Info."
1625 "Enter the Info tutorial."
1627 (delete-other-windows)
1628 (Info-find-node "info"
1629 (if (< (window-height) 23)
1633 (defun Info-summary ()
1634 "Display a brief summary of all Info commands."
1636 (save-window-excursion
1637 (switch-to-buffer "*Help*")
1638 (setq buffer-read-only nil)
1640 (insert (documentation 'Info-mode))
1642 (goto-char (point-min))
1644 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1645 (message (if flag "Type Space to see more"
1646 "Type Space to return to Info"))
1647 (if (not (eq ?\ (setq ch (read-event))))
1648 (progn (setq unread-command-events (list ch)) nil)
1651 (bury-buffer "*Help*")))
1653 (defun Info-get-token (pos start all &optional errorstring)
1654 "Return the token around POS,
1655 POS must be somewhere inside the token
1656 START is a regular expression which will match the
1657 beginning of the tokens delimited string
1658 ALL is a regular expression with a single
1659 parenthesized subpattern which is the token to be
1660 returned. E.g. '{\(.*\)}' would return any string
1661 enclosed in braces around POS.
1662 SIG optional fourth argument, controls action on no match
1665 a string: signal an error, using that string."
1666 (let ((case-fold-search t))
1669 ;; First look for a match for START that goes across POS.
1670 (while (and (not (bobp)) (> (point) (- pos (length start)))
1671 (not (looking-at start)))
1673 ;; If we did not find one, search back for START
1674 ;; (this finds only matches that end at or before POS).
1675 (or (looking-at start)
1678 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1680 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1681 (not (setq found (and (<= (match-beginning 0) pos)
1682 (> (match-end 0) pos))))))
1683 (if (and found (<= (match-beginning 0) pos)
1684 (> (match-end 0) pos))
1685 (buffer-substring (match-beginning 1) (match-end 1))
1686 (cond ((null errorstring)
1692 (error "No %s around position %d" errorstring pos))))))))
1694 (defun Info-mouse-follow-nearest-node (click)
1695 "\\<Info-mode-map>Follow a node reference near point.
1696 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1697 At end of the node's text, moves to the next node, or up if none."
1699 (let* ((start (event-start click))
1700 (window (car start))
1701 (pos (car (cdr start))))
1702 (select-window window)
1704 (and (not (Info-try-follow-nearest-node))
1705 (save-excursion (forward-line 1) (eobp))
1706 (Info-next-preorder)))
1708 (defun Info-follow-nearest-node ()
1709 "\\<Info-mode-map>Follow a node reference near point.
1710 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1711 If no reference to follow, moves to the next node, or up if none."
1713 (or (Info-try-follow-nearest-node)
1714 (Info-next-preorder)))
1716 ;; Common subroutine.
1717 (defun Info-try-follow-nearest-node ()
1718 "Follow a node reference near point. Return non-nil if successful."
1721 ((setq node (Info-get-token (point) "\\*note[ \n]"
1722 "\\*note[ \n]\\([^:]*\\):"))
1723 (Info-follow-reference node))
1724 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1725 (Info-goto-node node))
1726 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1729 (setq node (Info-extract-menu-node-name))
1730 (Info-goto-node node))
1731 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1732 (Info-goto-node node))
1733 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1734 (Info-goto-node node))
1735 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1736 (Info-goto-node "Top"))
1737 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1738 (Info-goto-node node)))
1741 (defvar Info-mode-map nil
1742 "Keymap containing Info commands.")
1745 (setq Info-mode-map (make-keymap))
1746 (suppress-keymap Info-mode-map)
1747 (define-key Info-mode-map "." 'beginning-of-buffer)
1748 (define-key Info-mode-map " " 'Info-scroll-up)
1749 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1750 (define-key Info-mode-map "\t" 'Info-next-reference)
1751 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1752 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1753 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1754 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1755 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1756 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1757 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1758 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1759 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1760 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1761 (define-key Info-mode-map "0" 'undefined)
1762 (define-key Info-mode-map "?" 'Info-summary)
1763 (define-key Info-mode-map "]" 'Info-forward-node)
1764 (define-key Info-mode-map "[" 'Info-backward-node)
1765 (define-key Info-mode-map "<" 'Info-top-node)
1766 (define-key Info-mode-map ">" 'Info-final-node)
1767 (define-key Info-mode-map "b" 'beginning-of-buffer)
1768 (define-key Info-mode-map "d" 'Info-directory)
1769 (define-key Info-mode-map "e" 'Info-edit)
1770 (define-key Info-mode-map "f" 'Info-follow-reference)
1771 (define-key Info-mode-map "g" 'Info-goto-node)
1772 (define-key Info-mode-map "h" 'Info-help)
1773 (define-key Info-mode-map "i" 'Info-index)
1774 (define-key Info-mode-map "l" 'Info-last)
1775 (define-key Info-mode-map "m" 'Info-menu)
1776 (define-key Info-mode-map "n" 'Info-next)
1777 (define-key Info-mode-map "p" 'Info-prev)
1778 (define-key Info-mode-map "q" 'Info-exit)
1779 (define-key Info-mode-map "s" 'Info-search)
1780 ;; For consistency with Rmail.
1781 (define-key Info-mode-map "\M-s" 'Info-search)
1782 (define-key Info-mode-map "t" 'Info-top-node)
1783 (define-key Info-mode-map "u" 'Info-up)
1784 (define-key Info-mode-map "," 'Info-index-next)
1785 (define-key Info-mode-map "\177" 'Info-scroll-down)
1786 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1789 (defun Info-check-pointer (item)
1790 ;; Non-nil if ITEM is present in this node.
1792 (Info-extract-pointer item)
1795 (easy-menu-define Info-mode-menu Info-mode-map
1796 "Menu for info files."
1798 ["Up" Info-up (Info-check-pointer "up")]
1799 ["Next" Info-next (Info-check-pointer "next")]
1800 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1801 ("Menu item" ["You should never see this" report-emacs-bug t])
1802 ("Reference" ["You should never see this" report-emacs-bug t])
1803 ["Search..." Info-search t]
1804 ["Goto node..." Info-goto-node t]
1805 ["Last" Info-last Info-history]
1806 ["Exit" Info-exit t]))
1808 (defvar Info-menu-last-node nil)
1809 ;; Last node the menu was created for.
1810 ;; Value is a list, (FILE-NAME NODE-NAME).
1812 (defun Info-menu-update ()
1813 ;; Update the Info menu for the current node.
1815 (if (or (not (eq major-mode 'Info-mode))
1816 (equal (list Info-current-file Info-current-node)
1817 Info-menu-last-node))
1819 ;; Update menu menu.
1820 (let* ((Info-complete-menu-buffer (current-buffer))
1821 (items (nreverse (condition-case nil
1822 (Info-complete-menu-item
1823 "" (lambda (e) t) t)
1827 (while (and items (< number 9))
1828 (setq current (car items)
1831 (setq entries (cons `[,current
1832 (Info-menu ,current)
1833 :keys ,(format "%d" number)]
1836 (setq entries (cons ["Other..." Info-menu t] entries)))
1838 (setq entries (list ["No menu" nil nil])))
1839 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1840 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1842 str i entries current
1844 (case-fold-search t))
1846 (goto-char (point-min))
1847 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1848 (setq str (buffer-substring
1852 (while (setq i (string-match "[ \n\t]+" str i))
1853 (setq str (concat (substring str 0 i) " "
1854 (substring str (match-end 0))))
1858 (while (and items (< number 9))
1859 (setq current (car items)
1862 (setq entries (cons `[,current
1863 (Info-follow-reference ,current)
1867 (setq entries (cons ["Other..." Info-follow-reference t]
1870 (setq entries (list ["No references" nil nil])))
1871 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1872 ;; Update last seen node.
1873 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1874 ;; Try to avoid entering infinite beep mode in case of errors.
1878 ;; Info mode is suitable only for specially formatted data.
1879 (put 'info-mode 'mode-class 'special)
1883 Info mode provides commands for browsing through the Info documentation tree.
1884 Documentation in Info is divided into \"nodes\", each of which discusses
1885 one topic and contains references to other nodes which discuss related
1886 topics. Info has commands to follow the references and show you other nodes.
1888 \\[Info-help] Invoke the Info tutorial.
1889 \\[Info-exit] Quit Info: reselect previously selected buffer.
1891 Selecting other nodes:
1892 \\[Info-mouse-follow-nearest-node]
1893 Follow a node reference you click on.
1894 This works with menu items, cross references, and
1895 the \"next\", \"previous\" and \"up\", depending on where you click.
1896 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1897 \\[Info-next] Move to the \"next\" node of this node.
1898 \\[Info-prev] Move to the \"previous\" node of this node.
1899 \\[Info-up] Move \"up\" from this node.
1900 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1901 Picking a menu item causes another node to be selected.
1902 \\[Info-directory] Go to the Info directory node.
1903 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1904 \\[Info-last] Move to the last node you were at.
1905 \\[Info-index] Look up a topic in this file's Index and move to that node.
1906 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1907 \\[Info-top-node] Go to the Top node of this file.
1908 \\[Info-final-node] Go to the final node in this file.
1909 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1910 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1912 Moving within a node:
1913 \\[Info-scroll-up] Normally, scroll forward a full screen.
1914 Once you scroll far enough in a node that its menu appears on the screen
1915 but after point, the next scroll moves into its first subnode.
1916 When after all menu items (or if their is no menu), move up to
1918 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1919 already visible, try to go to the previous menu entry, or up if there is none.
1920 \\[beginning-of-buffer] Go to beginning of node.
1923 \\[Info-exit] Quit Info: reselect previously selected buffer.
1924 \\[Info-edit] Edit contents of selected node.
1925 1 Pick first item in node's menu.
1926 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1927 \\[Info-goto-node] Move to node specified by name.
1928 You may include a filename as well, as (FILENAME)NODENAME.
1929 \\[universal-argument] \\[info] Move to new Info file with completion.
1930 \\[Info-search] Search through this Info file for specified regexp,
1931 and select the node in which the next occurrence is found.
1932 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1933 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1934 (kill-all-local-variables)
1935 (setq major-mode 'Info-mode)
1936 (setq mode-name "Info")
1938 (use-local-map Info-mode-map)
1939 (make-local-hook 'activate-menubar-hook)
1940 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1941 (set-syntax-table text-mode-syntax-table)
1942 (setq local-abbrev-table text-mode-abbrev-table)
1943 (setq case-fold-search t)
1944 (setq buffer-read-only t)
1945 (make-local-variable 'Info-current-file)
1946 (make-local-variable 'Info-current-subfile)
1947 (make-local-variable 'Info-current-node)
1948 (make-local-variable 'Info-tag-table-marker)
1949 (setq Info-tag-table-marker (make-marker))
1950 (make-local-variable 'Info-tag-table-buffer)
1951 (setq Info-tag-table-buffer nil)
1952 (make-local-variable 'Info-history)
1953 (make-local-variable 'Info-index-alternatives)
1954 ;; This is for the sake of the invisible text we use handling titles.
1955 (make-local-variable 'line-move-ignore-invisible)
1956 (setq line-move-ignore-invisible t)
1957 (Info-set-mode-line)
1958 (run-hooks 'Info-mode-hook))
1960 (defvar Info-edit-map nil
1961 "Local keymap used within `e' command of Info.")
1964 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1965 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1967 ;; Info-edit mode is suitable only for specially formatted data.
1968 (put 'info-edit-mode 'mode-class 'special)
1970 (defun Info-edit-mode ()
1971 "Major mode for editing the contents of an Info node.
1972 Like text mode with the addition of `Info-cease-edit'
1973 which returns to Info mode for browsing.
1975 (use-local-map Info-edit-map)
1976 (setq major-mode 'Info-edit-mode)
1977 (setq mode-name "Info Edit")
1978 (kill-local-variable 'mode-line-buffer-identification)
1979 (setq buffer-read-only nil)
1980 (force-mode-line-update)
1981 (buffer-enable-undo (current-buffer))
1982 (run-hooks 'Info-edit-mode-hook))
1985 "Edit the contents of this Info node.
1986 Allowed only if variable `Info-enable-edit' is non-nil."
1988 (or Info-enable-edit
1989 (error "Editing info nodes is not enabled"))
1991 (message "%s" (substitute-command-keys
1992 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1994 (defun Info-cease-edit ()
1995 "Finish editing Info node; switch back to Info proper."
1997 ;; Do this first, so nothing has changed if user C-g's at query.
1998 (and (buffer-modified-p)
1999 (y-or-n-p "Save the file? ")
2001 (use-local-map Info-mode-map)
2002 (setq major-mode 'Info-mode)
2003 (setq mode-name "Info")
2004 (Info-set-mode-line)
2005 (setq buffer-read-only t)
2006 (force-mode-line-update)
2007 (and (marker-position Info-tag-table-marker)
2009 (message "Tags may have changed. Use Info-tagify if necessary")))
2011 (defvar Info-file-list-for-emacs
2012 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
2013 "List of Info files that describe Emacs commands.
2014 An element can be a file name, or a list of the form (PREFIX . FILE)
2015 where PREFIX is a name prefix and FILE is the file to look in.
2016 If the element is just a file name, the file name also serves as the prefix.")
2018 (defun Info-find-emacs-command-nodes (command)
2019 "Return a list of locations documenting COMMAND.
2020 The `info-file' property of COMMAND says which Info manual to search.
2021 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2022 defines heuristics for which Info manual to try.
2023 The locations are of the format used in Info-history, i.e.
2024 \(FILENAME NODENAME BUFFERPOS\)."
2026 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2027 ":\\s *\\(.*\\)\\.$"))
2028 (info-file "emacs")) ;default
2029 ;; Determine which info file this command is documented in.
2030 (if (get command 'info-file)
2031 (setq info-file (get command 'info-file))
2032 ;; If it doesn't say explicitly, test its name against
2033 ;; various prefixes that we know.
2034 (let ((file-list Info-file-list-for-emacs))
2036 (let* ((elt (car file-list))
2037 (name (if (consp elt)
2040 (file (if (consp elt) (cdr elt) elt))
2041 (regexp (concat "\\`" (regexp-quote name)
2043 (if (string-match regexp (symbol-name command))
2044 (setq info-file file file-list nil))
2045 (setq file-list (cdr file-list))))))
2048 (Info-find-node info-file "Command Index")
2049 ;; Some manuals may not have a separate Command Index node,
2050 ;; so try just Index instead.
2052 (Info-find-node info-file "Index")))
2053 ;; Take the index node off the Info history.
2054 (setq Info-history (cdr Info-history))
2055 (goto-char (point-max))
2056 (while (re-search-backward cmd-desc nil t)
2057 (setq where (cons (list Info-current-file
2066 (defun Info-goto-emacs-command-node (command)
2067 "Go to the Info node in the Emacs manual for command COMMAND.
2068 The command is found by looking up in Emacs manual's Command Index
2069 or in another manual found via COMMAND's `info-file' property or
2070 the variable `Info-file-list-for-emacs'."
2071 (interactive "CFind documentation for command: ")
2072 (or (commandp command)
2073 (signal 'wrong-type-argument (list 'commandp command)))
2074 (let ((where (Info-find-emacs-command-nodes command)))
2076 (let ((num-matches (length where)))
2077 ;; Get Info running, and pop to it in another window.
2078 (save-window-excursion
2080 ;; FIXME It would be cool if this could use a buffer other
2082 (pop-to-buffer "*info*")
2083 (Info-find-node (car (car where))
2084 (car (cdr (car where))))
2085 (if (> num-matches 1)
2087 ;; Info-find-node already pushed (car where) onto
2088 ;; Info-history. Put the other nodes that were found on
2090 (setq Info-history (nconc (cdr where) Info-history))
2091 (message "Found %d other entr%s. Use %s to see %s."
2093 (if (> num-matches 2) "ies" "y")
2094 (substitute-command-keys "\\[Info-last]")
2095 (if (> num-matches 2) "them" "it")))))
2096 (error "Couldn't find documentation for %s" command))))
2099 (defun Info-goto-emacs-key-command-node (key)
2100 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2101 Interactively, if the binding is execute-extended-command, a command is read.
2102 The command is found by looking up in Emacs manual's Command Index
2103 or in another manual found via COMMAND's `info-file' property or
2104 the variable `Info-file-list-for-emacs'."
2105 (interactive "kFind documentation for key:")
2106 (let ((command (key-binding key)))
2107 (cond ((null command)
2108 (message "%s is undefined" (key-description key)))
2109 ((and (interactive-p)
2110 (eq command 'execute-extended-command))
2111 (Info-goto-emacs-command-node
2112 (read-command "Find documentation for command: ")))
2114 (Info-goto-emacs-command-node command)))))
2116 (defcustom Info-title-face-alist
2117 '((?* bold underline)
2118 (?= bold-italic underline)
2119 (?- italic underline))
2120 "*Alist of face or list of faces to use for pseudo-underlined titles.
2121 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2122 :type '(repeat (list character face face))
2125 (defun Info-fontify-node ()
2127 (let ((buffer-read-only nil)
2128 (case-fold-search t))
2129 (goto-char (point-min))
2130 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2131 (goto-char (match-end 0))
2133 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2134 (goto-char (match-end 0))
2136 (goto-char (match-beginning 1))
2137 (save-match-data (looking-at "Node:")))
2138 (put-text-property (match-beginning 2) (match-end 2)
2140 (put-text-property (match-beginning 2) (match-end 2)
2142 (put-text-property (match-beginning 2) (match-end 2)
2143 'mouse-face 'highlight))))
2144 (goto-char (point-min))
2145 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2147 (put-text-property (match-beginning 1) (match-end 1)
2149 (cdr (assq (preceding-char) Info-title-face-alist)))
2150 ;; This is a serious problem for trying to handle multiple
2151 ;; frame types at once. We want this text to be invisible
2152 ;; on frames that can display the font above.
2153 (if (memq (framep (selected-frame)) '(x pc w32))
2154 (put-text-property (match-end 1) (match-end 2)
2156 (goto-char (point-min))
2157 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2158 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2160 (put-text-property (match-beginning 1) (match-end 1)
2162 (put-text-property (match-beginning 1) (match-end 1)
2163 'mouse-face 'highlight)))
2164 (goto-char (point-min))
2165 (if (and (search-forward "\n* Menu:" nil t)
2166 (not (string-match "\\<Index\\>" Info-current-node))
2167 ;; Don't take time to annotate huge menus
2168 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2170 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2172 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2173 (put-text-property (match-beginning 0)
2174 (1+ (match-beginning 0))
2175 'face 'info-menu-5))
2176 (put-text-property (match-beginning 1) (match-end 1)
2178 (put-text-property (match-beginning 1) (match-end 1)
2179 'mouse-face 'highlight))))
2180 (set-buffer-modified-p nil))))
2183 ;; When an Info buffer is killed, make sure the associated tags buffer
2185 (defun Info-kill-buffer ()
2186 (and (eq major-mode 'Info-mode)
2187 Info-tag-table-buffer
2188 (kill-buffer Info-tag-table-buffer)))
2190 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2192 ;;; Speedbar support:
2193 ;; These functions permit speedbar to display the "tags" in the
2194 ;; current info node.
2195 (eval-when-compile (require 'speedbar))
2197 (defvar Info-speedbar-key-map nil
2198 "Keymap used when in the info display mode.")
2200 (defun Info-install-speedbar-variables ()
2201 "Install those variables used by speedbar to enhance Info."
2202 (if Info-speedbar-key-map
2204 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2206 ;; Basic tree features
2207 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2208 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2209 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2210 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2213 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2214 Info-speedbar-key-map
2215 Info-speedbar-hierarchy-buttons)))
2217 (defvar Info-speedbar-menu-items
2218 '(["Browse Node" speedbar-edit-line t]
2219 ["Expand Node" speedbar-expand-line
2220 (save-excursion (beginning-of-line)
2221 (looking-at "[0-9]+: *.\\+. "))]
2222 ["Contract Node" speedbar-contract-line
2223 (save-excursion (beginning-of-line)
2224 (looking-at "[0-9]+: *.-. "))]
2226 "Additional menu-items to add to speedbar frame.")
2228 ;; Make sure our special speedbar major mode is loaded
2229 (if (featurep 'speedbar)
2230 (Info-install-speedbar-variables)
2231 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2233 ;;; Info hierarchy display method
2235 (defun Info-speedbar-browser ()
2236 "Initialize speedbar to display an info node browser.
2237 This will add a speedbar major display mode."
2240 ;; Make sure that speedbar is active
2241 (speedbar-frame-mode 1)
2242 ;; Now, throw us into Info mode on speedbar.
2243 (speedbar-change-initial-expansion-list "Info")
2246 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2247 "Display an Info directory hierarchy in speedbar.
2248 DIRECTORY is the current directory in the attached frame.
2249 DEPTH is the current indentation depth.
2250 NODE is an optional argument that is used to represent the
2251 specific node to expand."
2253 (save-excursion (goto-char (point-min))
2254 (let ((case-fold-search t))
2255 (looking-at "Info Nodes:"))))
2256 ;; Update our "current node" maybe?
2258 ;; We cannot use the generic list code, that depends on all leaves
2259 ;; being known at creation time.
2261 (speedbar-with-writable (insert "Info Nodes:\n")))
2262 (let ((completions nil)
2263 (cf (selected-frame)))
2264 (select-frame speedbar-attached-frame)
2265 (save-window-excursion
2267 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2270 (speedbar-with-writable
2272 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2273 (cdr (car completions))
2274 (car (car completions))
2275 'Info-speedbar-goto-node
2276 (cdr (car completions))
2278 (setq completions (cdr completions)))
2282 (defun Info-speedbar-goto-node (text node indent)
2283 "When user clicks on TEXT, goto an info NODE.
2284 The INDENT level is ignored."
2285 (select-frame speedbar-attached-frame)
2286 (let* ((buff (or (get-buffer "*info*")
2287 (progn (info) (get-buffer "*info*"))))
2288 (bwin (get-buffer-window buff 0)))
2291 (select-window bwin)
2292 (raise-frame (window-frame bwin)))
2293 (if speedbar-power-click
2294 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2295 (select-frame speedbar-attached-frame)
2296 (switch-to-buffer buff)))
2297 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2298 (file (match-string 1 node))
2299 (node (match-string 2 node)))
2300 (Info-find-node file node)
2301 ;; If we do a find-node, and we were in info mode, restore
2302 ;; the old default method. Once we are in info mode, it makes
2303 ;; sense to return to whatever method the user was using before.
2304 (if (string= speedbar-initial-expansion-list-name "Info")
2305 (speedbar-change-initial-expansion-list
2306 speedbar-previously-used-expansion-list-name)))))
2308 (defun Info-speedbar-expand-node (text token indent)
2309 "Expand the node the user clicked on.
2310 TEXT is the text of the button we clicked on, a + or - item.
2311 TOKEN is data related to this node (NAME . FILE).
2312 INDENT is the current indentation depth."
2313 (cond ((string-match "+" text) ;we have to expand this file
2314 (speedbar-change-expand-button-char ?-)
2315 (if (speedbar-with-writable
2317 (end-of-line) (forward-char 1)
2318 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2319 (speedbar-change-expand-button-char ?-)
2320 (speedbar-change-expand-button-char ??)))
2321 ((string-match "-" text) ;we have to contract this node
2322 (speedbar-change-expand-button-char ?+)
2323 (speedbar-delete-subblock indent))
2324 (t (error "Ooops... not sure what to do")))
2325 (speedbar-center-buffer-smartly))
2327 (defun Info-speedbar-fetch-file-nodes (nodespec)
2328 "Fetch the subnodes from the info NODESPEC.
2329 NODESPEC is a string of the form: (file)node.
2330 Optional THISFILE represends the filename of"
2332 ;; Set up a buffer we can use to fake-out Info.
2333 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2334 (if (not (equal major-mode 'Info-mode))
2336 ;; Get the node into this buffer
2337 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2338 (file (match-string 1 nodespec))
2339 (node (match-string 2 nodespec)))
2340 (Info-find-node file node))
2341 ;; Scan the created buffer
2342 (goto-char (point-min))
2343 (let ((completions nil)
2344 (case-fold-search t)
2345 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2346 (match-string 1 nodespec))))
2347 ;; Always skip the first one...
2348 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2349 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2350 (let ((name (match-string 1)))
2351 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2352 (setq name (cons name (match-string 1)))
2353 (if (looking-at " *\\(([^)]+)\\)\\.")
2354 (setq name (cons name (concat (match-string 1) "Top")))
2355 (if (looking-at " \\([^.]+\\).")
2357 (cons name (concat "(" thisfile ")" (match-string 1))))
2358 (setq name (cons name (concat "(" thisfile ")" name))))))
2359 (setq completions (cons name completions))))
2360 (nreverse completions))))
2362 ;;; Info mode node listing
2363 (defun Info-speedbar-buttons (buffer)
2364 "Create a speedbar display to help navigation in an Info file.
2365 BUFFER is the buffer speedbar is requesting buttons for."
2366 (if (save-excursion (goto-char (point-min))
2367 (let ((case-fold-search t))
2368 (not (looking-at "Info Nodes:"))))
2370 (Info-speedbar-hierarchy-buttons nil 0)
2375 ;;; info.el ends here