1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
30 (defvar Info-history nil
31 "List of info nodes user has visited.
32 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
34 (defvar Info-enable-edit nil
35 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
36 This is convenient if you want to write info files by hand.
37 However, we recommend that you not do this.
38 It is better to write a Texinfo file and generate the Info file from that,
39 because that gives you a printed manual as well.")
41 (defvar Info-enable-active-nodes t
42 "Non-nil allows Info to execute Lisp code associated with nodes.
43 The Lisp code is executed when the node is selected.")
45 (defvar Info-default-directory-list nil
46 "List of default directories to search for Info documentation files.
47 This value is used as the default for `Info-directory-list'. It is set
50 (defvar Info-fontify t
51 "*Non-nil enables highlighting and fonts in Info nodes.")
53 (defvar Info-directory-list
54 (let ((path (getenv "INFOPATH"))
55 (sep (if (eq system-type 'ms-dos) ";" ":"))
56 (sibling (expand-file-name "../info/" (invocation-directory))))
60 (while (> (length path) 0)
61 (setq idx (or (string-match sep path) (length path))
62 list (cons (substring path 0 idx) list)
63 path (substring path (min (1+ idx)
66 (if (or (member sibling Info-default-directory-list)
67 (not (file-exists-p sibling))
68 ;; On MS-DOS, we use movable executables always,
69 ;; and we must always find the Info dir at run time.
70 (if (eq system-type 'ms-dos)
72 ;; Use invocation-directory for Info only if we used it for
73 ;; exec-directory also.
74 (not (string= exec-directory
75 (expand-file-name "../lib-src/"
76 (invocation-directory))))))
77 Info-default-directory-list
78 (reverse (cons sibling (cdr (reverse Info-default-directory-list)))))))
79 "List of directories to search for Info documentation files.
80 nil means not yet initialized. In this case, Info uses the environment
81 variable INFOPATH to initialize it, or `Info-default-directory-list'
82 if there is no INFOPATH variable in the environment.
83 The last element of `Info-default-directory-list' is the directory
84 where Emacs installs the Info files that come with it.
85 If Emacs finds it has been installed elsewhere, or not yet installed,
86 it replaces that element with the directory that its Info files are in.")
88 (defvar Info-current-file nil
89 "Info file that Info is now looking at, or nil.")
91 (defvar Info-current-subfile nil
92 "Info subfile that is actually in the *info* buffer now,
93 or nil if current info file is not split into subfiles.")
95 (defvar Info-current-node nil
96 "Name of node that Info is now looking at, or nil.")
98 (defvar Info-tag-table-marker (make-marker)
99 "Marker pointing at beginning of current Info file's tag table.
100 Marker points nowhere if file has no tag table.")
102 (defvar Info-current-file-completions nil
103 "Cached completion list for current Info file.")
105 (defvar Info-index-alternatives nil
106 "List of possible matches for last Info-index command.")
108 (defvar Info-standalone nil
109 "Non-nil if Emacs was started solely as an Info browser.")
111 (defvar Info-suffix-list '( (".info.Z" . "uncompress")
112 (".info.Y" . "unyabba")
113 (".info.gz" . "gunzip")
114 (".info.z" . "gunzip")
116 (".Z" . "uncompress")
121 "List of file name suffixes and associated decoding commands.
122 Each entry should be (SUFFIX . STRING); the file is given to
123 the command as standard input. If STRING is nil, no decoding is done.
124 Because the SUFFIXes are tried in order, the empty string should
125 be last in the list.")
127 (defun info-insert-file-contents (filename &optional visit)
128 "Insert the contents of an info file in the current buffer.
129 Do the right thing if the file has been compressed or zipped."
130 (let ((tail Info-suffix-list)
132 (if (file-exists-p filename)
136 (concat (regexp-quote (car (car tail))) "$")
138 (setq tail (cdr tail)))
139 (setq fullname filename
140 decoder (cdr (car tail))))
142 (not (file-exists-p (concat filename (car (car tail))))))
143 (setq tail (cdr tail)))
144 (setq fullname (concat filename (car (car tail)))
145 decoder (cdr (car tail)))
146 ;; check for conflict with jka-compr
147 (if (and (featurep 'jka-compr)
148 (jka-compr-installed-p)
149 (jka-compr-get-compression-info (concat filename
153 (error "Can't find %s or any compressed version of it!" filename)))
154 (insert-file-contents fullname visit)
156 (let ((buffer-read-only nil))
157 (shell-command-on-region (point-min) (point-max) decoder t)))))
160 (defun info (&optional file)
161 "Enter Info, the documentation browser.
162 Optional argument FILE specifies the file to examine;
163 the default is the top-level directory of Info.
165 In interactive use, a prefix argument directs this command
166 to read a file name from the minibuffer."
167 (interactive (if current-prefix-arg
168 (list (read-file-name "Info file name: " nil nil t))))
170 (Info-goto-node (concat "(" file ")"))
171 (if (get-buffer "*info*")
172 (switch-to-buffer "*info*")
176 (defun info-standalone ()
177 "Run Emacs as a standalone Info reader.
178 Usage: emacs -f info-standalone [filename]
179 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
180 (setq Info-standalone t)
181 (if (and command-line-args-left
182 (not (string-match "^-" (car command-line-args-left))))
185 (info (car command-line-args-left))
186 (setq command-line-args-left (cdr command-line-args-left)))
187 (error (send-string-to-terminal
188 (format "%s\n" (if (eq (car-safe err) 'error)
190 (save-buffers-kill-emacs)))
193 ;; Go to an info node specified as separate filename and nodename.
194 ;; no-going-back is non-nil if recovering from an error in this function;
195 ;; it says do not attempt further (recursive) error recovery.
196 (defun Info-find-node (filename nodename &optional no-going-back)
197 ;; Convert filename to lower case if not found as specified.
200 (let (temp temp-downcase found)
201 (setq filename (substitute-in-file-name filename))
202 (if (string= (downcase (file-name-nondirectory filename)) "dir")
204 (let ((dirs (if (string-match "^\\./" filename)
205 ;; If specified name starts with `./'
206 ;; then just try current directory.
208 Info-directory-list)))
209 ;; Search the directory list for file FILENAME.
210 (while (and dirs (not found))
211 (setq temp (expand-file-name filename (car dirs)))
213 (expand-file-name (downcase filename) (car dirs)))
214 ;; Try several variants of specified name.
219 (if (file-exists-p (concat temp (car x)))
222 (throw 'foundit nil)))
223 (if (file-exists-p (concat temp-downcase (car x)))
225 (setq found temp-downcase)
226 (throw 'foundit nil)))))
228 (setq dirs (cdr dirs)))))
230 (setq filename found)
231 (error "Info file %s does not exist" filename))))
232 ;; Record the node we are leaving.
233 (if (and Info-current-file (not no-going-back))
235 (cons (list Info-current-file Info-current-node (point))
237 ;; Go into info buffer.
238 (switch-to-buffer "*info*")
239 (buffer-disable-undo (current-buffer))
240 (or (eq major-mode 'Info-mode)
243 (setq Info-current-node nil)
246 ;; Switch files if necessary
248 (equal Info-current-file filename)
249 (let ((buffer-read-only nil))
250 (setq Info-current-file nil
251 Info-current-subfile nil
252 Info-current-file-completions nil
253 Info-index-alternatives nil
254 buffer-file-name nil)
258 (info-insert-file-contents filename t)
259 (setq default-directory (file-name-directory filename)))
260 (set-buffer-modified-p nil)
261 ;; See whether file has a tag table. Record the location if yes.
262 (set-marker Info-tag-table-marker nil)
263 (goto-char (point-max))
265 (or (equal nodename "*")
266 (not (search-forward "\^_\nEnd tag table\n" nil t))
268 ;; We have a tag table. Find its beginning.
269 ;; Is this an indirect file?
270 (search-backward "\nTag table:\n")
274 (looking-at "(Indirect)\n"))
275 ;; It is indirect. Copy it to another buffer
276 ;; and record that the tag table is in that buffer.
278 (let ((buf (current-buffer)))
279 (set-buffer (get-buffer-create " *info tag table*"))
280 (buffer-disable-undo (current-buffer))
281 (setq case-fold-search t)
283 (insert-buffer-substring buf)
284 (set-marker Info-tag-table-marker
286 (set-marker Info-tag-table-marker pos))))
287 (setq Info-current-file
288 (if (eq filename t) "dir"
289 (file-name-sans-versions buffer-file-name)))))
290 (if (equal nodename "*")
291 (progn (setq Info-current-node nodename)
292 (Info-set-mode-line))
293 ;; Search file for a suitable node.
294 (let ((guesspos (point-min))
295 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
296 ;; First get advice from tag table if file has one.
297 ;; Also, if this is an indirect info file,
298 ;; read the proper subfile into this buffer.
299 (if (marker-position Info-tag-table-marker)
301 (set-buffer (marker-buffer Info-tag-table-marker))
302 (goto-char Info-tag-table-marker)
303 (if (re-search-forward regexp nil t)
305 (setq guesspos (read (current-buffer)))
306 ;; If this is an indirect file,
307 ;; determine which file really holds this node
309 (if (not (eq (current-buffer) (get-buffer "*info*")))
311 (Info-read-subfile guesspos))))
312 (error "No such node: \"%s\"" nodename))))
313 (goto-char (max (point-min) (- guesspos 1000)))
314 ;; Now search from our advised position (or from beg of buffer)
315 ;; to find the actual node.
317 (while (search-forward "\n\^_" nil t)
321 (if (re-search-backward regexp beg t)
323 (error "No such node: %s" nodename)))
325 ;; If we did not finish finding the specified node,
326 ;; go back to the previous one.
327 (or Info-current-node no-going-back (null Info-history)
328 (let ((hist (car Info-history)))
329 (setq Info-history (cdr Info-history))
330 (Info-find-node (nth 0 hist) (nth 1 hist) t)
331 (goto-char (nth 2 hist)))))
332 (goto-char (point-min)))
334 ;; Cache the contents of the (virtual) dir file, once we have merged
335 ;; it for the first time, so we can save time subsequently.
336 (defvar Info-dir-contents nil)
338 ;; Cache for the directory we decided to use for the default-directory
339 ;; of the merged dir text.
340 (defvar Info-dir-contents-directory nil)
342 ;; Record the file attributes of all the files from which we
343 ;; constructed Info-dir-contents.
344 (defvar Info-dir-file-attributes nil)
346 ;; Construct the Info directory node by merging the files named `dir'
347 ;; from various directories. Set the *info* buffer's
348 ;; default-directory to the first directory we actually get any text
350 (defun Info-insert-dir ()
351 (if (and Info-dir-contents Info-dir-file-attributes
352 ;; Verify that none of the files we used has changed
355 (mapcar '(lambda (elt)
356 (let ((curr (file-attributes (car elt))))
357 ;; Don't compare the access time.
358 (if curr (setcar (nthcdr 4 curr) 0))
359 (setcar (nthcdr 4 (cdr elt)) 0)
360 (equal (cdr elt) curr)))
361 Info-dir-file-attributes))))
362 (insert Info-dir-contents)
363 (let ((dirs Info-directory-list)
364 buffers buffer others nodes dirs-done)
366 (setq Info-dir-file-attributes nil)
368 ;; Search the directory list for the directory file.
370 (let ((truename (file-truename (expand-file-name (car dirs)))))
371 (or (member truename dirs-done)
372 (member (directory-file-name truename) dirs-done)
373 ;; Try several variants of specified name.
374 ;; Try upcasing, appending `.info', or both.
378 (progn (setq file (expand-file-name "dir" truename))
379 (file-attributes file))
380 (progn (setq file (expand-file-name "DIR" truename))
381 (file-attributes file))
382 (progn (setq file (expand-file-name "dir.info" truename))
383 (file-attributes file))
384 (progn (setq file (expand-file-name "DIR.INFO" truename))
385 (file-attributes file)))))
388 (cons (directory-file-name truename)
393 (message "Composing main Info directory..."))
394 (set-buffer (generate-new-buffer "info dir"))
395 (insert-file-contents file)
396 (setq buffers (cons (current-buffer) buffers)
397 Info-dir-file-attributes
398 (cons (cons file attrs)
399 Info-dir-file-attributes))))))
400 (setq dirs (cdr dirs))))
403 (error "Can't find the info directory node"))
404 ;; Distinguish the dir file that comes with Emacs from all the
405 ;; others. Yes, that is really what this is supposed to do.
406 ;; If it doesn't work, fix it.
407 (setq buffer (car buffers)
408 others (cdr buffers))
410 ;; Insert the entire original dir file as a start; use its
411 ;; default directory as the default directory for the whole
413 (insert-buffer buffer)
414 (setq Info-dir-contents-directory (save-excursion
418 ;; Look at each of the other buffers one by one.
420 (let ((other (car others)))
421 ;; In each, find all the menus.
424 (goto-char (point-min))
425 ;; Find each menu, and add an elt to NODES for it.
426 (while (re-search-forward "^\\* Menu:" nil t)
427 (let (beg nodename end)
430 (search-backward "\n\^_")
431 (search-forward "Node: ")
432 (setq nodename (Info-following-node-name))
433 (search-forward "\n\^_" nil 'move)
436 (setq nodes (cons (list nodename other beg end) nodes))))))
437 (setq others (cdr others)))
438 ;; Add to the main menu a menu item for each other node.
439 (re-search-forward "^\\* Menu:")
441 (let ((menu-items '("top"))
444 (end (save-excursion (search-forward "\^_" nil t) (point))))
446 (let ((nodename (car (car nodes))))
448 (or (member (downcase nodename) menu-items)
449 (re-search-forward (concat "^\\* "
450 (regexp-quote nodename)
454 (insert "* " nodename "::" "\n")
455 (setq menu-items (cons nodename menu-items))))))
456 (setq nodes (cdr nodes))))
457 ;; Now take each node of each of the other buffers
458 ;; and merge it into the main buffer.
460 (let ((nodename (car (car nodes))))
461 (goto-char (point-min))
462 ;; Find the like-named node in the main buffer.
463 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
464 (regexp-quote nodename)
468 (search-forward "\n\^_" nil 'move)
470 ;; If none exists, add one.
471 (goto-char (point-max))
472 (insert "\^_\nFile: dir\tnode: " nodename "\n\n* Menu:\n\n"))
473 ;; Merge the text from the other buffer's menu
474 ;; into the menu in the like-named node in the main buffer.
475 (apply 'insert-buffer-substring (cdr (car nodes)))
477 (setq nodes (cdr nodes)))
478 ;; Kill all the buffers we just made.
480 (kill-buffer (car buffers))
481 (setq buffers (cdr buffers)))
482 (message "Composing main Info directory...done"))
483 (setq Info-dir-contents (buffer-string)))
484 (setq default-directory Info-dir-contents-directory))
486 (defun Info-read-subfile (nodepos)
487 (set-buffer (marker-buffer Info-tag-table-marker))
488 (goto-char (point-min))
489 (search-forward "\n\^_")
494 (while (not (looking-at "\^_"))
497 thisfilepos thisfilename)
498 (search-forward ": ")
499 (setq thisfilename (buffer-substring beg (- (point) 2)))
500 (setq thisfilepos (read (current-buffer)))
501 ;; read in version 19 stops at the end of number.
502 ;; Advance to the next line.
504 (if (> thisfilepos nodepos)
506 (setq lastfilename thisfilename)
507 (setq lastfilepos thisfilepos))
509 (set-buffer (get-buffer "*info*"))
510 (or (equal Info-current-subfile lastfilename)
511 (let ((buffer-read-only nil))
512 (setq buffer-file-name nil)
515 (info-insert-file-contents lastfilename)
516 (set-buffer-modified-p nil)
517 (setq Info-current-subfile lastfilename)))
518 (goto-char (point-min))
519 (search-forward "\n\^_")
520 (+ (- nodepos lastfilepos) (point))))
522 ;; Select the info node that point is in.
523 (defun Info-select-node ()
525 ;; Find beginning of node.
526 (search-backward "\n\^_")
528 ;; Get nodename spelled as it is in the node.
529 (re-search-forward "Node:[ \t]*")
530 (setq Info-current-node
531 (buffer-substring (point)
533 (skip-chars-forward "^,\t\n")
536 ;; Find the end of it, and narrow.
538 (let (active-expression)
539 (narrow-to-region (point)
540 (if (re-search-forward "\n[\^_\f]" nil t)
543 (if (looking-at "[\n\^_\f]*execute: ")
545 (goto-char (match-end 0))
546 (setq active-expression
547 (read (current-buffer))))))
549 (if Info-enable-active-nodes (eval active-expression))
550 (if Info-fontify (Info-fontify-node))
551 (run-hooks 'Info-selection-hook))))
553 (defun Info-set-mode-line ()
554 (setq mode-line-buffer-identification
557 (if Info-current-file
558 (file-name-nondirectory Info-current-file)
561 (or Info-current-node ""))))
563 ;; Go to an info node specified with a filename-and-nodename string
564 ;; of the sort that is found in pointers in nodes.
566 (defun Info-goto-node (nodename)
567 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
568 (interactive (list (Info-read-node-name "Goto node: ")))
570 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
572 (setq filename (if (= (match-beginning 1) (match-end 1))
574 (substring nodename (match-beginning 2) (match-end 2)))
575 nodename (substring nodename (match-beginning 3) (match-end 3)))
576 (let ((trim (string-match "\\s *\\'" filename)))
577 (if trim (setq filename (substring filename 0 trim))))
578 (let ((trim (string-match "\\s *\\'" nodename)))
579 (if trim (setq nodename (substring nodename 0 trim))))
580 (Info-find-node (if (equal filename "") nil filename)
581 (if (equal nodename "") "Top" nodename))))
583 (defun Info-read-node-name (prompt &optional default)
584 (let* ((completion-ignore-case t)
585 (nodename (completing-read prompt (Info-build-node-completions))))
586 (if (equal nodename "")
588 (Info-read-node-name prompt))
591 (defun Info-build-node-completions ()
592 (or Info-current-file-completions
596 (if (marker-buffer Info-tag-table-marker)
598 (set-buffer (marker-buffer Info-tag-table-marker))
600 (goto-char Info-tag-table-marker)
601 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
603 (cons (list (buffer-substring (match-beginning 1)
607 (goto-char (point-min))
608 (while (search-forward "\n\^_" nil t)
612 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
615 (cons (list (buffer-substring (match-beginning 1)
618 (setq Info-current-file-completions compl))))
620 (defun Info-restore-point (hl)
621 "If this node has been visited, restore the point value when we left."
623 (if (and (equal (nth 0 (car hl)) Info-current-file)
624 (equal (nth 1 (car hl)) Info-current-node))
626 (goto-char (nth 2 (car hl)))
627 (setq hl nil)) ;terminate the while at next iter
628 (setq hl (cdr hl)))))
630 (defvar Info-last-search nil
631 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
633 (defun Info-search (regexp)
634 "Search for REGEXP, starting from point, and select node it's found in."
635 (interactive "sSearch (regexp): ")
636 (if (equal regexp "")
637 (setq regexp Info-last-search)
638 (setq Info-last-search regexp))
639 (let ((found ()) current
640 (onode Info-current-node)
641 (ofile Info-current-file)
643 (osubfile Info-current-subfile))
647 (if (null Info-current-subfile)
648 (progn (re-search-forward regexp) (setq found (point)))
650 (progn (re-search-forward regexp) (setq found (point)))
651 (search-failed nil)))))
652 (if (not found) ;can only happen in subfile case -- else would have erred
655 (set-buffer (marker-buffer Info-tag-table-marker))
656 (goto-char (point-min))
657 (search-forward "\n\^_\nIndirect:")
659 (narrow-to-region (point)
660 (progn (search-forward "\n\^_")
662 (goto-char (point-min))
663 (search-forward (concat "\n" osubfile ": "))
666 (re-search-forward "\\(^.*\\): [0-9]+$")
667 (goto-char (+ (match-end 1) 2))
668 (setq list (cons (cons (read (current-buffer))
669 (buffer-substring (match-beginning 1)
672 (goto-char (1+ (match-end 0))))
673 (setq list (nreverse list)
674 current (car (car list))
677 (message "Searching subfile %s..." (cdr (car list)))
678 (Info-read-subfile (car (car list)))
679 (setq list (cdr list))
680 (goto-char (point-min))
681 (if (re-search-forward regexp nil t)
682 (setq found (point) list ())))
685 (signal 'search-failed (list regexp))))
687 (progn (Info-read-subfile opoint)
689 (Info-select-node)))))
693 (or (and (equal onode Info-current-node)
694 (equal ofile Info-current-file))
695 (setq Info-history (cons (list ofile onode opoint)
698 ;; Extract the value of the node-pointer named NAME.
699 ;; If there is none, use ERRORNAME in the error message;
700 ;; if ERRORNAME is nil, just return nil.
701 (defun Info-extract-pointer (name &optional errorname)
703 (goto-char (point-min))
705 (if (re-search-backward (concat name ":") nil t)
707 (goto-char (match-end 0))
708 (Info-following-node-name))
711 (error (concat "Node has no " (capitalize (or errorname name))))))))
713 ;; Return the node name in the buffer following point.
714 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
715 ;; saying which chas may appear in the node name.
716 (defun Info-following-node-name (&optional allowedchars)
717 (skip-chars-forward " \t")
721 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
722 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
724 (skip-chars-forward "^)")))
725 (skip-chars-backward " ")
729 "Go to the next node of this node."
731 (Info-goto-node (Info-extract-pointer "next")))
734 "Go to the previous node of this node."
736 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
739 "Go to the superior node of this node."
741 (Info-goto-node (Info-extract-pointer "up"))
742 (Info-restore-point Info-history))
745 "Go back to the last node visited."
748 (error "This is the first Info node you looked at"))
749 (let (filename nodename opoint)
750 (setq filename (car (car Info-history)))
751 (setq nodename (car (cdr (car Info-history))))
752 (setq opoint (car (cdr (cdr (car Info-history)))))
753 (setq Info-history (cdr Info-history))
754 (Info-find-node filename nodename)
755 (setq Info-history (cdr Info-history))
758 (defun Info-directory ()
759 "Go to the Info directory node."
761 (Info-find-node "dir" "top"))
763 (defun Info-follow-reference (footnotename)
764 "Follow cross reference named NAME to the node it refers to.
765 NAME may be an abbreviation of the reference name."
767 (let ((completion-ignore-case t)
768 completions default alt-default (start-point (point)) str i bol eol)
770 ;; Store end and beginning of line.
776 (goto-char (point-min))
777 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
778 (setq str (buffer-substring
781 ;; See if this one should be the default.
783 (<= (match-beginning 0) start-point)
784 (<= start-point (point))
786 ;; See if this one should be the alternate default.
787 (and (null alt-default)
788 (and (<= bol (match-beginning 0))
790 (setq alt-default t))
792 (while (setq i (string-match "[ \n\t]+" str i))
793 (setq str (concat (substring str 0 i) " "
794 (substring str (match-end 0))))
796 ;; Record as a completion and perhaps as default.
797 (if (eq default t) (setq default str))
798 (if (eq alt-default t) (setq alt-default str))
802 ;; If no good default was found, try an alternate.
804 (setq default alt-default))
805 ;; If only one cross-reference found, then make it default.
806 (if (eq (length completions) 1)
807 (setq default (car (car completions))))
809 (let ((input (completing-read (if default
810 (concat "Follow reference named: ("
812 "Follow reference named: ")
814 (list (if (equal input "")
816 (error "No cross-references in this node"))))
817 (let (target beg i (str (concat "\\*note " footnotename)))
818 (while (setq i (string-match " " str i))
819 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
822 (goto-char (point-min))
823 (or (re-search-forward str nil t)
824 (error "No cross-reference named %s" footnotename))
825 (goto-char (+ (match-beginning 0) 5))
827 (Info-extract-menu-node-name "Bad format cross reference" t)))
828 (while (setq i (string-match "[ \t\n]+" target i))
829 (setq target (concat (substring target 0 i) " "
830 (substring target (match-end 0))))
832 (Info-goto-node target)))
834 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
835 (skip-chars-forward " \t\n")
838 (skip-chars-forward "^:")
842 (buffer-substring beg (1- (point)))
843 (skip-chars-forward " \t\n")
844 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
845 (while (setq i (string-match "\n" str i))
849 ;; No one calls this.
850 ;;(defun Info-menu-item-sequence (list)
852 ;; (Info-menu (car list))
853 ;; (setq list (cdr list))))
855 (defun Info-complete-menu-item (string predicate action)
856 (let ((case-fold-search t))
857 (cond ((eq action nil)
859 (pattern (concat "\n\\* \\("
860 (regexp-quote string)
863 (set-buffer Info-complete-menu-buffer)
864 (goto-char (point-min))
865 (while (re-search-forward pattern nil t)
866 (setq completions (cons (cons (format "%s"
872 (try-completion string completions predicate)))
875 (pattern (concat "\n\\* \\("
876 (regexp-quote string)
879 (set-buffer Info-complete-menu-buffer)
880 (goto-char (point-min))
881 (while (re-search-forward pattern nil t)
882 (setq completions (cons (cons (format "%s"
888 (all-completions string completions predicate)))
891 (set-buffer Info-complete-menu-buffer)
892 (goto-char (point-min))
893 (re-search-forward (concat "\n\\* "
894 (regexp-quote string)
899 (defun Info-menu (menu-item)
900 "Go to node for menu item named (or abbreviated) NAME.
901 Completion is allowed, and the menu item point is on is the default."
903 (let ((completions '())
904 ;; If point is within a menu item, use that item as the default
909 (goto-char (point-min))
910 (if (not (search-forward "\n* menu:" nil t))
911 (error "No menu in this node"))
917 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t)
918 (setq default (format "%s" (buffer-substring
923 (setq item (let ((completion-ignore-case t)
924 (Info-complete-menu-buffer (current-buffer)))
925 (completing-read (if default
926 (format "Menu item (default %s): "
929 'Info-complete-menu-item nil t)))
930 ;; we rely on the fact that completing-read accepts an input
931 ;; of "" even when the require-match argument is true and ""
932 ;; is not a valid possibility
933 (if (string= item "")
939 ;; there is a problem here in that if several menu items have the same
940 ;; name you can only go to the node of the first with this command.
941 (Info-goto-node (Info-extract-menu-item menu-item)))
943 (defun Info-extract-menu-item (menu-item)
944 (setq menu-item (regexp-quote menu-item))
946 (goto-char (point-min))
947 (or (search-forward "\n* menu:" nil t)
948 (error "No menu in this node"))
949 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
950 (re-search-forward (concat "\n\\* " menu-item) nil t)
951 (error "No such item in menu"))
954 (Info-extract-menu-node-name)))
956 ;; If COUNT is nil, use the last item in the menu.
957 (defun Info-extract-menu-counting (count)
959 (goto-char (point-min))
960 (or (search-forward "\n* menu:" nil t)
961 (error "No menu in this node"))
963 (or (search-forward "\n* " nil t count)
964 (error "Too few items in menu"))
965 (while (search-forward "\n* " nil t)
967 (Info-extract-menu-node-name)))
969 (defun Info-nth-menu-item ()
970 "Go to the node of the Nth menu item.
971 N is the digit argument used to invoke this command."
974 (Info-extract-menu-counting
975 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
977 (defun Info-top-node ()
978 "Go to the Top node of this file."
980 (Info-goto-node "Top"))
982 (defun Info-final-node ()
983 "Go to the final node in this file."
985 (Info-goto-node "Top")
987 ;; Go to the last node in the menu of Top.
988 (Info-goto-node (Info-extract-menu-counting nil))
989 ;; If the last node in the menu is not last in pointer structure,
990 ;; move forward until we can't go any farther.
991 (while (Info-forward-node t t) nil)
992 ;; Then keep moving down to last subnode, unless we reach an index.
993 (while (and (not (string-match "\\<index\\>" Info-current-node))
994 (save-excursion (search-forward "\n* Menu:" nil t)))
995 (Info-goto-node (Info-extract-menu-counting nil)))))
997 (defun Info-forward-node (&optional not-down no-error)
998 "Go forward one node, considering all nodes as forming one sequence."
1000 (goto-char (point-min))
1002 ;; three possibilities, in order of priority:
1003 ;; 1. next node is in a menu in this node (but not in an index)
1004 ;; 2. next node is next at same level
1005 ;; 3. next node is up and next
1006 (cond ((and (not not-down)
1007 (save-excursion (search-forward "\n* menu:" nil t))
1008 (not (string-match "\\<index\\>" Info-current-node)))
1009 (Info-goto-node (Info-extract-menu-counting 1))
1011 ((save-excursion (search-backward "next:" nil t))
1014 ((and (save-excursion (search-backward "up:" nil t))
1015 (not (equal (downcase (Info-extract-pointer "up")) "top")))
1016 (let ((old-node Info-current-node))
1018 (let (Info-history success)
1020 (setq success (Info-forward-node t no-error))
1021 (or success (Info-goto-node old-node))))))
1023 (t (error "No pointer forward from this node"))))
1025 (defun Info-backward-node ()
1026 "Go backward one node, considering all nodes as forming one sequence."
1028 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1029 (upnode (Info-extract-pointer "up" t)))
1030 (cond ((and upnode (string-match "(" upnode))
1031 (error "First node in file"))
1032 ((and upnode (or (null prevnode)
1033 (equal (downcase prevnode) (downcase upnode))))
1036 ;; If we move back at the same level,
1037 ;; go down to find the last subnode*.
1040 (while (and (not (string-match "\\<index\\>" Info-current-node))
1041 (save-excursion (search-forward "\n* Menu:" nil t)))
1042 (Info-goto-node (Info-extract-menu-counting nil)))))
1044 (error "No pointer backward from this node")))))
1047 "Exit Info by selecting some other buffer."
1050 (save-buffers-kill-emacs)
1051 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1052 (bury-buffer (current-buffer))))))
1054 (defun Info-next-menu-item ()
1058 (search-forward "\n* menu:" nil t)
1059 (or (search-forward "\n* " nil t)
1060 (error "No more items in menu"))
1061 (Info-goto-node (Info-extract-menu-node-name))))
1063 (defun Info-last-menu-item ()
1067 (search-backward "\n* menu:" nil t)
1068 (or (search-backward "\n* " nil t)
1069 (error "No previous items in menu"))
1070 (Info-goto-node (Info-extract-menu-node-name))))
1072 (defmacro Info-no-error (&rest body)
1073 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1075 (defun Info-next-preorder ()
1076 "Go to the next node, popping up a level if there is none."
1078 (cond ((Info-no-error (Info-next-menu-item)) )
1079 ((Info-no-error (Info-up)) (forward-line 1))
1080 (t (error "No more nodes"))))
1082 (defun Info-last-preorder ()
1083 "Go to the last node, popping up a level if there is none."
1085 (cond ((Info-no-error (Info-last-menu-item)) )
1086 ((Info-no-error (Info-up)) (forward-line -1))
1087 (t (error "No previous nodes"))))
1089 (defun Info-scroll-up ()
1090 "Read the next screen. If end of buffer is visible, go to next entry."
1092 (if (pos-visible-in-window-p (point-max))
1093 (Info-next-preorder)
1096 (defun Info-scroll-down ()
1097 "Read the previous screen. If start of buffer is visible, go to last entry."
1099 (if (pos-visible-in-window-p (point-min))
1100 (Info-last-preorder)
1103 (defun Info-next-reference ()
1104 "Move cursor to the next cross-reference or menu item in the node."
1106 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1108 (or (eobp) (forward-char 1))
1109 (or (re-search-forward pat nil t)
1111 (goto-char (point-min))
1112 (or (re-search-forward pat nil t)
1115 (error "No cross references in this node")))))
1116 (goto-char (match-beginning 0))
1117 (if (looking-at "\\* Menu:")
1118 (Info-next-reference))))
1120 (defun Info-prev-reference ()
1121 "Move cursor to the previous cross-reference or menu item in the node."
1123 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1125 (or (re-search-backward pat nil t)
1127 (goto-char (point-max))
1128 (or (re-search-backward pat nil t)
1131 (error "No cross references in this node")))))
1132 (goto-char (match-beginning 0))
1133 (if (looking-at "\\* Menu:")
1134 (Info-prev-reference))))
1136 (defun Info-index (topic)
1137 "Look up a string in the index for this file.
1138 The index is defined as the first node in the top-level menu whose
1139 name contains the word \"Index\", plus any immediately following
1140 nodes whose names also contain the word \"Index\".
1141 If there are no exact matches to the specified topic, this chooses
1142 the first match which is a case-insensitive substring of a topic.
1143 Use the `,' command to see the other matches.
1144 Give a blank topic name to go to the Index node itself."
1145 (interactive "sIndex topic: ")
1146 (let ((orignode Info-current-node)
1148 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
1149 (regexp-quote topic)))
1151 (Info-goto-node "Top")
1152 (or (search-forward "\n* menu:" nil t)
1154 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1156 (goto-char (match-beginning 1))
1157 (let ((Info-keeping-history nil))
1158 (Info-goto-node (Info-extract-menu-node-name)))
1159 (or (equal topic "")
1162 (Info-keeping-history nil)
1166 (goto-char (point-min))
1167 (while (re-search-forward pattern nil t)
1169 (cons (list (buffer-substring (match-beginning 1)
1171 (buffer-substring (match-beginning 2)
1174 (string-to-int (concat "0"
1179 (and (setq node (Info-extract-pointer "next" t))
1180 (string-match "\\<Index\\>" node)))
1181 (Info-goto-node node))
1185 (error "No \"%s\" in index" topic)))
1186 ;; Here it is a feature that assoc is case-sensitive.
1187 (while (setq found (assoc topic matches))
1188 (setq exact (cons found exact)
1189 matches (delq found matches)))
1190 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1191 (Info-index-next 0)))))
1193 (defun Info-index-next (num)
1194 "Go to the next matching index item from the last `i' command."
1196 (or Info-index-alternatives
1197 (error "No previous `i' command in this file"))
1199 (setq num (+ num (length Info-index-alternatives))))
1201 (setq Info-index-alternatives
1202 (nconc (cdr Info-index-alternatives)
1203 (list (car Info-index-alternatives)))
1205 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1206 (if (> (nth 3 (car Info-index-alternatives)) 0)
1207 (forward-line (nth 3 (car Info-index-alternatives)))
1208 (forward-line 3) ; don't search in headers
1209 (let ((name (car (car Info-index-alternatives))))
1210 (if (or (re-search-forward (format
1211 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1212 (regexp-quote name)) nil t)
1213 (search-forward (format "`%s'" name) nil t)
1214 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1216 (format "`%s'" (substring name 0 (match-beginning 1)))
1218 (search-forward name nil t))
1220 (goto-char (point-min)))))
1221 (message "Found \"%s\" in %s. %s"
1222 (car (car Info-index-alternatives))
1223 (nth 2 (car Info-index-alternatives))
1224 (if (cdr Info-index-alternatives)
1225 "(Press `,' for more)"
1228 (defun Info-undefined ()
1229 "Make command be undefined in Info."
1234 "Enter the Info tutorial."
1236 (delete-other-windows)
1237 (Info-find-node "info"
1238 (if (< (window-height) 23)
1242 (defun Info-summary ()
1243 "Display a brief summary of all Info commands."
1245 (save-window-excursion
1246 (switch-to-buffer "*Help*")
1248 (insert (documentation 'Info-mode))
1249 (goto-char (point-min))
1251 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1252 (message (if flag "Type Space to see more"
1253 "Type Space to return to Info"))
1254 (if (not (eq ?\ (setq ch (read-event))))
1255 (progn (setq unread-command-events (list ch)) nil)
1258 (bury-buffer "*Help*")))
1260 (defun Info-get-token (pos start all &optional errorstring)
1261 "Return the token around POS,
1262 POS must be somewhere inside the token
1263 START is a regular expression which will match the
1264 beginning of the tokens delimited string
1265 ALL is a regular expression with a single
1266 parenthized subpattern which is the token to be
1267 returned. E.g. '{\(.*\)}' would return any string
1268 enclosed in braces around POS.
1269 SIG optional fourth argument, controls action on no match
1272 a string: signal an error, using that string."
1275 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1277 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1278 (not (setq found (and (<= (match-beginning 0) pos)
1279 (> (match-end 0) pos))))))
1280 (if (and found (<= (match-beginning 0) pos)
1281 (> (match-end 0) pos))
1282 (buffer-substring (match-beginning 1) (match-end 1))
1283 (cond ((null errorstring)
1289 (error "No %s around position %d" errorstring pos)))))))
1291 (defun Info-mouse-follow-nearest-node (click)
1292 "\\<Info-mode-map>Follow a node reference near point.
1293 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1294 At end of the node's text, moves to the next node, or up if none."
1296 (let* ((start (event-start click))
1297 (window (car start))
1298 (pos (car (cdr start))))
1299 (select-window window)
1301 (and (not (Info-try-follow-nearest-node))
1302 (save-excursion (forward-line 1) (eobp))
1303 (Info-next-preorder)))
1305 (defun Info-follow-nearest-node ()
1306 "\\<Info-mode-map>Follow a node reference near point.
1307 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1308 If no reference to follow, moves to the next node, or up if none."
1310 (or (Info-try-follow-nearest-node)
1311 (Info-next-preorder)))
1313 ;; Common subroutine.
1314 (defun Info-try-follow-nearest-node ()
1315 "Follow a node reference near point. Return non-nil if successful."
1318 ((setq node (Info-get-token (point) "\\*note[ \n]"
1319 "\\*note[ \n]\\([^:]*\\):"))
1320 (Info-follow-reference node))
1321 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1322 (Info-goto-node node))
1323 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1325 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1326 (Info-goto-node node))
1327 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1328 (Info-goto-node node))
1329 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1330 (Info-goto-node "Top"))
1331 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1332 (Info-goto-node node)))
1335 (defvar Info-mode-map nil
1336 "Keymap containing Info commands.")
1339 (setq Info-mode-map (make-keymap))
1340 (suppress-keymap Info-mode-map)
1341 (define-key Info-mode-map "." 'beginning-of-buffer)
1342 (define-key Info-mode-map " " 'Info-scroll-up)
1343 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1344 (define-key Info-mode-map "\t" 'Info-next-reference)
1345 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1346 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1347 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1348 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1349 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1350 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1351 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1352 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1353 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1354 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1355 (define-key Info-mode-map "0" 'undefined)
1356 (define-key Info-mode-map "?" 'Info-summary)
1357 (define-key Info-mode-map "]" 'Info-forward-node)
1358 (define-key Info-mode-map "[" 'Info-backward-node)
1359 (define-key Info-mode-map "<" 'Info-top-node)
1360 (define-key Info-mode-map ">" 'Info-final-node)
1361 (define-key Info-mode-map "b" 'beginning-of-buffer)
1362 (define-key Info-mode-map "d" 'Info-directory)
1363 (define-key Info-mode-map "e" 'Info-edit)
1364 (define-key Info-mode-map "f" 'Info-follow-reference)
1365 (define-key Info-mode-map "g" 'Info-goto-node)
1366 (define-key Info-mode-map "h" 'Info-help)
1367 (define-key Info-mode-map "i" 'Info-index)
1368 (define-key Info-mode-map "l" 'Info-last)
1369 (define-key Info-mode-map "m" 'Info-menu)
1370 (define-key Info-mode-map "n" 'Info-next)
1371 (define-key Info-mode-map "p" 'Info-prev)
1372 (define-key Info-mode-map "q" 'Info-exit)
1373 (define-key Info-mode-map "s" 'Info-search)
1374 (define-key Info-mode-map "t" 'Info-top-node)
1375 (define-key Info-mode-map "u" 'Info-up)
1376 (define-key Info-mode-map "," 'Info-index-next)
1377 (define-key Info-mode-map "\177" 'Info-scroll-down)
1378 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1381 ;; Info mode is suitable only for specially formatted data.
1382 (put 'info-mode 'mode-class 'special)
1386 Info mode provides commands for browsing through the Info documentation tree.
1387 Documentation in Info is divided into \"nodes\", each of which discusses
1388 one topic and contains references to other nodes which discuss related
1389 topics. Info has commands to follow the references and show you other nodes.
1391 \\[Info-help] Invoke the Info tutorial.
1393 Selecting other nodes:
1394 \\[Info-next] Move to the \"next\" node of this node.
1395 \\[Info-prev] Move to the \"previous\" node of this node.
1396 \\[Info-up] Move \"up\" from this node.
1397 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1398 Picking a menu item causes another node to be selected.
1399 \\[Info-directory] Go to the Info directory node.
1400 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1401 \\[Info-last] Move to the last node you were at.
1402 \\[Info-index] Look up a topic in this file's Index and move to that node.
1403 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1405 Moving within a node:
1406 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1407 already visible, try to go to the next menu entry, or up if there is none.
1408 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1409 already visible, try to go to the previous menu entry, or up if there is none.
1410 \\[beginning-of-buffer] Go to beginning of node.
1413 \\[Info-exit] Quit Info: reselect previously selected buffer.
1414 \\[Info-edit] Edit contents of selected node.
1415 1 Pick first item in node's menu.
1416 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1417 \\[Info-goto-node] Move to node specified by name.
1418 You may include a filename as well, as (FILENAME)NODENAME.
1419 \\[universal-argument] \\[info] Move to new Info file with completion.
1420 \\[Info-search] Search through this Info file for specified regexp,
1421 and select the node in which the next occurrence is found.
1422 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1423 and if that fails try to move up, and if that fails, tell user
1424 he/she is done reading.
1425 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1426 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1427 (kill-all-local-variables)
1428 (setq major-mode 'Info-mode)
1429 (setq mode-name "Info")
1430 (use-local-map Info-mode-map)
1431 (set-syntax-table text-mode-syntax-table)
1432 (setq local-abbrev-table text-mode-abbrev-table)
1433 (setq case-fold-search t)
1434 (setq buffer-read-only t)
1435 (make-local-variable 'Info-current-file)
1436 (make-local-variable 'Info-current-subfile)
1437 (make-local-variable 'Info-current-node)
1438 (make-local-variable 'Info-tag-table-marker)
1439 (make-local-variable 'Info-history)
1440 (make-local-variable 'Info-index-alternatives)
1441 (if (fboundp 'make-face)
1443 (make-face 'info-node)
1444 (make-face 'info-menu-5)
1445 (make-face 'info-xref)
1446 (or (face-differs-from-default-p 'info-node)
1447 (if (face-differs-from-default-p 'bold-italic)
1448 (copy-face 'bold-italic 'info-node)
1449 (copy-face 'bold 'info-node)))
1450 (or (face-differs-from-default-p 'info-menu-5)
1451 (set-face-underline-p 'info-menu-5 t))
1452 (or (face-differs-from-default-p 'info-xref)
1453 (copy-face 'bold 'info-xref)))
1454 (setq Info-fontify nil))
1455 (Info-set-mode-line)
1456 (run-hooks 'Info-mode-hook))
1458 (defvar Info-edit-map nil
1459 "Local keymap used within `e' command of Info.")
1462 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1463 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1465 ;; Info-edit mode is suitable only for specially formatted data.
1466 (put 'info-edit-mode 'mode-class 'special)
1468 (defun Info-edit-mode ()
1469 "Major mode for editing the contents of an Info node.
1470 Like text mode with the addition of `Info-cease-edit'
1471 which returns to Info mode for browsing.
1476 "Edit the contents of this Info node.
1477 Allowed only if variable `Info-enable-edit' is non-nil."
1479 (or Info-enable-edit
1480 (error "Editing info nodes is not enabled"))
1481 (use-local-map Info-edit-map)
1482 (setq major-mode 'Info-edit-mode)
1483 (setq mode-name "Info Edit")
1484 (kill-local-variable 'mode-line-buffer-identification)
1485 (setq buffer-read-only nil)
1486 ;; Make mode line update.
1487 (set-buffer-modified-p (buffer-modified-p))
1488 (message (substitute-command-keys
1489 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1491 (defun Info-cease-edit ()
1492 "Finish editing Info node; switch back to Info proper."
1494 ;; Do this first, so nothing has changed if user C-g's at query.
1495 (and (buffer-modified-p)
1496 (y-or-n-p "Save the file? ")
1498 (use-local-map Info-mode-map)
1499 (setq major-mode 'Info-mode)
1500 (setq mode-name "Info")
1501 (Info-set-mode-line)
1502 (setq buffer-read-only t)
1503 ;; Make mode line update.
1504 (set-buffer-modified-p (buffer-modified-p))
1505 (and (marker-position Info-tag-table-marker)
1507 (message "Tags may have changed. Use Info-tagify if necessary")))
1509 (defun Info-find-emacs-command-nodes (command)
1510 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1511 The locations are of the format used in Info-history, i.e.
1512 \(FILENAME NODENAME BUFFERPOS\)."
1515 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1516 ":\\s *\\(.*\\)\\.$")))
1518 (Info-find-node "emacs" "Command Index")
1519 ;; Take the index node off the Info history.
1520 (setq Info-history (cdr Info-history))
1521 (goto-char (point-max))
1522 (while (re-search-backward cmd-desc nil t)
1523 (setq where (cons (list Info-current-file
1532 (defun Info-goto-emacs-command-node (command)
1533 "Go to the Info node in the Emacs manual for command COMMAND.
1534 The command is found by looking up in Emacs manual's Command Index."
1535 (interactive "CFind documentation for command: ")
1536 (or (commandp command)
1537 (signal 'wrong-type-argument (list 'commandp command)))
1538 (let ((where (Info-find-emacs-command-nodes command)))
1540 (let ((num-matches (length where)))
1541 ;; Get Info running, and pop to it in another window.
1542 (save-window-excursion
1544 (pop-to-buffer "*info*")
1545 (Info-find-node (car (car where))
1546 (car (cdr (car where))))
1547 (if (> num-matches 1)
1549 ;; Info-find-node already pushed (car where) onto
1550 ;; Info-history. Put the other nodes that were found on
1552 (setq Info-history (nconc (cdr where) Info-history))
1553 (message (substitute-command-keys
1554 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1556 (if (> num-matches 2) "ies" "y")
1557 (if (> num-matches 2) "them" "it")))))
1558 (error "Couldn't find documentation for %s." command))))
1561 (defun Info-goto-emacs-key-command-node (key)
1562 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1563 Interactively, if the binding is execute-extended-command, a command is read.
1564 The command is found by looking up in Emacs manual's Command Index."
1565 (interactive "kFind documentation for key:")
1566 (let ((command (key-binding key)))
1567 (cond ((null command)
1568 (message "%s is undefined" (key-description key)))
1569 ((and (interactive-p)
1570 (eq command 'execute-extended-command))
1571 (Info-goto-emacs-command-node
1572 (read-command "Find documentation for command: ")))
1574 (Info-goto-emacs-command-node command)))))
1576 (defun Info-fontify-node ()
1578 (let ((buffer-read-only nil))
1579 (goto-char (point-min))
1580 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1582 (goto-char (match-end 0))
1584 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1585 (goto-char (match-end 0))
1586 (put-text-property (match-beginning 1) (match-end 1)
1588 (put-text-property (match-beginning 1) (match-end 1)
1589 'mouse-face 'highlight))))
1590 (goto-char (point-min))
1591 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
1592 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1594 (put-text-property (match-beginning 1) (match-end 1)
1596 (put-text-property (match-beginning 1) (match-end 1)
1597 'mouse-face 'highlight)))
1598 (goto-char (point-min))
1599 (if (and (search-forward "\n* Menu:" nil t)
1600 (not (string-match "\\<Index\\>" Info-current-node))
1601 ;; Don't take time to annotate huge menus
1602 (< (- (point-max) (point)) 30000))
1604 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1606 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
1607 (put-text-property (match-beginning 0)
1608 (1+ (match-beginning 0))
1609 'face 'info-menu-5))
1610 (put-text-property (match-beginning 1) (match-end 1)
1612 (put-text-property (match-beginning 1) (match-end 1)
1613 'mouse-face 'highlight))))
1614 (set-buffer-modified-p nil))))
1618 ;;; info.el ends here