1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97 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."
61 (defcustom Info-fontify-maximum-menu-size 30000
62 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
66 (defvar Info-directory-list
67 (let ((path (getenv "INFOPATH"))
68 ;; This is for older Emacs versions
69 ;; which might get this info.el from the Texinfo distribution.
70 (path-separator (if (boundp 'path-separator) path-separator
71 (if (eq system-type 'ms-dos) ";" ":")))
72 (source (expand-file-name "info/" source-directory))
73 (sibling (if installation-directory
74 (expand-file-name "info/" installation-directory)))
79 (while (> (length path) 0)
80 (setq idx (or (string-match path-separator path) (length path))
81 list (cons (substring path 0 idx) list)
82 path (substring path (min (1+ idx)
85 (if (and sibling (file-exists-p sibling))
86 (setq alternative sibling)
87 (setq alternative source))
88 (if (or (member alternative Info-default-directory-list)
89 (not (file-exists-p alternative))
90 ;; On DOS/NT, we use movable executables always,
91 ;; and we must always find the Info dir at run time.
92 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
94 ;; Use invocation-directory for Info only if we used it for
95 ;; exec-directory also.
96 (not (string= exec-directory
97 (expand-file-name "lib-src/"
98 installation-directory)))))
99 Info-default-directory-list
100 (reverse (cons alternative
101 (cdr (reverse Info-default-directory-list)))))))
102 "List of directories to search for Info documentation files.
103 nil means not yet initialized. In this case, Info uses the environment
104 variable INFOPATH to initialize it, or `Info-default-directory-list'
105 if there is no INFOPATH variable in the environment.
106 The last element of `Info-default-directory-list' is the directory
107 where Emacs installs the Info files that come with it.
109 If you run the Emacs executable from the `src' directory in the Emacs
110 source tree, the `info' directory in the source tree is used as the last
111 element, in place of the installation Info directory. This is useful
112 when you run a version of Emacs without installing it.")
114 (defcustom Info-additional-directory-list nil
115 "List of additional directories to search for Info documentation files.
116 These directories are not searched for merging the `dir' file."
117 :type '(repeat directory)
120 (defvar Info-current-file nil
121 "Info file that Info is now looking at, or nil.
122 This is the name that was specified in Info, not the actual file name.
123 It doesn't contain directory names or file name extensions added by Info.")
125 (defvar Info-current-subfile nil
126 "Info subfile that is actually in the *info* buffer now,
127 or nil if current info file is not split into subfiles.")
129 (defvar Info-current-node nil
130 "Name of node that Info is now looking at, or nil.")
132 (defvar Info-tag-table-marker nil
133 "Marker pointing at beginning of current Info file's tag table.
134 Marker points nowhere if file has no tag table.")
136 (defvar Info-tag-table-buffer nil
137 "Buffer used for indirect tag tables.")
139 (defvar Info-current-file-completions nil
140 "Cached completion list for current Info file.")
142 (defvar Info-index-alternatives nil
143 "List of possible matches for last Info-index command.")
145 (defvar Info-standalone nil
146 "Non-nil if Emacs was started solely as an Info browser.")
148 (defvar Info-suffix-list
149 (if (eq system-type 'ms-dos)
150 '( (".gz" . "gunzip")
154 '( (".info.Z" . "uncompress")
155 (".info.Y" . "unyabba")
156 (".info.gz" . "gunzip")
157 (".info.z" . "gunzip")
159 (".Z" . "uncompress")
164 "List of file name suffixes and associated decoding commands.
165 Each entry should be (SUFFIX . STRING); the file is given to
166 the command as standard input. If STRING is nil, no decoding is done.
167 Because the SUFFIXes are tried in order, the empty string should
168 be last in the list.")
170 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
171 ;; First, on ms-dos, delete some of the extension in FILENAME
173 (defun info-insert-file-contents-1 (filename suffix)
174 (if (not (eq system-type 'ms-dos))
175 (concat filename suffix)
176 (let* ((sans-exts (file-name-sans-extension filename))
177 ;; How long is the extension in FILENAME (not counting the dot).
178 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
180 ;; SUFFIX starts with a dot. If FILENAME already has one,
181 ;; get rid of the one in SUFFIX (unless suffix is empty).
182 (or (and (<= ext-len 0)
183 (not (eq (aref filename (1- (length filename))) ?.)))
184 (= (length suffix) 0)
185 (setq suffix (substring suffix 1)))
186 ;; How many chars of that extension should we keep?
187 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
188 ;; Get rid of the rest of the extension, and add SUFFIX.
189 (concat (substring filename 0 (- (length filename)
190 (- ext-len ext-left)))
193 (defun info-insert-file-contents (filename &optional visit)
194 "Insert the contents of an info file in the current buffer.
195 Do the right thing if the file has been compressed or zipped."
196 (let ((tail Info-suffix-list)
198 (if (file-exists-p filename)
199 ;; FILENAME exists--see if that name contains a suffix.
200 ;; If so, set DECODE accordingly.
204 (concat (regexp-quote (car (car tail))) "$")
206 (setq tail (cdr tail)))
207 (setq fullname filename
208 decoder (cdr (car tail))))
209 ;; Try adding suffixes to FILENAME and see if we can find something.
211 (not (file-exists-p (info-insert-file-contents-1
212 filename (car (car tail))))))
213 (setq tail (cdr tail)))
214 ;; If we found a file with a suffix, set DECODER according to the suffix
215 ;; and set FULLNAME to the file's actual name.
216 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
217 decoder (cdr (car tail)))
219 (error "Can't find %s or any compressed version of it" filename)))
220 ;; check for conflict with jka-compr
221 (if (and (featurep 'jka-compr)
222 (jka-compr-installed-p)
223 (jka-compr-get-compression-info fullname))
225 (insert-file-contents fullname visit)
227 (let ((buffer-read-only nil)
228 (default-directory (or (file-name-directory fullname)
230 (call-process-region (point-min) (point-max) decoder t t)))))
232 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
235 (defun info (&optional file)
236 "Enter Info, the documentation browser.
237 Optional argument FILE specifies the file to examine;
238 the default is the top-level directory of Info.
240 In interactive use, a prefix argument directs this command
241 to read a file name from the minibuffer.
243 The search path for Info files is in the variable `Info-directory-list'.
244 The top-level Info directory is made by combining all the files named `dir'
245 in all the directories in that path."
246 (interactive (if current-prefix-arg
247 (list (read-file-name "Info file name: " nil nil t))))
249 (Info-goto-node (concat "(" file ")"))
250 (if (get-buffer "*info*")
251 (pop-to-buffer "*info*")
255 (defun info-standalone ()
256 "Run Emacs as a standalone Info reader.
257 Usage: emacs -f info-standalone [filename]
258 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
259 (setq Info-standalone t)
260 (if (and command-line-args-left
261 (not (string-match "^-" (car command-line-args-left))))
264 (info (car command-line-args-left))
265 (setq command-line-args-left (cdr command-line-args-left)))
266 (error (send-string-to-terminal
267 (format "%s\n" (if (eq (car-safe err) 'error)
269 (save-buffers-kill-emacs)))
272 ;; Go to an info node specified as separate filename and nodename.
273 ;; no-going-back is non-nil if recovering from an error in this function;
274 ;; it says do not attempt further (recursive) error recovery.
275 (defun Info-find-node (filename nodename &optional no-going-back)
276 ;; Convert filename to lower case if not found as specified.
279 (let (temp temp-downcase found)
280 (setq filename (substitute-in-file-name filename))
281 (if (string= (downcase filename) "dir")
283 (let ((dirs (if (string-match "^\\./" filename)
284 ;; If specified name starts with `./'
285 ;; then just try current directory.
287 (if (file-name-absolute-p filename)
288 ;; No point in searching for an
289 ;; absolute file name
291 (if Info-additional-directory-list
292 (append Info-directory-list
293 Info-additional-directory-list)
294 Info-directory-list)))))
295 ;; Search the directory list for file FILENAME.
296 (while (and dirs (not found))
297 (setq temp (expand-file-name filename (car dirs)))
299 (expand-file-name (downcase filename) (car dirs)))
300 ;; Try several variants of specified name.
301 (let ((suffix-list Info-suffix-list))
302 (while (and suffix-list (not found))
303 (cond ((file-exists-p
304 (info-insert-file-contents-1
305 temp (car (car suffix-list))))
308 (info-insert-file-contents-1
309 temp-downcase (car (car suffix-list))))
310 (setq found temp-downcase)))
311 (setq suffix-list (cdr suffix-list))))
312 (setq dirs (cdr dirs)))))
314 (setq filename found)
315 (error "Info file %s does not exist" filename))))
316 ;; Record the node we are leaving.
317 (if (and Info-current-file (not no-going-back))
319 (cons (list Info-current-file Info-current-node (point))
321 ;; Go into info buffer.
322 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
323 (buffer-disable-undo (current-buffer))
324 (or (eq major-mode 'Info-mode)
327 (setq Info-current-node nil)
330 ;; Switch files if necessary
332 (equal Info-current-file filename)
333 (let ((buffer-read-only nil))
334 (setq Info-current-file nil
335 Info-current-subfile nil
336 Info-current-file-completions nil
337 buffer-file-name nil)
341 (info-insert-file-contents filename t)
342 (setq default-directory (file-name-directory filename)))
343 (set-buffer-modified-p nil)
344 ;; See whether file has a tag table. Record the location if yes.
345 (goto-char (point-max))
347 ;; Use string-equal, not equal, to ignore text props.
348 (if (not (or (string-equal nodename "*")
350 (search-forward "\^_\nEnd tag table\n" nil t))))
352 ;; We have a tag table. Find its beginning.
353 ;; Is this an indirect file?
354 (search-backward "\nTag table:\n")
358 (looking-at "(Indirect)\n"))
359 ;; It is indirect. Copy it to another buffer
360 ;; and record that the tag table is in that buffer.
361 (let ((buf (current-buffer))
363 (or Info-tag-table-buffer
364 (generate-new-buffer " *info tag table*"))))
365 (setq Info-tag-table-buffer tagbuf)
368 (buffer-disable-undo (current-buffer))
369 (setq case-fold-search t)
371 (insert-buffer-substring buf))
372 (set-marker Info-tag-table-marker
373 (match-end 0) tagbuf))
374 (set-marker Info-tag-table-marker pos)))
375 (set-marker Info-tag-table-marker nil))
376 (setq Info-current-file
377 (if (eq filename t) "dir" filename))))
378 ;; Use string-equal, not equal, to ignore text props.
379 (if (string-equal nodename "*")
380 (progn (setq Info-current-node nodename)
381 (Info-set-mode-line))
382 ;; Search file for a suitable node.
383 (let ((guesspos (point-min))
384 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
385 ;; First get advice from tag table if file has one.
386 ;; Also, if this is an indirect info file,
387 ;; read the proper subfile into this buffer.
388 (if (marker-position Info-tag-table-marker)
390 (let ((m Info-tag-table-marker)
393 (set-buffer (marker-buffer m))
395 (beginning-of-line) ;so re-search will work.
396 (setq found (re-search-forward regexp nil t))
398 (setq guesspos (read (current-buffer))))
399 (setq found-mode major-mode))
402 ;; If this is an indirect file, determine
403 ;; which file really holds this node and
405 (if (not (eq found-mode 'Info-mode))
406 ;; Note that the current buffer must be
407 ;; the *info* buffer on entry to
408 ;; Info-read-subfile. Thus the hackery
410 (setq guesspos (Info-read-subfile guesspos))))
411 (error "No such node: %s" nodename)))))
412 (goto-char (max (point-min) (- guesspos 1000)))
413 ;; Now search from our advised position (or from beg of buffer)
414 ;; to find the actual node.
416 (while (search-forward "\n\^_" nil t)
420 (if (re-search-backward regexp beg t)
422 (error "No such node: %s" nodename)))
424 ;; If we did not finish finding the specified node,
425 ;; go back to the previous one.
426 (or Info-current-node no-going-back (null Info-history)
427 (let ((hist (car Info-history)))
428 (setq Info-history (cdr Info-history))
429 (Info-find-node (nth 0 hist) (nth 1 hist) t)
430 (goto-char (nth 2 hist)))))
431 (goto-char (point-min)))
433 ;; Cache the contents of the (virtual) dir file, once we have merged
434 ;; it for the first time, so we can save time subsequently.
435 (defvar Info-dir-contents nil)
437 ;; Cache for the directory we decided to use for the default-directory
438 ;; of the merged dir text.
439 (defvar Info-dir-contents-directory nil)
441 ;; Record the file attributes of all the files from which we
442 ;; constructed Info-dir-contents.
443 (defvar Info-dir-file-attributes nil)
445 ;; Construct the Info directory node by merging the files named `dir'
446 ;; from various directories. Set the *info* buffer's
447 ;; default-directory to the first directory we actually get any text
449 (defun Info-insert-dir ()
450 (if (and Info-dir-contents Info-dir-file-attributes
451 ;; Verify that none of the files we used has changed
454 (mapcar '(lambda (elt)
455 (let ((curr (file-attributes (car elt))))
456 ;; Don't compare the access time.
457 (if curr (setcar (nthcdr 4 curr) 0))
458 (setcar (nthcdr 4 (cdr elt)) 0)
459 (equal (cdr elt) curr)))
460 Info-dir-file-attributes))))
461 (insert Info-dir-contents)
462 (let ((dirs Info-directory-list)
463 buffers buffer others nodes dirs-done)
465 (setq Info-dir-file-attributes nil)
467 ;; Search the directory list for the directory file.
469 (let ((truename (file-truename (expand-file-name (car dirs)))))
470 (or (member truename dirs-done)
471 (member (directory-file-name truename) dirs-done)
472 ;; Try several variants of specified name.
473 ;; Try upcasing, appending `.info', or both.
477 (progn (setq file (expand-file-name "dir" truename))
478 (file-attributes file))
479 (progn (setq file (expand-file-name "DIR" truename))
480 (file-attributes file))
481 (progn (setq file (expand-file-name "dir.info" truename))
482 (file-attributes file))
483 (progn (setq file (expand-file-name "DIR.INFO" truename))
484 (file-attributes file)))))
487 (cons (directory-file-name truename)
492 (message "Composing main Info directory..."))
493 (set-buffer (generate-new-buffer "info dir"))
494 (insert-file-contents file)
495 (setq buffers (cons (current-buffer) buffers)
496 Info-dir-file-attributes
497 (cons (cons file attrs)
498 Info-dir-file-attributes))))))
499 (or (cdr dirs) (setq Info-dir-contents-directory
500 (file-name-as-directory (car dirs))))
501 (setq dirs (cdr dirs))))
504 (error "Can't find the Info directory node"))
505 ;; Distinguish the dir file that comes with Emacs from all the
506 ;; others. Yes, that is really what this is supposed to do.
507 ;; If it doesn't work, fix it.
508 (setq buffer (car buffers)
509 others (cdr buffers))
511 ;; Insert the entire original dir file as a start; note that we've
512 ;; already saved its default directory to use as the default
513 ;; directory for the whole concatenation.
514 (insert-buffer buffer)
516 ;; Look at each of the other buffers one by one.
518 (let ((other (car others)))
519 ;; In each, find all the menus.
522 (goto-char (point-min))
523 ;; Find each menu, and add an elt to NODES for it.
524 (while (re-search-forward "^\\* Menu:" nil t)
525 (let (beg nodename end)
528 (search-backward "\n\^_")
529 (search-forward "Node: ")
530 (setq nodename (Info-following-node-name))
531 (search-forward "\n\^_" nil 'move)
534 (setq nodes (cons (list nodename other beg end) nodes))))))
535 (setq others (cdr others)))
536 ;; Add to the main menu a menu item for each other node.
537 (re-search-forward "^\\* Menu:")
539 (let ((menu-items '("top"))
542 (end (save-excursion (search-forward "\^_" nil t) (point))))
544 (let ((nodename (car (car nodes))))
546 (or (member (downcase nodename) menu-items)
547 (re-search-forward (concat "^\\* "
548 (regexp-quote nodename)
552 (insert "* " nodename "::" "\n")
553 (setq menu-items (cons nodename menu-items))))))
554 (setq nodes (cdr nodes))))
555 ;; Now take each node of each of the other buffers
556 ;; and merge it into the main buffer.
558 (let ((nodename (car (car nodes))))
559 (goto-char (point-min))
560 ;; Find the like-named node in the main buffer.
561 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
562 (regexp-quote nodename)
566 (search-forward "\n\^_" nil 'move)
569 ;; If none exists, add one.
570 (goto-char (point-max))
571 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
572 ;; Merge the text from the other buffer's menu
573 ;; into the menu in the like-named node in the main buffer.
574 (apply 'insert-buffer-substring (cdr (car nodes))))
575 (setq nodes (cdr nodes)))
576 ;; Kill all the buffers we just made.
578 (kill-buffer (car buffers))
579 (setq buffers (cdr buffers)))
580 (message "Composing main Info directory...done"))
581 (setq Info-dir-contents (buffer-string)))
582 (setq default-directory Info-dir-contents-directory))
584 ;; Note that on entry to this function the current-buffer must be the
585 ;; *info* buffer; not the info tags buffer.
586 (defun Info-read-subfile (nodepos)
587 ;; NODEPOS is either a position (in the Info file as a whole,
588 ;; not relative to a subfile) or the name of a subfile.
591 (if (numberp nodepos)
593 (set-buffer (marker-buffer Info-tag-table-marker))
594 (goto-char (point-min))
595 (search-forward "\n\^_")
598 (while (not (looking-at "\^_"))
601 thisfilepos thisfilename)
602 (search-forward ": ")
603 (setq thisfilename (buffer-substring beg (- (point) 2)))
604 (setq thisfilepos (read (current-buffer)))
605 ;; read in version 19 stops at the end of number.
606 ;; Advance to the next line.
608 (if (> thisfilepos nodepos)
610 (setq lastfilename thisfilename)
611 (setq lastfilepos thisfilepos))
613 (setq lastfilename nodepos)
614 (setq lastfilepos 0))
615 ;; Assume previous buffer is in Info-mode.
616 ;; (set-buffer (get-buffer "*info*"))
617 (or (equal Info-current-subfile lastfilename)
618 (let ((buffer-read-only nil))
619 (setq buffer-file-name nil)
622 (info-insert-file-contents lastfilename)
623 (set-buffer-modified-p nil)
624 (setq Info-current-subfile lastfilename)))
625 (goto-char (point-min))
626 (search-forward "\n\^_")
627 (if (numberp nodepos)
628 (+ (- nodepos lastfilepos) (point)))))
630 ;; Select the info node that point is in.
631 (defun Info-select-node ()
633 ;; Find beginning of node.
634 (search-backward "\n\^_")
636 ;; Get nodename spelled as it is in the node.
637 (re-search-forward "Node:[ \t]*")
638 (setq Info-current-node
639 (buffer-substring-no-properties (point)
641 (skip-chars-forward "^,\t\n")
644 ;; Find the end of it, and narrow.
646 (let (active-expression)
647 (narrow-to-region (point)
648 (if (re-search-forward "\n[\^_\f]" nil t)
651 (if (looking-at "[\n\^_\f]*execute: ")
653 (goto-char (match-end 0))
654 (setq active-expression
655 (read (current-buffer))))))
657 (if Info-enable-active-nodes (eval active-expression))
658 (if Info-fontify (Info-fontify-node))
659 (run-hooks 'Info-selection-hook))))
661 (defun Info-set-mode-line ()
662 (setq mode-line-buffer-identification
665 (if Info-current-file
666 (file-name-nondirectory Info-current-file)
669 (or Info-current-node ""))))
671 ;; Go to an info node specified with a filename-and-nodename string
672 ;; of the sort that is found in pointers in nodes.
674 (defun Info-goto-node (nodename)
675 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
676 (interactive (list (Info-read-node-name "Goto node: ")))
678 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
680 (setq filename (if (= (match-beginning 1) (match-end 1))
682 (substring nodename (match-beginning 2) (match-end 2)))
683 nodename (substring nodename (match-beginning 3) (match-end 3)))
684 (let ((trim (string-match "\\s *\\'" filename)))
685 (if trim (setq filename (substring filename 0 trim))))
686 (let ((trim (string-match "\\s *\\'" nodename)))
687 (if trim (setq nodename (substring nodename 0 trim))))
688 (if transient-mark-mode (deactivate-mark))
689 (Info-find-node (if (equal filename "") nil filename)
690 (if (equal nodename "") "Top" nodename))))
692 ;; This function is used as the "completion table" while reading a node name.
693 ;; It does completion using the alist in completion-table
694 ;; unless STRING starts with an open-paren.
695 (defun Info-read-node-name-1 (string predicate code)
696 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
700 (try-completion string completion-table predicate)))
704 (all-completions string completion-table predicate)))
708 (assoc string completion-table))))))
710 (defun Info-read-node-name (prompt &optional default)
711 (let* ((completion-ignore-case t)
712 (completion-table (Info-build-node-completions))
713 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
714 (if (equal nodename "")
716 (Info-read-node-name prompt))
719 (defun Info-build-node-completions ()
720 (or Info-current-file-completions
724 (if (marker-buffer Info-tag-table-marker)
725 (let ((marker Info-tag-table-marker))
726 (set-buffer (marker-buffer marker))
729 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
731 (cons (list (buffer-substring (match-beginning 1)
735 (goto-char (point-min))
736 (while (search-forward "\n\^_" nil t)
740 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
743 (cons (list (buffer-substring (match-beginning 1)
746 (setq Info-current-file-completions compl))))
748 (defun Info-restore-point (hl)
749 "If this node has been visited, restore the point value when we left."
751 (if (and (equal (nth 0 (car hl)) Info-current-file)
752 ;; Use string-equal, not equal, to ignore text props.
753 (string-equal (nth 1 (car hl)) Info-current-node))
755 (goto-char (nth 2 (car hl)))
756 (setq hl nil)) ;terminate the while at next iter
757 (setq hl (cdr hl)))))
759 (defvar Info-last-search nil
760 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
762 (defun Info-search (regexp)
763 "Search for REGEXP, starting from point, and select node it's found in."
764 (interactive "sSearch (regexp): ")
765 (if transient-mark-mode (deactivate-mark))
766 (if (equal regexp "")
767 (setq regexp Info-last-search)
768 (setq Info-last-search regexp))
769 (let ((found ()) current
770 (onode Info-current-node)
771 (ofile Info-current-file)
773 (ostart (window-start))
774 (osubfile Info-current-subfile))
778 (if (null Info-current-subfile)
779 (progn (re-search-forward regexp) (setq found (point)))
781 (progn (re-search-forward regexp) (setq found (point)))
782 (search-failed nil)))))
783 (if (not found) ;can only happen in subfile case -- else would have erred
787 (set-buffer (marker-buffer Info-tag-table-marker))
788 (goto-char (point-min))
789 (search-forward "\n\^_\nIndirect:")
791 (narrow-to-region (point)
792 (progn (search-forward "\n\^_")
794 (goto-char (point-min))
795 (search-forward (concat "\n" osubfile ": "))
798 (re-search-forward "\\(^.*\\): [0-9]+$")
799 (goto-char (+ (match-end 1) 2))
800 (setq list (cons (cons (read (current-buffer))
802 (match-beginning 1) (match-end 1)))
804 (goto-char (1+ (match-end 0))))
805 (setq list (nreverse list)
806 current (car (car list))
809 (message "Searching subfile %s..." (cdr (car list)))
810 (Info-read-subfile (car (car list)))
811 (setq list (cdr list))
812 ;; (goto-char (point-min))
813 (if (re-search-forward regexp nil t)
814 (setq found (point) list ())))
817 (signal 'search-failed (list regexp))))
819 (progn (Info-read-subfile osubfile)
822 (set-window-start (selected-window) ostart)))))
826 ;; Use string-equal, not equal, to ignore text props.
827 (or (and (string-equal onode Info-current-node)
828 (equal ofile Info-current-file))
829 (setq Info-history (cons (list ofile onode opoint)
832 ;; Extract the value of the node-pointer named NAME.
833 ;; If there is none, use ERRORNAME in the error message;
834 ;; if ERRORNAME is nil, just return nil.
835 (defun Info-extract-pointer (name &optional errorname)
837 (goto-char (point-min))
839 (if (re-search-backward (concat name ":") nil t)
841 (goto-char (match-end 0))
842 (Info-following-node-name))
845 (error "Node has no %s" (capitalize (or errorname name)))))))
847 ;; Return the node name in the buffer following point.
848 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
849 ;; saying which chars may appear in the node name.
850 (defun Info-following-node-name (&optional allowedchars)
851 (skip-chars-forward " \t")
852 (buffer-substring-no-properties
855 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
856 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
858 (skip-chars-forward "^)")))
859 (skip-chars-backward " ")
863 "Go to the next node of this node."
865 (Info-goto-node (Info-extract-pointer "next")))
868 "Go to the previous node of this node."
870 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
873 "Go to the superior node of this node."
875 (Info-goto-node (Info-extract-pointer "up"))
876 (Info-restore-point Info-history))
879 "Go back to the last node visited."
882 (error "This is the first Info node you looked at"))
883 (let (filename nodename opoint)
884 (setq filename (car (car Info-history)))
885 (setq nodename (car (cdr (car Info-history))))
886 (setq opoint (car (cdr (cdr (car Info-history)))))
887 (setq Info-history (cdr Info-history))
888 (Info-find-node filename nodename)
889 (setq Info-history (cdr Info-history))
892 (defun Info-directory ()
893 "Go to the Info directory node."
895 (Info-find-node "dir" "top"))
897 (defun Info-follow-reference (footnotename)
898 "Follow cross reference named NAME to the node it refers to.
899 NAME may be an abbreviation of the reference name."
901 (let ((completion-ignore-case t)
902 completions default alt-default (start-point (point)) str i bol eol)
904 ;; Store end and beginning of line.
910 (goto-char (point-min))
911 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
912 (setq str (buffer-substring
915 ;; See if this one should be the default.
917 (<= (match-beginning 0) start-point)
918 (<= start-point (point))
920 ;; See if this one should be the alternate default.
921 (and (null alt-default)
922 (and (<= bol (match-beginning 0))
924 (setq alt-default t))
926 (while (setq i (string-match "[ \n\t]+" str i))
927 (setq str (concat (substring str 0 i) " "
928 (substring str (match-end 0))))
930 ;; Record as a completion and perhaps as default.
931 (if (eq default t) (setq default str))
932 (if (eq alt-default t) (setq alt-default str))
933 ;; Don't add this string if it's a duplicate.
934 ;; We use a loop instead of "(assoc str completions)" because
935 ;; we want to do a case-insensitive compare.
936 (let ((tail completions)
937 (tem (downcase str)))
939 (not (string-equal tem (downcase (car (car tail))))))
940 (setq tail (cdr tail)))
945 ;; If no good default was found, try an alternate.
947 (setq default alt-default))
948 ;; If only one cross-reference found, then make it default.
949 (if (eq (length completions) 1)
950 (setq default (car (car completions))))
952 (let ((input (completing-read (if default
953 (concat "Follow reference named: ("
955 "Follow reference named: ")
957 (list (if (equal input "")
959 (error "No cross-references in this node"))))
960 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename))))
961 (while (setq i (string-match " " str i))
962 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
965 (goto-char (point-min))
966 (or (re-search-forward str nil t)
967 (error "No cross-reference named %s" footnotename))
968 (goto-char (+ (match-beginning 0) 5))
970 (Info-extract-menu-node-name "Bad format cross reference" t)))
971 (while (setq i (string-match "[ \t\n]+" target i))
972 (setq target (concat (substring target 0 i) " "
973 (substring target (match-end 0))))
975 (Info-goto-node target)))
977 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
978 (skip-chars-forward " \t\n")
981 (skip-chars-forward "^:")
985 (buffer-substring-no-properties beg (1- (point)))
986 (skip-chars-forward " \t\n")
987 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
988 (while (setq i (string-match "\n" str i))
990 ;; Collapse multiple spaces.
991 (while (string-match " +" str)
992 (setq str (replace-match " " t t str)))
995 ;; No one calls this.
996 ;;(defun Info-menu-item-sequence (list)
998 ;; (Info-menu (car list))
999 ;; (setq list (cdr list))))
1001 (defun Info-complete-menu-item (string predicate action)
1002 (let ((case-fold-search t))
1003 (cond ((eq action nil)
1005 (pattern (concat "\n\\* \\("
1006 (regexp-quote string)
1009 (set-buffer Info-complete-menu-buffer)
1010 (goto-char (point-min))
1011 (search-forward "\n* Menu:")
1012 (while (re-search-forward pattern nil t)
1013 (setq completions (cons (cons (format "%s"
1017 (match-beginning 1))
1019 (try-completion string completions predicate)))
1022 (pattern (concat "\n\\* \\("
1023 (regexp-quote string)
1026 (set-buffer Info-complete-menu-buffer)
1027 (goto-char (point-min))
1028 (search-forward "\n* Menu:")
1029 (while (re-search-forward pattern nil t)
1030 (setq completions (cons (cons (format "%s"
1034 (match-beginning 1))
1036 (all-completions string completions predicate)))
1039 (set-buffer Info-complete-menu-buffer)
1040 (goto-char (point-min))
1041 (search-forward "\n* Menu:")
1042 (re-search-forward (concat "\n\\* "
1043 (regexp-quote string)
1048 (defun Info-menu (menu-item)
1049 "Go to node for menu item named (or abbreviated) NAME.
1050 Completion is allowed, and the menu item point is on is the default."
1052 (let ((completions '())
1053 ;; If point is within a menu item, use that item as the default
1059 (goto-char (point-min))
1060 (if (not (search-forward "\n* menu:" nil t))
1061 (error "No menu in this node"))
1067 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t)
1068 (setq default (format "%s" (buffer-substring
1073 (setq item (let ((completion-ignore-case t)
1074 (Info-complete-menu-buffer (current-buffer)))
1075 (completing-read (if default
1076 (format "Menu item (default %s): "
1079 'Info-complete-menu-item nil t)))
1080 ;; we rely on the fact that completing-read accepts an input
1081 ;; of "" even when the require-match argument is true and ""
1082 ;; is not a valid possibility
1083 (if (string= item "")
1089 ;; there is a problem here in that if several menu items have the same
1090 ;; name you can only go to the node of the first with this command.
1091 (Info-goto-node (Info-extract-menu-item menu-item)))
1093 (defun Info-extract-menu-item (menu-item)
1094 (setq menu-item (regexp-quote menu-item))
1096 (goto-char (point-min))
1097 (or (search-forward "\n* menu:" nil t)
1098 (error "No menu in this node"))
1099 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
1100 (re-search-forward (concat "\n\\* " menu-item) nil t)
1101 (error "No such item in menu"))
1104 (Info-extract-menu-node-name)))
1106 ;; If COUNT is nil, use the last item in the menu.
1107 (defun Info-extract-menu-counting (count)
1109 (goto-char (point-min))
1110 (or (search-forward "\n* menu:" nil t)
1111 (error "No menu in this node"))
1113 (or (search-forward "\n* " nil t count)
1114 (error "Too few items in menu"))
1115 (while (search-forward "\n* " nil t)
1117 (Info-extract-menu-node-name)))
1119 (defun Info-nth-menu-item ()
1120 "Go to the node of the Nth menu item.
1121 N is the digit argument used to invoke this command."
1124 (Info-extract-menu-counting
1125 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1127 (defun Info-top-node ()
1128 "Go to the Top node of this file."
1130 (Info-goto-node "Top"))
1132 (defun Info-final-node ()
1133 "Go to the final node in this file."
1135 (Info-goto-node "Top")
1137 ;; Go to the last node in the menu of Top.
1138 (Info-goto-node (Info-extract-menu-counting nil))
1139 ;; If the last node in the menu is not last in pointer structure,
1140 ;; move forward until we can't go any farther.
1141 (while (Info-forward-node t t) nil)
1142 ;; Then keep moving down to last subnode, unless we reach an index.
1143 (while (and (not (string-match "\\<index\\>" Info-current-node))
1144 (save-excursion (search-forward "\n* Menu:" nil t)))
1145 (Info-goto-node (Info-extract-menu-counting nil)))))
1147 (defun Info-forward-node (&optional not-down no-error)
1148 "Go forward one node, considering all nodes as forming one sequence."
1150 (goto-char (point-min))
1152 ;; three possibilities, in order of priority:
1153 ;; 1. next node is in a menu in this node (but not in an index)
1154 ;; 2. next node is next at same level
1155 ;; 3. next node is up and next
1156 (cond ((and (not not-down)
1157 (save-excursion (search-forward "\n* menu:" nil t))
1158 (not (string-match "\\<index\\>" Info-current-node)))
1159 (Info-goto-node (Info-extract-menu-counting 1))
1161 ((save-excursion (search-backward "next:" nil t))
1164 ((and (save-excursion (search-backward "up:" nil t))
1165 ;; Use string-equal, not equal, to ignore text props.
1166 (not (string-equal (downcase (Info-extract-pointer "up"))
1168 (let ((old-node Info-current-node))
1170 (let (Info-history success)
1172 (setq success (Info-forward-node t no-error))
1173 (or success (Info-goto-node old-node))))))
1175 (t (error "No pointer forward from this node"))))
1177 (defun Info-backward-node ()
1178 "Go backward one node, considering all nodes as forming one sequence."
1180 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1181 (upnode (Info-extract-pointer "up" t)))
1182 (cond ((and upnode (string-match "(" upnode))
1183 (error "First node in file"))
1184 ((and upnode (or (null prevnode)
1185 ;; Use string-equal, not equal,
1186 ;; to ignore text properties.
1187 (string-equal (downcase prevnode)
1188 (downcase upnode))))
1191 ;; If we move back at the same level,
1192 ;; go down to find the last subnode*.
1195 (while (and (not (string-match "\\<index\\>" Info-current-node))
1196 (save-excursion (search-forward "\n* Menu:" nil t)))
1197 (Info-goto-node (Info-extract-menu-counting nil)))))
1199 (error "No pointer backward from this node")))))
1202 "Exit Info by selecting some other buffer."
1205 (save-buffers-kill-emacs)
1206 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1207 (bury-buffer (current-buffer))))))
1209 (defun Info-next-menu-item ()
1213 (search-forward "\n* menu:" nil t)
1214 (or (search-forward "\n* " nil t)
1215 (error "No more items in menu"))
1216 (Info-goto-node (Info-extract-menu-node-name))))
1218 (defun Info-last-menu-item ()
1222 (let ((beg (save-excursion
1223 (and (search-backward "\n* menu:" nil t)
1225 (or (and beg (search-backward "\n* " beg t))
1226 (error "No previous items in menu")))
1227 (Info-goto-node (save-excursion
1228 (goto-char (match-end 0))
1229 (Info-extract-menu-node-name)))))
1231 (defmacro Info-no-error (&rest body)
1232 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1234 (defun Info-next-preorder ()
1235 "Go to the next subnode or the next node, or go up a level."
1237 (cond ((Info-no-error (Info-next-menu-item)))
1238 ((Info-no-error (Info-next)))
1239 ((Info-no-error (Info-up))
1240 ;; Since we have already gone thru all the items in this menu,
1241 ;; go up to the end of this node.
1242 (goto-char (point-max))
1243 ;; Since logically we are done with the node with that menu,
1245 (Info-next-preorder))
1247 (error "No more nodes"))))
1249 (defun Info-last-preorder ()
1250 "Go to the last node, popping up a level if there is none."
1252 (cond ((Info-no-error
1253 (Info-last-menu-item)
1254 ;; If we go down a menu item, go to the end of the node
1255 ;; so we can scroll back through it.
1256 (goto-char (point-max)))
1257 ;; Keep going down, as long as there are nested menu nodes.
1258 (while (Info-no-error
1259 (Info-last-menu-item)
1260 ;; If we go down a menu item, go to the end of the node
1261 ;; so we can scroll back through it.
1262 (goto-char (point-max))))
1264 ((Info-no-error (Info-prev))
1265 (goto-char (point-max))
1266 (while (Info-no-error
1267 (Info-last-menu-item)
1268 ;; If we go down a menu item, go to the end of the node
1269 ;; so we can scroll back through it.
1270 (goto-char (point-max))))
1272 ((Info-no-error (Info-up))
1273 (goto-char (point-min))
1274 (or (search-forward "\n* Menu:" nil t)
1275 (goto-char (point-max))))
1276 (t (error "No previous nodes"))))
1278 (defun Info-scroll-up ()
1279 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1280 Once you scroll far enough in a node that its menu appears on the screen
1281 but after point, the next scroll moves into its first subnode.
1283 When you scroll past the end of a node, that goes to the next node; if
1284 this node has no successor, it moves to the parent node's successor,
1285 and so on. If point is inside the menu of a node, it moves to
1286 subnode indicated by the following menu item. (That case won't
1287 normally result from this command, but can happen in other ways.)"
1290 (if (or (< (window-start) (point-min))
1291 (> (window-start) (point-max)))
1292 (set-window-start (selected-window) (point)))
1293 (let ((virtual-end (save-excursion
1294 (goto-char (point-min))
1295 (if (search-forward "\n* Menu:" nil t)
1298 (if (or (< virtual-end (window-start))
1299 (pos-visible-in-window-p virtual-end))
1300 (Info-next-preorder)
1303 (defun Info-scroll-down ()
1304 "Scroll one screenful back in Info, considering all nodes as one sequence.
1305 Within the menu of a node, this goes to its last subnode.
1306 When you scroll past the beginning of a node, that goes to the
1307 previous node or back up to the parent node."
1309 (if (or (< (window-start) (point-min))
1310 (> (window-start) (point-max)))
1311 (set-window-start (selected-window) (point)))
1312 (let* ((current-point (point))
1313 (virtual-end (save-excursion
1315 (setq current-point (point))
1316 (goto-char (point-min))
1317 (search-forward "\n* Menu:"
1320 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1321 (Info-last-preorder)
1324 (defun Info-next-reference (&optional recur)
1325 "Move cursor to the next cross-reference or menu item in the node."
1327 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1329 (or (eobp) (forward-char 1))
1330 (or (re-search-forward pat nil t)
1332 (goto-char (point-min))
1333 (or (re-search-forward pat nil t)
1336 (error "No cross references in this node")))))
1337 (goto-char (match-beginning 0))
1338 (if (looking-at "\\* Menu:")
1340 (error "No cross references in this node")
1341 (Info-next-reference t)))))
1343 (defun Info-prev-reference (&optional recur)
1344 "Move cursor to the previous cross-reference or menu item in the node."
1346 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1348 (or (re-search-backward pat nil t)
1350 (goto-char (point-max))
1351 (or (re-search-backward pat nil t)
1354 (error "No cross references in this node")))))
1355 (goto-char (match-beginning 0))
1356 (if (looking-at "\\* Menu:")
1358 (error "No cross references in this node")
1359 (Info-prev-reference t)))))
1361 (defun Info-index (topic)
1362 "Look up a string in the index for this file.
1363 The index is defined as the first node in the top-level menu whose
1364 name contains the word \"Index\", plus any immediately following
1365 nodes whose names also contain the word \"Index\".
1366 If there are no exact matches to the specified topic, this chooses
1367 the first match which is a case-insensitive substring of a topic.
1368 Use the `,' command to see the other matches.
1369 Give a blank topic name to go to the Index node itself."
1370 (interactive "sIndex topic: ")
1371 (let ((orignode Info-current-node)
1373 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1374 (regexp-quote topic)))
1376 (Info-goto-node "Top")
1377 (or (search-forward "\n* menu:" nil t)
1379 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1381 (goto-char (match-beginning 1))
1382 ;; Here, and subsequently in this function,
1383 ;; we bind Info-history to nil for internal node-switches
1384 ;; so that we don't put junk in the history.
1385 ;; In the first Info-goto-node call, above, we do update the history
1386 ;; because that is what the user's previous node choice into it.
1387 (let ((Info-history nil))
1388 (Info-goto-node (Info-extract-menu-node-name)))
1389 (or (equal topic "")
1396 (goto-char (point-min))
1397 (while (re-search-forward pattern nil t)
1399 (cons (list (buffer-substring (match-beginning 1)
1401 (buffer-substring (match-beginning 2)
1404 (string-to-int (concat "0"
1409 (and (setq node (Info-extract-pointer "next" t))
1410 (string-match "\\<Index\\>" node)))
1411 (Info-goto-node node))
1414 (Info-goto-node orignode)
1415 (error "No `%s' in index" topic)))
1416 ;; Here it is a feature that assoc is case-sensitive.
1417 (while (setq found (assoc topic matches))
1418 (setq exact (cons found exact)
1419 matches (delq found matches)))
1420 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1421 (Info-index-next 0)))))
1423 (defun Info-index-next (num)
1424 "Go to the next matching index item from the last `i' command."
1426 (or Info-index-alternatives
1427 (error "No previous `i' command"))
1429 (setq num (+ num (length Info-index-alternatives))))
1431 (setq Info-index-alternatives
1432 (nconc (cdr Info-index-alternatives)
1433 (list (car Info-index-alternatives)))
1435 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1436 (if (> (nth 3 (car Info-index-alternatives)) 0)
1437 (forward-line (nth 3 (car Info-index-alternatives)))
1438 (forward-line 3) ; don't search in headers
1439 (let ((name (car (car Info-index-alternatives))))
1440 (Info-find-index-name name)))
1441 (message "Found `%s' in %s. %s"
1442 (car (car Info-index-alternatives))
1443 (nth 2 (car Info-index-alternatives))
1444 (if (cdr Info-index-alternatives)
1445 "(Press `,' for more)"
1448 (defun Info-find-index-name (name)
1449 "Move point to the place within the current node where NAME is defined."
1450 (if (or (re-search-forward (format
1451 "[a-zA-Z]+: %s\\( \\|$\\)"
1452 (regexp-quote name)) nil t)
1453 (search-forward (format "`%s'" name) nil t)
1454 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1456 (format "`%s'" (substring name 0 (match-beginning 1)))
1458 (search-forward name nil t))
1460 (goto-char (point-min))))
1462 (defun Info-undefined ()
1463 "Make command be undefined in Info."
1468 "Enter the Info tutorial."
1470 (delete-other-windows)
1471 (Info-find-node "info"
1472 (if (< (window-height) 23)
1476 (defun Info-summary ()
1477 "Display a brief summary of all Info commands."
1479 (save-window-excursion
1480 (switch-to-buffer "*Help*")
1482 (insert (documentation 'Info-mode))
1484 (goto-char (point-min))
1486 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1487 (message (if flag "Type Space to see more"
1488 "Type Space to return to Info"))
1489 (if (not (eq ?\ (setq ch (read-event))))
1490 (progn (setq unread-command-events (list ch)) nil)
1493 (bury-buffer "*Help*")))
1495 (defun Info-get-token (pos start all &optional errorstring)
1496 "Return the token around POS,
1497 POS must be somewhere inside the token
1498 START is a regular expression which will match the
1499 beginning of the tokens delimited string
1500 ALL is a regular expression with a single
1501 parenthesized subpattern which is the token to be
1502 returned. E.g. '{\(.*\)}' would return any string
1503 enclosed in braces around POS.
1504 SIG optional fourth argument, controls action on no match
1507 a string: signal an error, using that string."
1510 ;; First look for a match for START that goes across POS.
1511 (while (and (not (bobp)) (> (point) (- pos (length start)))
1512 (not (looking-at start)))
1514 ;; If we did not find one, search back for START
1515 ;; (this finds only matches that end at or before POS).
1516 (or (looking-at start)
1519 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1521 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1522 (not (setq found (and (<= (match-beginning 0) pos)
1523 (> (match-end 0) pos))))))
1524 (if (and found (<= (match-beginning 0) pos)
1525 (> (match-end 0) pos))
1526 (buffer-substring (match-beginning 1) (match-end 1))
1527 (cond ((null errorstring)
1533 (error "No %s around position %d" errorstring pos)))))))
1535 (defun Info-mouse-follow-nearest-node (click)
1536 "\\<Info-mode-map>Follow a node reference near point.
1537 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1538 At end of the node's text, moves to the next node, or up if none."
1540 (let* ((start (event-start click))
1541 (window (car start))
1542 (pos (car (cdr start))))
1543 (select-window window)
1545 (and (not (Info-try-follow-nearest-node))
1546 (save-excursion (forward-line 1) (eobp))
1547 (Info-next-preorder)))
1549 (defun Info-follow-nearest-node ()
1550 "\\<Info-mode-map>Follow a node reference near point.
1551 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1552 If no reference to follow, moves to the next node, or up if none."
1554 (or (Info-try-follow-nearest-node)
1555 (Info-next-preorder)))
1557 ;; Common subroutine.
1558 (defun Info-try-follow-nearest-node ()
1559 "Follow a node reference near point. Return non-nil if successful."
1562 ((setq node (Info-get-token (point) "\\*note[ \n]"
1563 "\\*note[ \n]\\([^:]*\\):"))
1564 (Info-follow-reference node))
1565 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1566 (Info-goto-node node))
1567 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1569 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1570 (Info-goto-node node))
1571 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1572 (Info-goto-node node))
1573 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1574 (Info-goto-node "Top"))
1575 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1576 (Info-goto-node node)))
1579 (defvar Info-mode-map nil
1580 "Keymap containing Info commands.")
1583 (setq Info-mode-map (make-keymap))
1584 (suppress-keymap Info-mode-map)
1585 (define-key Info-mode-map "." 'beginning-of-buffer)
1586 (define-key Info-mode-map " " 'Info-scroll-up)
1587 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1588 (define-key Info-mode-map "\t" 'Info-next-reference)
1589 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1590 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1591 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1592 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1593 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1594 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1595 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1596 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1597 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1598 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1599 (define-key Info-mode-map "0" 'undefined)
1600 (define-key Info-mode-map "?" 'Info-summary)
1601 (define-key Info-mode-map "]" 'Info-forward-node)
1602 (define-key Info-mode-map "[" 'Info-backward-node)
1603 (define-key Info-mode-map "<" 'Info-top-node)
1604 (define-key Info-mode-map ">" 'Info-final-node)
1605 (define-key Info-mode-map "b" 'beginning-of-buffer)
1606 (define-key Info-mode-map "d" 'Info-directory)
1607 (define-key Info-mode-map "e" 'Info-edit)
1608 (define-key Info-mode-map "f" 'Info-follow-reference)
1609 (define-key Info-mode-map "g" 'Info-goto-node)
1610 (define-key Info-mode-map "h" 'Info-help)
1611 (define-key Info-mode-map "i" 'Info-index)
1612 (define-key Info-mode-map "l" 'Info-last)
1613 (define-key Info-mode-map "m" 'Info-menu)
1614 (define-key Info-mode-map "n" 'Info-next)
1615 (define-key Info-mode-map "p" 'Info-prev)
1616 (define-key Info-mode-map "q" 'Info-exit)
1617 (define-key Info-mode-map "s" 'Info-search)
1618 ;; For consistency with Rmail.
1619 (define-key Info-mode-map "\M-s" 'Info-search)
1620 (define-key Info-mode-map "t" 'Info-top-node)
1621 (define-key Info-mode-map "u" 'Info-up)
1622 (define-key Info-mode-map "," 'Info-index-next)
1623 (define-key Info-mode-map "\177" 'Info-scroll-down)
1624 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1627 (defun Info-check-pointer (item)
1628 ;; Non-nil if ITEM is present in this node.
1630 (Info-extract-pointer item)
1633 (easy-menu-define Info-mode-menu Info-mode-map
1634 "Menu for info files."
1636 ["Up" Info-up (Info-check-pointer "up")]
1637 ["Next" Info-next (Info-check-pointer "next")]
1638 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1639 ("Menu item" ["You should never see this" report-emacs-bug t])
1640 ("Reference" ["You should never see this" report-emacs-bug t])
1641 ["Search..." Info-search t]
1642 ["Goto node..." Info-goto-node t]
1643 ["Last" Info-last Info-history]
1644 ["Exit" Info-exit t]))
1646 (defvar Info-menu-last-node nil)
1647 ;; Last node the menu was created for.
1649 (defun Info-menu-update ()
1650 ;; Update the Info menu for the current node.
1652 (if (or (not (eq major-mode 'Info-mode))
1653 (eq Info-current-node Info-menu-last-node))
1655 ;; Update menu menu.
1656 (let* ((Info-complete-menu-buffer (current-buffer))
1657 (items (nreverse (condition-case nil
1658 (Info-complete-menu-item
1659 "" (lambda (e) t) t)
1663 (while (and items (< number 9))
1664 (setq current (car items)
1667 (setq entries (cons `[,current
1668 (Info-menu ,current)
1669 :keys ,(format "%d" number)]
1672 (setq entries (cons ["Other..." Info-menu t] entries)))
1674 (setq entries (list ["No menu" nil nil])))
1675 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1676 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1678 str i entries current
1681 (goto-char (point-min))
1682 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1683 (setq str (buffer-substring
1687 (while (setq i (string-match "[ \n\t]+" str i))
1688 (setq str (concat (substring str 0 i) " "
1689 (substring str (match-end 0))))
1693 (while (and items (< number 9))
1694 (setq current (car items)
1697 (setq entries (cons `[,current
1698 (Info-follow-reference ,current)
1702 (setq entries (cons ["Other..." Info-follow-reference t]
1705 (setq entries (list ["No references" nil nil])))
1706 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1707 ;; Update last seen node.
1708 (setq Info-menu-last-node (current-buffer)))
1709 ;; Try to avoid entering infinite beep mode in case of errors.
1713 ;; Info mode is suitable only for specially formatted data.
1714 (put 'info-mode 'mode-class 'special)
1718 Info mode provides commands for browsing through the Info documentation tree.
1719 Documentation in Info is divided into \"nodes\", each of which discusses
1720 one topic and contains references to other nodes which discuss related
1721 topics. Info has commands to follow the references and show you other nodes.
1723 \\[Info-help] Invoke the Info tutorial.
1725 Selecting other nodes:
1726 \\[Info-mouse-follow-nearest-node]
1727 Follow a node reference you click on.
1728 This works with menu items, cross references, and
1729 the \"next\", \"previous\" and \"up\", depending on where you click.
1730 \\[Info-next] Move to the \"next\" node of this node.
1731 \\[Info-prev] Move to the \"previous\" node of this node.
1732 \\[Info-up] Move \"up\" from this node.
1733 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1734 Picking a menu item causes another node to be selected.
1735 \\[Info-directory] Go to the Info directory node.
1736 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1737 \\[Info-last] Move to the last node you were at.
1738 \\[Info-index] Look up a topic in this file's Index and move to that node.
1739 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1741 Moving within a node:
1742 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1743 already visible, try to go to the next menu entry, or up if there is none.
1744 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1745 already visible, try to go to the previous menu entry, or up if there is none.
1746 \\[beginning-of-buffer] Go to beginning of node.
1749 \\[Info-exit] Quit Info: reselect previously selected buffer.
1750 \\[Info-edit] Edit contents of selected node.
1751 1 Pick first item in node's menu.
1752 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1753 \\[Info-goto-node] Move to node specified by name.
1754 You may include a filename as well, as (FILENAME)NODENAME.
1755 \\[universal-argument] \\[info] Move to new Info file with completion.
1756 \\[Info-search] Search through this Info file for specified regexp,
1757 and select the node in which the next occurrence is found.
1758 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1759 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1760 (kill-all-local-variables)
1761 (setq major-mode 'Info-mode)
1762 (setq mode-name "Info")
1764 (use-local-map Info-mode-map)
1765 (make-local-hook 'activate-menubar-hook)
1766 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1767 (set-syntax-table text-mode-syntax-table)
1768 (setq local-abbrev-table text-mode-abbrev-table)
1769 (setq case-fold-search t)
1770 (setq buffer-read-only t)
1771 (make-local-variable 'Info-current-file)
1772 (make-local-variable 'Info-current-subfile)
1773 (make-local-variable 'Info-current-node)
1774 (make-local-variable 'Info-tag-table-marker)
1775 (setq Info-tag-table-marker (make-marker))
1776 (make-local-variable 'Info-tag-table-buffer)
1777 (setq Info-tag-table-buffer nil)
1778 (make-local-variable 'Info-history)
1779 (make-local-variable 'Info-index-alternatives)
1780 (if (memq (framep (selected-frame)) '(x pc w32))
1782 (make-face 'info-node)
1783 (make-face 'info-menu-5)
1784 (make-face 'info-xref)
1785 (or (face-differs-from-default-p 'info-node)
1786 (if (face-differs-from-default-p 'bold-italic)
1787 (copy-face 'bold-italic 'info-node)
1788 (copy-face 'bold 'info-node)))
1789 (or (face-differs-from-default-p 'info-menu-5)
1790 (set-face-underline-p 'info-menu-5 t))
1791 (or (face-differs-from-default-p 'info-xref)
1792 (copy-face 'bold 'info-xref)))
1793 (setq Info-fontify nil))
1794 (Info-set-mode-line)
1795 (run-hooks 'Info-mode-hook))
1797 (defvar Info-edit-map nil
1798 "Local keymap used within `e' command of Info.")
1801 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1802 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1804 ;; Info-edit mode is suitable only for specially formatted data.
1805 (put 'info-edit-mode 'mode-class 'special)
1807 (defun Info-edit-mode ()
1808 "Major mode for editing the contents of an Info node.
1809 Like text mode with the addition of `Info-cease-edit'
1810 which returns to Info mode for browsing.
1812 (use-local-map Info-edit-map)
1813 (setq major-mode 'Info-edit-mode)
1814 (setq mode-name "Info Edit")
1815 (kill-local-variable 'mode-line-buffer-identification)
1816 (setq buffer-read-only nil)
1817 (force-mode-line-update)
1818 (buffer-enable-undo (current-buffer))
1819 (run-hooks 'Info-edit-mode-hook))
1822 "Edit the contents of this Info node.
1823 Allowed only if variable `Info-enable-edit' is non-nil."
1825 (or Info-enable-edit
1826 (error "Editing info nodes is not enabled"))
1828 (message "%s" (substitute-command-keys
1829 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1831 (defun Info-cease-edit ()
1832 "Finish editing Info node; switch back to Info proper."
1834 ;; Do this first, so nothing has changed if user C-g's at query.
1835 (and (buffer-modified-p)
1836 (y-or-n-p "Save the file? ")
1838 (use-local-map Info-mode-map)
1839 (setq major-mode 'Info-mode)
1840 (setq mode-name "Info")
1841 (Info-set-mode-line)
1842 (setq buffer-read-only t)
1843 (force-mode-line-update)
1844 (and (marker-position Info-tag-table-marker)
1846 (message "Tags may have changed. Use Info-tagify if necessary")))
1848 (defvar Info-file-list-for-emacs
1849 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1850 "List of Info files that describe Emacs commands.
1851 An element can be a file name, or a list of the form (PREFIX . FILE)
1852 where PREFIX is a name prefix and FILE is the file to look in.
1853 If the element is just a file name, the file name also serves as the prefix.")
1855 (defun Info-find-emacs-command-nodes (command)
1856 "Return a list of locations documenting COMMAND.
1857 The `info-file' property of COMMAND says which Info manual to search.
1858 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1859 defines heuristics for which Info manual to try.
1860 The locations are of the format used in Info-history, i.e.
1861 \(FILENAME NODENAME BUFFERPOS\)."
1863 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1864 ":\\s *\\(.*\\)\\.$"))
1865 (info-file "emacs")) ;default
1866 ;; Determine which info file this command is documented in.
1867 (if (get command 'info-file)
1868 (setq info-file (get command 'info-file))
1869 ;; If it doesn't say explicitly, test its name against
1870 ;; various prefixes that we know.
1871 (let ((file-list Info-file-list-for-emacs))
1873 (let* ((elt (car file-list))
1874 (name (if (consp elt)
1877 (file (if (consp elt) (cdr elt) elt))
1878 (regexp (concat "\\`" (regexp-quote name)
1880 (if (string-match regexp (symbol-name command))
1881 (setq info-file file file-list nil))
1882 (setq file-list (cdr file-list))))))
1885 (Info-find-node info-file "Command Index")
1886 ;; Some manuals may not have a separate Command Index node,
1887 ;; so try just Index instead.
1889 (Info-find-node info-file "Index")))
1890 ;; Take the index node off the Info history.
1891 (setq Info-history (cdr Info-history))
1892 (goto-char (point-max))
1893 (while (re-search-backward cmd-desc nil t)
1894 (setq where (cons (list Info-current-file
1903 (defun Info-goto-emacs-command-node (command)
1904 "Go to the Info node in the Emacs manual for command COMMAND.
1905 The command is found by looking up in Emacs manual's Command Index
1906 or in another manual found via COMMAND's `info-file' property or
1907 the variable `Info-file-list-for-emacs'."
1908 (interactive "CFind documentation for command: ")
1909 (or (commandp command)
1910 (signal 'wrong-type-argument (list 'commandp command)))
1911 (let ((where (Info-find-emacs-command-nodes command)))
1913 (let ((num-matches (length where)))
1914 ;; Get Info running, and pop to it in another window.
1915 (save-window-excursion
1917 ;; FIXME It would be cool if this could use a buffer other
1919 (pop-to-buffer "*info*")
1920 (Info-find-node (car (car where))
1921 (car (cdr (car where))))
1922 (if (> num-matches 1)
1924 ;; Info-find-node already pushed (car where) onto
1925 ;; Info-history. Put the other nodes that were found on
1927 (setq Info-history (nconc (cdr where) Info-history))
1928 (message "Found %d other entr%s. Use %s to see %s."
1930 (if (> num-matches 2) "ies" "y")
1931 (substitute-command-keys "\\[Info-last]")
1932 (if (> num-matches 2) "them" "it")))))
1933 (error "Couldn't find documentation for %s" command))))
1936 (defun Info-goto-emacs-key-command-node (key)
1937 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1938 Interactively, if the binding is execute-extended-command, a command is read.
1939 The command is found by looking up in Emacs manual's Command Index
1940 or in another manual found via COMMAND's `info-file' property or
1941 the variable `Info-file-list-for-emacs'."
1942 (interactive "kFind documentation for key:")
1943 (let ((command (key-binding key)))
1944 (cond ((null command)
1945 (message "%s is undefined" (key-description key)))
1946 ((and (interactive-p)
1947 (eq command 'execute-extended-command))
1948 (Info-goto-emacs-command-node
1949 (read-command "Find documentation for command: ")))
1951 (Info-goto-emacs-command-node command)))))
1953 (defcustom Info-title-face-alist
1954 '((?* bold underline)
1955 (?= bold-italic underline)
1956 (?- italic underline))
1957 "*Alist of face or list of faces to use for pseudo-underlined titles.
1958 The alist key is the character the title is underlined with (?*, ?= or ?-)."
1959 :type '(repeat (list character face face))
1962 (defun Info-fontify-node ()
1964 (let ((buffer-read-only nil))
1965 (goto-char (point-min))
1966 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1968 (goto-char (match-end 0))
1970 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1971 (goto-char (match-end 0))
1972 (put-text-property (match-beginning 1) (match-end 1)
1974 (put-text-property (match-beginning 1) (match-end 1)
1975 'mouse-face 'highlight))))
1976 (goto-char (point-min))
1977 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
1979 (put-text-property (match-beginning 1) (match-end 1)
1981 (cdr (assq (preceding-char) Info-title-face-alist)))
1982 (put-text-property (match-end 1) (match-end 2)
1984 (goto-char (point-min))
1985 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
1986 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1988 (put-text-property (match-beginning 1) (match-end 1)
1990 (put-text-property (match-beginning 1) (match-end 1)
1991 'mouse-face 'highlight)))
1992 (goto-char (point-min))
1993 (if (and (search-forward "\n* Menu:" nil t)
1994 (not (string-match "\\<Index\\>" Info-current-node))
1995 ;; Don't take time to annotate huge menus
1996 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
1998 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
2000 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2001 (put-text-property (match-beginning 0)
2002 (1+ (match-beginning 0))
2003 'face 'info-menu-5))
2004 (put-text-property (match-beginning 1) (match-end 1)
2006 (put-text-property (match-beginning 1) (match-end 1)
2007 'mouse-face 'highlight))))
2008 (set-buffer-modified-p nil))))
2011 ;; When an Info buffer is killed, make sure the associated tags buffer
2013 (defun Info-kill-buffer ()
2014 (and (eq major-mode 'Info-mode)
2015 Info-tag-table-buffer
2016 (kill-buffer Info-tag-table-buffer)))
2018 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2023 ;;; info.el ends here