(copy-tree): Use let* to bind new before i.
[emacs.git] / lisp / info.el
blob8176ce6934d146ceb893493cebda8ec396207343
1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: help
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)
13 ;; any later version.
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.
24 ;;; Commentary:
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
28 ;;; Code:
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
48 in paths.el.")
50 (defvar Info-directory-list
51 (let ((path (getenv "INFOPATH")))
52 (if path
53 (let ((list nil)
54 idx)
55 (while (> (length path) 0)
56 (setq idx (or (string-match ":" path) (length path))
57 list (cons (substring path 0 idx) list)
58 path (substring path (min (1+ idx)
59 (length path)))))
60 (nreverse list))
61 Info-default-directory-list))
62 "List of directories to search for Info documentation files.
63 nil means not yet initialized. In this case, Info uses the environment
64 variable INFOPATH to initialize it, or `Info-default-directory-list'
65 if there is no INFOPATH variable in the environment.")
67 (defvar Info-current-file nil
68 "Info file that Info is now looking at, or nil.")
70 (defvar Info-current-subfile nil
71 "Info subfile that is actually in the *info* buffer now,
72 or nil if current info file is not split into subfiles.")
74 (defvar Info-current-node nil
75 "Name of node that Info is now looking at, or nil.")
77 (defvar Info-tag-table-marker (make-marker)
78 "Marker pointing at beginning of current Info file's tag table.
79 Marker points nowhere if file has no tag table.")
81 (defvar Info-index-alternatives nil
82 "List of possible matches for last Info-index command.")
84 (defvar Info-suffix-list '( ("" . nil)
85 (".info" . nil)
86 (".Z" . "uncompress")
87 (".Y" . "unyabba")
88 (".z" . "gunzip")
89 (".info.Z" . "uncompress")
90 (".info.Y" . "unyabba")
91 (".info.z" . "gunzip"))
92 "List of file name suffixes and associated decoding commands.
93 Each entry should be (SUFFIX . STRING); the file is given to
94 the command as standard input. If STRING is nil, no decoding is done.")
96 (defun info-insert-file-contents (filename &optional visit)
97 "Insert the contents of an info file in the current buffer.
98 Do the right thing if the file has been compressed or zipped."
99 (if (null (catch 'ok
100 (mapcar
101 (function
102 (lambda (x)
103 (let ((compressed (concat filename (car x))))
104 (if (file-exists-p compressed)
105 (progn
106 (insert-file-contents compressed visit)
107 (if (cdr x)
108 (let ((buffer-read-only nil))
109 (shell-command-on-region
110 (point-min) (point-max) (cdr x) t)))
111 (throw 'ok t))))))
112 Info-suffix-list)
113 nil))
114 (error "Can't find %s or any compressed version of it!" filename)))
116 ;;;###autoload
117 (defun info (&optional file)
118 "Enter Info, the documentation browser.
119 Optional argument FILE specifies the file to examine;
120 the default is the top-level directory of Info.
122 In interactive use, a prefix argument directs this command
123 to read a file name from the minibuffer."
124 (interactive (if current-prefix-arg
125 (list (read-file-name "Info file name: " nil nil t))))
126 (if file
127 (Info-goto-node (concat "(" file ")"))
128 (if (get-buffer "*info*")
129 (switch-to-buffer "*info*")
130 (Info-directory))))
132 ;; Go to an info node specified as separate filename and nodename.
133 ;; no-going-back is non-nil if recovering from an error in this function;
134 ;; it says do not attempt further (recursive) error recovery.
135 (defun Info-find-node (filename nodename &optional no-going-back)
136 ;; Convert filename to lower case if not found as specified.
137 ;; Expand it.
138 (if filename
139 (let (temp temp-downcase found)
140 (setq filename (substitute-in-file-name filename))
141 (if (string= (downcase (file-name-nondirectory filename)) "dir")
142 (setq found t)
143 (let ((dirs (if (string-match "^\\./" filename)
144 ;; If specified name starts with `./'
145 ;; then just try current directory.
146 '("./")
147 Info-directory-list)))
148 ;; Search the directory list for file FILENAME.
149 (while (and dirs (not found))
150 (setq temp (expand-file-name filename (car dirs)))
151 (setq temp-downcase
152 (expand-file-name (downcase filename) (car dirs)))
153 ;; Try several variants of specified name.
154 (catch 'foundit
155 (mapcar
156 (function
157 (lambda (x)
158 (if (file-exists-p (concat temp (car x)))
159 (progn
160 (setq found temp)
161 (throw 'foundit nil)))
162 (if (file-exists-p (concat temp-downcase (car x)))
163 (progn
164 (setq found temp-downcase)
165 (throw 'foundit nil)))))
166 Info-suffix-list))
167 (setq dirs (cdr dirs)))))
168 (if found
169 (setq filename found)
170 (error "Info file %s does not exist" filename))))
171 ;; Record the node we are leaving.
172 (if (and Info-current-file (not no-going-back))
173 (setq Info-history
174 (cons (list Info-current-file Info-current-node (point))
175 Info-history)))
176 ;; Go into info buffer.
177 (switch-to-buffer "*info*")
178 (buffer-disable-undo (current-buffer))
179 (or (eq major-mode 'Info-mode)
180 (Info-mode))
181 (widen)
182 (setq Info-current-node nil)
183 (unwind-protect
184 (progn
185 ;; Switch files if necessary
186 (or (null filename)
187 (equal Info-current-file filename)
188 (let ((buffer-read-only nil))
189 (setq Info-current-file nil
190 Info-current-subfile nil
191 Info-index-alternatives nil
192 buffer-file-name nil)
193 (erase-buffer)
194 (if (eq filename t)
195 (Info-insert-dir)
196 (info-insert-file-contents filename t)
197 (setq default-directory (file-name-directory filename)))
198 (set-buffer-modified-p nil)
199 ;; See whether file has a tag table. Record the location if yes.
200 (set-marker Info-tag-table-marker nil)
201 (goto-char (point-max))
202 (forward-line -8)
203 (or (equal nodename "*")
204 (not (search-forward "\^_\nEnd tag table\n" nil t))
205 (let (pos)
206 ;; We have a tag table. Find its beginning.
207 ;; Is this an indirect file?
208 (search-backward "\nTag table:\n")
209 (setq pos (point))
210 (if (save-excursion
211 (forward-line 2)
212 (looking-at "(Indirect)\n"))
213 ;; It is indirect. Copy it to another buffer
214 ;; and record that the tag table is in that buffer.
215 (save-excursion
216 (let ((buf (current-buffer)))
217 (set-buffer (get-buffer-create " *info tag table*"))
218 (buffer-disable-undo (current-buffer))
219 (setq case-fold-search t)
220 (erase-buffer)
221 (insert-buffer-substring buf)
222 (set-marker Info-tag-table-marker
223 (match-end 0))))
224 (set-marker Info-tag-table-marker pos))))
225 (setq Info-current-file
226 (if (eq filename t) "dir"
227 (file-name-sans-versions buffer-file-name)))))
228 (if (equal nodename "*")
229 (progn (setq Info-current-node nodename)
230 (Info-set-mode-line))
231 ;; Search file for a suitable node.
232 (let ((guesspos (point-min))
233 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
234 ;; First get advice from tag table if file has one.
235 ;; Also, if this is an indirect info file,
236 ;; read the proper subfile into this buffer.
237 (if (marker-position Info-tag-table-marker)
238 (save-excursion
239 (set-buffer (marker-buffer Info-tag-table-marker))
240 (goto-char Info-tag-table-marker)
241 (if (re-search-forward regexp nil t)
242 (progn
243 (setq guesspos (read (current-buffer)))
244 ;; If this is an indirect file,
245 ;; determine which file really holds this node
246 ;; and read it in.
247 (if (not (eq (current-buffer) (get-buffer "*info*")))
248 (setq guesspos
249 (Info-read-subfile guesspos))))
250 (error "No such node: \"%s\"" nodename))))
251 (goto-char (max (point-min) (- guesspos 1000)))
252 ;; Now search from our advised position (or from beg of buffer)
253 ;; to find the actual node.
254 (catch 'foo
255 (while (search-forward "\n\^_" nil t)
256 (forward-line 1)
257 (let ((beg (point)))
258 (forward-line 1)
259 (if (re-search-backward regexp beg t)
260 (throw 'foo t))))
261 (error "No such node: %s" nodename)))
262 (Info-select-node)))
263 ;; If we did not finish finding the specified node,
264 ;; go back to the previous one.
265 (or Info-current-node no-going-back
266 (let ((hist (car Info-history)))
267 (setq Info-history (cdr Info-history))
268 (Info-find-node (nth 0 hist) (nth 1 hist) t)
269 (goto-char (nth 2 hist)))))
270 (goto-char (point-min)))
272 ;; Cache the contents of the (virtual) dir file, once we have merged
273 ;; it for the first time, so we can save time subsequently.
274 (defvar Info-dir-contents nil)
276 ;; Cache for the directory we decided to use for the default-directory
277 ;; of the merged dir text.
278 (defvar Info-dir-contents-directory nil)
280 ;; Construct the Info directory node by merging the files named `dir'
281 ;; from various directories. Set the *info* buffer's
282 ;; default-directory to the first directory we actually get any text
283 ;; from.
284 (defun Info-insert-dir ()
285 (if Info-dir-contents
286 (insert Info-dir-contents)
287 (let ((dirs Info-directory-list)
288 buffers buffer others nodes dirs-done)
290 ;; Search the directory list for the directory file.
291 (while dirs
292 (or (member (file-truename (expand-file-name (car dirs))) dirs-done)
293 (member (directory-file-name (file-truename (expand-file-name (car dirs))))
294 dirs-done)
295 ;; Try several variants of specified name.
296 ;; Try upcasing, appending `.info', or both.
297 (let* (temp
298 (buffer
299 (cond
300 ((progn (setq temp (expand-file-name "DIR" (car dirs)))
301 (file-exists-p temp))
302 (find-file-noselect temp))
303 ((progn (setq temp (expand-file-name "dir" (car dirs)))
304 (file-exists-p temp))
305 (find-file-noselect temp))
306 ((progn (setq temp (expand-file-name "DIR.INFO" (car dirs)))
307 (file-exists-p temp))
308 (find-file-noselect temp))
309 ((progn (setq temp (expand-file-name "dir.info" (car dirs)))
310 (file-exists-p temp))
311 (find-file-noselect temp)))))
312 (setq dirs-done
313 (cons (file-truename (expand-file-name (car dirs)))
314 (cons (directory-file-name
315 (file-truename (expand-file-name (car dirs))))
316 dirs-done)))
317 (if buffer (setq buffers (cons buffer buffers)))))
318 (setq dirs (cdr dirs)))
320 ;; Distinguish the dir file that comes with Emacs from all the
321 ;; others. Yes, that is really what this is supposed to do.
322 ;; If it doesn't work, fix it.
323 (setq buffer (car buffers)
324 others (cdr buffers))
326 ;; Insert the entire original dir file as a start; use its
327 ;; default directory as the default directory for the whole
328 ;; concatenation.
329 (insert-buffer buffer)
330 (setq Info-dir-contents-directory (save-excursion
331 (set-buffer buffer)
332 default-directory))
334 ;; Look at each of the other buffers one by one.
335 (while others
336 (let ((other (car others)))
337 ;; In each, find all the menus.
338 (save-excursion
339 (set-buffer other)
340 (goto-char (point-min))
341 ;; Find each menu, and add an elt to NODES for it.
342 (while (re-search-forward "^\\* Menu:" nil t)
343 (let (beg nodename end)
344 (forward-line 1)
345 (setq beg (point))
346 (search-backward "\n\x1f")
347 (search-forward "Node: ")
348 (setq nodename (Info-following-node-name))
349 (search-forward "\n\x1f" nil 'move)
350 (beginning-of-line)
351 (setq end (point))
352 (setq nodes (cons (list nodename other beg end) nodes))))))
353 (setq others (cdr others)))
354 ;; Add to the main menu a menu item for each other node.
355 (re-search-forward "^\\* Menu:")
356 (forward-line 1)
357 (let ((menu-items '("top"))
358 (nodes nodes)
359 (case-fold-search t)
360 (end (save-excursion (search-forward "\x1f" nil t) (point))))
361 (while nodes
362 (let ((nodename (car (car nodes))))
363 (or (member (downcase nodename) menu-items)
364 (re-search-forward (concat "^\\* " (regexp-quote nodename) ":")
365 end t)
366 (progn
367 (insert "* " nodename "\n")
368 (setq menu-items (cons nodename menu-items)))))
369 (setq nodes (cdr nodes))))
370 ;; Now take each node of each of the other buffers
371 ;; and merge it into the main buffer.
372 (while nodes
373 (let ((nodename (car (car nodes))))
374 (goto-char (point-min))
375 ;; Find the like-named node in the main buffer.
376 (if (re-search-forward (concat "\n\x1f.*\n.*Node: "
377 (regexp-quote nodename)
378 "[,\n\t]")
379 nil t)
380 (progn
381 (search-forward "\n\x1f" nil 'move)
382 (beginning-of-line))
383 ;; If none exists, add one.
384 (goto-char (point-max))
385 (insert "\x1f\nFile: dir\tnode: " nodename "\n\n* Menu:\n\n"))
386 ;; Merge the text from the other buffer's menu
387 ;; into the menu in the like-named node in the main buffer.
388 (apply 'insert-buffer-substring (cdr (car nodes)))
389 (insert "\n"))
390 (setq nodes (cdr nodes)))
391 ;; Kill all the buffers we just made.
392 (while buffers
393 (kill-buffer (car buffers))
394 (setq buffers (cdr buffers))))
395 (setq Info-dir-contents (buffer-string)))
396 (setq default-directory Info-dir-contents-directory))
398 (defun Info-read-subfile (nodepos)
399 (set-buffer (marker-buffer Info-tag-table-marker))
400 (goto-char (point-min))
401 (search-forward "\n\^_")
402 (let (lastfilepos
403 lastfilename)
404 (forward-line 2)
405 (catch 'foo
406 (while (not (looking-at "\^_"))
407 (if (not (eolp))
408 (let ((beg (point))
409 thisfilepos thisfilename)
410 (search-forward ": ")
411 (setq thisfilename (buffer-substring beg (- (point) 2)))
412 (setq thisfilepos (read (current-buffer)))
413 ;; read in version 19 stops at the end of number.
414 ;; Advance to the next line.
415 (forward-line 1)
416 (if (> thisfilepos nodepos)
417 (throw 'foo t))
418 (setq lastfilename thisfilename)
419 (setq lastfilepos thisfilepos))
420 (forward-line 1))))
421 (set-buffer (get-buffer "*info*"))
422 (or (equal Info-current-subfile lastfilename)
423 (let ((buffer-read-only nil))
424 (setq buffer-file-name nil)
425 (widen)
426 (erase-buffer)
427 (info-insert-file-contents lastfilename)
428 (set-buffer-modified-p nil)
429 (setq Info-current-subfile lastfilename)))
430 (goto-char (point-min))
431 (search-forward "\n\^_")
432 (+ (- nodepos lastfilepos) (point))))
434 ;; Select the info node that point is in.
435 (defun Info-select-node ()
436 (save-excursion
437 ;; Find beginning of node.
438 (search-backward "\n\^_")
439 (forward-line 2)
440 ;; Get nodename spelled as it is in the node.
441 (re-search-forward "Node:[ \t]*")
442 (setq Info-current-node
443 (buffer-substring (point)
444 (progn
445 (skip-chars-forward "^,\t\n")
446 (point))))
447 (Info-set-mode-line)
448 ;; Find the end of it, and narrow.
449 (beginning-of-line)
450 (let (active-expression)
451 (narrow-to-region (point)
452 (if (re-search-forward "\n[\^_\f]" nil t)
453 (prog1
454 (1- (point))
455 (if (looking-at "[\n\^_\f]*execute: ")
456 (progn
457 (goto-char (match-end 0))
458 (setq active-expression
459 (read (current-buffer))))))
460 (point-max)))
461 (if Info-enable-active-nodes (eval active-expression)))))
463 (defun Info-set-mode-line ()
464 (setq mode-line-buffer-identification
465 (concat
466 "Info: ("
467 (if Info-current-file
468 (file-name-nondirectory Info-current-file)
471 (or Info-current-node ""))))
473 ;; Go to an info node specified with a filename-and-nodename string
474 ;; of the sort that is found in pointers in nodes.
476 (defun Info-goto-node (nodename)
477 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
478 (interactive "sGoto node: ")
479 (let (filename)
480 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
481 nodename)
482 (setq filename (if (= (match-beginning 1) (match-end 1))
484 (substring nodename (match-beginning 2) (match-end 2)))
485 nodename (substring nodename (match-beginning 3) (match-end 3)))
486 (let ((trim (string-match "\\s *\\'" filename)))
487 (if trim (setq filename (substring filename 0 trim))))
488 (let ((trim (string-match "\\s *\\'" nodename)))
489 (if trim (setq nodename (substring nodename 0 trim))))
490 (Info-find-node (if (equal filename "") nil filename)
491 (if (equal nodename "") "Top" nodename))))
493 (defun Info-restore-point (hl)
494 "If this node has been visited, restore the point value when we left."
495 (if hl
496 (if (and (equal (nth 0 (car hl)) Info-current-file)
497 (equal (nth 1 (car hl)) Info-current-node))
498 (goto-char (nth 2 (car hl)))
499 (Info-restore-point (cdr hl)))))
501 (defvar Info-last-search nil
502 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
504 (defun Info-search (regexp)
505 "Search for REGEXP, starting from point, and select node it's found in."
506 (interactive "sSearch (regexp): ")
507 (if (equal regexp "")
508 (setq regexp Info-last-search)
509 (setq Info-last-search regexp))
510 (let ((found ()) current
511 (onode Info-current-node)
512 (ofile Info-current-file)
513 (opoint (point))
514 (osubfile Info-current-subfile))
515 (save-excursion
516 (save-restriction
517 (widen)
518 (if (null Info-current-subfile)
519 (progn (re-search-forward regexp) (setq found (point)))
520 (condition-case err
521 (progn (re-search-forward regexp) (setq found (point)))
522 (search-failed nil)))))
523 (if (not found) ;can only happen in subfile case -- else would have erred
524 (unwind-protect
525 (let ((list ()))
526 (set-buffer (marker-buffer Info-tag-table-marker))
527 (goto-char (point-min))
528 (search-forward "\n\^_\nIndirect:")
529 (save-restriction
530 (narrow-to-region (point)
531 (progn (search-forward "\n\^_")
532 (1- (point))))
533 (goto-char (point-min))
534 (search-forward (concat "\n" osubfile ": "))
535 (beginning-of-line)
536 (while (not (eobp))
537 (re-search-forward "\\(^.*\\): [0-9]+$")
538 (goto-char (+ (match-end 1) 2))
539 (setq list (cons (cons (read (current-buffer))
540 (buffer-substring (match-beginning 1)
541 (match-end 1)))
542 list))
543 (goto-char (1+ (match-end 0))))
544 (setq list (nreverse list)
545 current (car (car list))
546 list (cdr list)))
547 (while list
548 (message "Searching subfile %s..." (cdr (car list)))
549 (Info-read-subfile (car (car list)))
550 (setq list (cdr list))
551 (goto-char (point-min))
552 (if (re-search-forward regexp nil t)
553 (setq found (point) list ())))
554 (if found
555 (message "")
556 (signal 'search-failed (list regexp))))
557 (if (not found)
558 (progn (Info-read-subfile opoint)
559 (goto-char opoint)
560 (Info-select-node)))))
561 (widen)
562 (goto-char found)
563 (Info-select-node)
564 (or (and (equal onode Info-current-node)
565 (equal ofile Info-current-file))
566 (setq Info-history (cons (list ofile onode opoint)
567 Info-history)))))
569 ;; Extract the value of the node-pointer named NAME.
570 ;; If there is none, use ERRORNAME in the error message;
571 ;; if ERRORNAME is nil, just return nil.
572 (defun Info-extract-pointer (name &optional errorname)
573 (save-excursion
574 (goto-char (point-min))
575 (forward-line 1)
576 (if (re-search-backward (concat name ":") nil t)
577 (progn
578 (goto-char (match-end 0))
579 (Info-following-node-name))
580 (if (eq errorname t)
582 (error (concat "Node has no " (capitalize (or errorname name))))))))
584 ;; Return the node name in the buffer following point.
585 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
586 ;; saying which chas may appear in the node name.
587 (defun Info-following-node-name (&optional allowedchars)
588 (skip-chars-forward " \t")
589 (buffer-substring
590 (point)
591 (progn
592 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
593 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
594 (if (looking-at "(")
595 (skip-chars-forward "^)")))
596 (skip-chars-backward " ")
597 (point))))
599 (defun Info-next ()
600 "Go to the next node of this node."
601 (interactive)
602 (Info-goto-node (Info-extract-pointer "next")))
604 (defun Info-prev ()
605 "Go to the previous node of this node."
606 (interactive)
607 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
609 (defun Info-up ()
610 "Go to the superior node of this node."
611 (interactive)
612 (Info-goto-node (Info-extract-pointer "up"))
613 (Info-restore-point Info-history))
615 (defun Info-last ()
616 "Go back to the last node visited."
617 (interactive)
618 (or Info-history
619 (error "This is the first Info node you looked at"))
620 (let (filename nodename opoint)
621 (setq filename (car (car Info-history)))
622 (setq nodename (car (cdr (car Info-history))))
623 (setq opoint (car (cdr (cdr (car Info-history)))))
624 (setq Info-history (cdr Info-history))
625 (Info-find-node filename nodename)
626 (setq Info-history (cdr Info-history))
627 (goto-char opoint)))
629 (defun Info-directory ()
630 "Go to the Info directory node."
631 (interactive)
632 (Info-find-node "dir" "top"))
634 (defun Info-follow-reference (footnotename)
635 "Follow cross reference named NAME to the node it refers to.
636 NAME may be an abbreviation of the reference name."
637 (interactive
638 (let ((completion-ignore-case t)
639 completions default (start-point (point)) str i)
640 (save-excursion
641 (goto-char (point-min))
642 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
643 (setq str (buffer-substring
644 (match-beginning 1)
645 (1- (point))))
646 ;; See if this one should be the default.
647 (and (null default)
648 (< (match-beginning 0) start-point)
649 (<= start-point (point))
650 (setq default t))
651 (setq i 0)
652 (while (setq i (string-match "[ \n\t]+" str i))
653 (setq str (concat (substring str 0 i) " "
654 (substring str (match-end 0))))
655 (setq i (1+ i)))
656 ;; Record as a completion and perhaps as default.
657 (if (eq default t) (setq default str))
658 (setq completions
659 (cons (cons str nil)
660 completions))))
661 (if completions
662 (list (completing-read (if default
663 (concat "Follow reference named: ("
664 default ") ")
665 "Follow reference named: ")
666 completions default t))
667 (error "No cross-references in this node"))))
668 (let (target beg i (str (concat "\\*note " footnotename)))
669 (while (setq i (string-match " " str i))
670 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
671 (setq i (+ i 6)))
672 (save-excursion
673 (goto-char (point-min))
674 (or (re-search-forward str nil t)
675 (error "No cross-reference named %s" footnotename))
676 (goto-char (+ (match-beginning 0) 5))
677 (setq target
678 (Info-extract-menu-node-name "Bad format cross reference" t)))
679 (while (setq i (string-match "[ \t\n]+" target i))
680 (setq target (concat (substring target 0 i) " "
681 (substring target (match-end 0))))
682 (setq i (+ i 1)))
683 (Info-goto-node target)))
685 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
686 (skip-chars-forward " \t\n")
687 (let ((beg (point))
688 str i)
689 (skip-chars-forward "^:")
690 (forward-char 1)
691 (setq str
692 (if (looking-at ":")
693 (buffer-substring beg (1- (point)))
694 (skip-chars-forward " \t\n")
695 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
696 (while (setq i (string-match "\n" str i))
697 (aset str i ?\ ))
698 str))
700 ;; No one calls this and Info-menu-item doesn't exist.
701 ;;(defun Info-menu-item-sequence (list)
702 ;; (while list
703 ;; (Info-menu-item (car list))
704 ;; (setq list (cdr list))))
706 (defun Info-menu (menu-item)
707 "Go to node for menu item named (or abbreviated) NAME.
708 Completion is allowed, and the menu item point is on is the default."
709 (interactive
710 (let ((completions '())
711 ;; If point is within a menu item, use that item as the default
712 (default nil)
713 (p (point))
714 (last nil))
715 (save-excursion
716 (goto-char (point-min))
717 (if (not (search-forward "\n* menu:" nil t))
718 (error "No menu in this node"))
719 (while (re-search-forward
720 "\n\\* \\([^:\t\n]*\\):" nil t)
721 (if (and (null default)
722 (prog1 (if last (< last p) nil)
723 (setq last (match-beginning 0)))
724 (<= p last))
725 (setq default (car (car completions))))
726 (setq completions (cons (cons (buffer-substring
727 (match-beginning 1)
728 (match-end 1))
729 (match-beginning 1))
730 completions)))
731 (if (and (null default) last
732 (< last p)
733 (<= p (progn (end-of-line) (point))))
734 (setq default (car (car completions)))))
735 (let ((item nil))
736 (while (null item)
737 (setq item (let ((completion-ignore-case t))
738 (completing-read (if default
739 (format "Menu item (default %s): "
740 default)
741 "Menu item: ")
742 completions nil t)))
743 ;; we rely on the fact that completing-read accepts an input
744 ;; of "" even when the require-match argument is true and ""
745 ;; is not a valid possibility
746 (if (string= item "")
747 (if default
748 (setq item default)
749 ;; ask again
750 (setq item nil))))
751 (list item))))
752 ;; there is a problem here in that if several menu items have the same
753 ;; name you can only go to the node of the first with this command.
754 (Info-goto-node (Info-extract-menu-item menu-item)))
756 (defun Info-extract-menu-item (menu-item)
757 (setq menu-item (regexp-quote menu-item))
758 (save-excursion
759 (goto-char (point-min))
760 (or (search-forward "\n* menu:" nil t)
761 (error "No menu in this node"))
762 (or (re-search-forward (concat "\n* " menu-item ":") nil t)
763 (re-search-forward (concat "\n* " menu-item) nil t)
764 (error "No such item in menu"))
765 (beginning-of-line)
766 (forward-char 2)
767 (Info-extract-menu-node-name)))
769 ;; If COUNT is nil, use the last item in the menu.
770 (defun Info-extract-menu-counting (count)
771 (save-excursion
772 (goto-char (point-min))
773 (or (search-forward "\n* menu:" nil t)
774 (error "No menu in this node"))
775 (if count
776 (or (search-forward "\n* " nil t count)
777 (error "Too few items in menu"))
778 (while (search-forward "\n* " nil t)
779 nil))
780 (Info-extract-menu-node-name)))
782 (defun Info-nth-menu-item ()
783 "Go to the node of the Nth menu item.
784 N is the digit argument used to invoke this command."
785 (interactive)
786 (Info-goto-node
787 (Info-extract-menu-counting
788 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
790 (defun Info-top-node ()
791 "Go to the Top node of this file."
792 (interactive)
793 (Info-goto-node "Top"))
795 (defun Info-final-node ()
796 "Go to the final node in this file."
797 (interactive)
798 (Info-goto-node "Top")
799 (let (Info-history)
800 ;; Go to the last node in the menu of Top.
801 (Info-goto-node (Info-extract-menu-counting nil))
802 ;; If the last node in the menu is not last in pointer structure,
803 ;; move forward until we can't go any farther.
804 (while (Info-forward-node t t) nil)
805 ;; Then keep moving down to last subnode, unless we reach an index.
806 (while (and (not (string-match "\\<index\\>" Info-current-node))
807 (save-excursion (search-forward "\n* Menu:" nil t)))
808 (Info-goto-node (Info-extract-menu-counting nil)))))
810 (defun Info-forward-node (&optional not-down no-error)
811 "Go forward one node, considering all nodes as forming one sequence."
812 (interactive)
813 (goto-char (point-min))
814 (forward-line 1)
815 ;; three possibilities, in order of priority:
816 ;; 1. next node is in a menu in this node (but not in an index)
817 ;; 2. next node is next at same level
818 ;; 3. next node is up and next
819 (cond ((and (not not-down)
820 (save-excursion (search-forward "\n* menu:" nil t))
821 (not (string-match "\\<index\\>" Info-current-node)))
822 (Info-goto-node (Info-extract-menu-counting 1))
824 ((save-excursion (search-backward "next:" nil t))
825 (Info-next)
827 ((and (save-excursion (search-backward "up:" nil t))
828 (not (equal (downcase (Info-extract-pointer "up")) "top")))
829 (let ((old-node Info-current-node))
830 (Info-up)
831 (let (Info-history success)
832 (unwind-protect
833 (setq success (Info-forward-node t no-error))
834 (or success (Info-goto-node old-node))))))
835 (no-error nil)
836 (t (error "No pointer forward from this node"))))
838 (defun Info-backward-node ()
839 "Go backward one node, considering all nodes as forming one sequence."
840 (interactive)
841 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
842 (upnode (Info-extract-pointer "up" t)))
843 (cond ((and upnode (string-match "(" upnode))
844 (error "First node in file"))
845 ((and upnode (or (null prevnode)
846 (equal (downcase prevnode) (downcase upnode))))
847 (Info-up))
848 (prevnode
849 ;; If we move back at the same level,
850 ;; go down to find the last subnode*.
851 (Info-prev)
852 (let (Info-history)
853 (while (and (not (string-match "\\<index\\>" Info-current-node))
854 (save-excursion (search-forward "\n* Menu:" nil t)))
855 (Info-goto-node (Info-extract-menu-counting nil)))))
857 (error "No pointer backward from this node")))))
859 (defun Info-exit ()
860 "Exit Info by selecting some other buffer."
861 (interactive)
862 (switch-to-buffer (prog1 (other-buffer (current-buffer))
863 (bury-buffer (current-buffer)))))
865 (defun Info-next-menu-item ()
866 (interactive)
867 (save-excursion
868 (forward-line -1)
869 (search-forward "\n* menu:" nil t)
870 (or (search-forward "\n* " nil t)
871 (error "No more items in menu"))
872 (Info-goto-node (Info-extract-menu-node-name))))
874 (defun Info-last-menu-item ()
875 (interactive)
876 (save-excursion
877 (forward-line 1)
878 (search-backward "\n* menu:" nil t)
879 (or (search-backward "\n* " nil t)
880 (error "No previous items in menu"))
881 (Info-goto-node (Info-extract-menu-node-name))))
883 (defmacro no-error (&rest body)
884 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
886 (defun Info-next-preorder ()
887 "Go to the next node, popping up a level if there is none."
888 (interactive)
889 (cond ((no-error (Info-next-menu-item)) )
890 ((no-error (Info-up)) (forward-line 1))
891 (t (error "No more nodes"))))
893 (defun Info-last-preorder ()
894 "Go to the last node, popping up a level if there is none."
895 (interactive)
896 (cond ((no-error (Info-last-menu-item)) )
897 ((no-error (Info-up)) (forward-line -1))
898 (t (error "No previous nodes"))))
900 (defun Info-scroll-up ()
901 "Read the next screen. If end of buffer is visible, go to next entry."
902 (interactive)
903 (if (pos-visible-in-window-p (point-max))
904 (Info-next-preorder)
905 (scroll-up))
908 (defun Info-scroll-down ()
909 "Read the previous screen. If start of buffer is visible, go to last entry."
910 (interactive)
911 (if (pos-visible-in-window-p (point-min))
912 (Info-last-preorder)
913 (scroll-down))
916 (defun Info-index (topic)
917 "Look up a string in the index for this file.
918 The index is defined as the first node in the top-level menu whose
919 name contains the word \"Index\", plus any immediately following
920 nodes whose names also contain the word \"Index\".
921 If there are no exact matches to the specified topic, this chooses
922 the first match which is a case-insensitive substring of a topic.
923 Use the `,' command to see the other matches.
924 Give a blank topic name to go to the Index node itself."
925 (interactive "sIndex topic: ")
926 (let ((orignode Info-current-node)
927 (rnode nil)
928 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
929 (regexp-quote topic)))
930 node)
931 (Info-goto-node "Top")
932 (or (search-forward "\n* menu:" nil t)
933 (error "No index"))
934 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
935 (error "No index"))
936 (goto-char (match-beginning 1))
937 (let ((Info-keeping-history nil))
938 (Info-goto-node (Info-extract-menu-node-name)))
939 (or (equal topic "")
940 (let ((matches nil)
941 (exact nil)
942 (Info-keeping-history nil)
943 found)
944 (while
945 (progn
946 (goto-char (point-min))
947 (while (re-search-forward pattern nil t)
948 (setq matches
949 (cons (list (buffer-substring (match-beginning 1)
950 (match-end 1))
951 (buffer-substring (match-beginning 2)
952 (match-end 2))
953 Info-current-node
954 (string-to-int (concat "0"
955 (buffer-substring
956 (match-beginning 3)
957 (match-end 3)))))
958 matches)))
959 (and (setq node (Info-extract-pointer "next" t))
960 (string-match "\\<Index\\>" node)))
961 (Info-goto-node node))
962 (or matches
963 (progn
964 (Info-last)
965 (error "No \"%s\" in index" topic)))
966 ;; Here it is a feature that assoc is case-sensitive.
967 (while (setq found (assoc topic matches))
968 (setq exact (cons found exact)
969 matches (delq found matches)))
970 (setq Info-index-alternatives (nconc exact (nreverse matches)))
971 (Info-index-next 0)))))
973 (defun Info-index-next (num)
974 "Go to the next matching index item from the last `i' command."
975 (interactive "p")
976 (or Info-index-alternatives
977 (error "No previous `i' command in this file"))
978 (while (< num 0)
979 (setq num (+ num (length Info-index-alternatives))))
980 (while (> num 0)
981 (setq Info-index-alternatives
982 (nconc (cdr Info-index-alternatives)
983 (list (car Info-index-alternatives)))
984 num (1- num)))
985 (Info-goto-node (nth 1 (car Info-index-alternatives)))
986 (if (> (nth 3 (car Info-index-alternatives)) 0)
987 (forward-line (nth 3 (car Info-index-alternatives)))
988 (forward-line 3) ; don't search in headers
989 (let ((name (car (car Info-index-alternatives))))
990 (if (or (re-search-forward (format
991 "\\(Function\\|Command\\): %s\\( \\|$\\)"
992 (regexp-quote name)) nil t)
993 (search-forward (format "`%s'" name) nil t)
994 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
995 (search-forward
996 (format "`%s'" (substring name 0 (match-beginning 1)))
997 nil t))
998 (search-forward name nil t))
999 (beginning-of-line)
1000 (goto-char (point-min)))))
1001 (message "Found \"%s\" in %s. %s"
1002 (car (car Info-index-alternatives))
1003 (nth 2 (car Info-index-alternatives))
1004 (if (cdr Info-index-alternatives)
1005 "(Press `,' for more)"
1006 "(Only match)")))
1008 (defun Info-undefined ()
1009 "Make command be undefined in Info."
1010 (interactive)
1011 (ding))
1013 (defun Info-help ()
1014 "Enter the Info tutorial."
1015 (interactive)
1016 (delete-other-windows)
1017 (Info-find-node "info"
1018 (if (< (window-height) 23)
1019 "Help-Small-Screen"
1020 "Help")))
1022 (defun Info-summary ()
1023 "Display a brief summary of all Info commands."
1024 (interactive)
1025 (save-window-excursion
1026 (switch-to-buffer "*Help*")
1027 (erase-buffer)
1028 (insert (documentation 'Info-mode))
1029 (goto-char (point-min))
1030 (let (ch flag)
1031 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1032 (message (if flag "Type Space to see more"
1033 "Type Space to return to Info"))
1034 (if (not (eq ?\ (setq ch (read-event))))
1035 (progn (setq unread-command-events (list ch)) nil)
1036 flag))
1037 (scroll-up)))))
1039 (defun Info-get-token (pos start all &optional errorstring)
1040 "Return the token around POS,
1041 POS must be somewhere inside the token
1042 START is a regular expression which will match the
1043 beginning of the tokens delimited string
1044 ALL is a regular expression with a single
1045 parenthized subpattern which is the token to be
1046 returned. E.g. '{\(.*\)}' would return any string
1047 enclosed in braces around POS.
1048 SIG optional fourth argument, controls action on no match
1049 nil: return nil
1050 t: beep
1051 a string: signal an error, using that string."
1052 (save-excursion
1053 (goto-char pos)
1054 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1055 (let (found)
1056 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1057 (not (setq found (and (<= (match-beginning 0) pos)
1058 (> (match-end 0) pos))))))
1059 (if (and found (<= (match-beginning 0) pos)
1060 (> (match-end 0) pos))
1061 (buffer-substring (match-beginning 1) (match-end 1))
1062 (cond ((null errorstring)
1063 nil)
1064 ((eq errorstring t)
1065 (beep)
1066 nil)
1068 (error "No %s around position %d" errorstring pos)))))))
1070 (defun Info-follow-nearest-node (click)
1071 "\\<Info-mode-map>Follow a node reference near point.
1072 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1073 At end of the node's text, moves to the next node."
1074 (interactive "e")
1075 (let* ((start (event-start click))
1076 (window (car start))
1077 (pos (car (cdr start))))
1078 (select-window window)
1079 (goto-char pos))
1080 (let (node)
1081 (cond
1082 ((setq node (Info-get-token (point) "\\*note[ \n]" "\\*note[ \n]\\([^:]*\\):"))
1083 (Info-follow-reference node))
1084 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1085 (Info-goto-node node))
1086 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1087 (Info-menu node))
1088 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1089 (Info-goto-node node))
1090 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1091 (Info-goto-node node))
1092 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1093 (Info-goto-node "Top"))
1094 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1095 (Info-goto-node node))
1096 ((save-excursion (forward-line 1) (eobp))
1097 (Info-next)))
1100 (defvar Info-mode-map nil
1101 "Keymap containing Info commands.")
1102 (if Info-mode-map
1104 (setq Info-mode-map (make-keymap))
1105 (suppress-keymap Info-mode-map)
1106 (define-key Info-mode-map "." 'beginning-of-buffer)
1107 (define-key Info-mode-map " " 'Info-scroll-up)
1108 (define-key Info-mode-map "\C-m" 'Info-next-preorder)
1109 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1110 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1111 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1112 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1113 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1114 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1115 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1116 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1117 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1118 (define-key Info-mode-map "0" 'undefined)
1119 (define-key Info-mode-map "?" 'Info-summary)
1120 (define-key Info-mode-map "]" 'Info-forward-node)
1121 (define-key Info-mode-map "[" 'Info-backward-node)
1122 (define-key Info-mode-map "<" 'Info-top-node)
1123 (define-key Info-mode-map ">" 'Info-final-node)
1124 (define-key Info-mode-map "b" 'beginning-of-buffer)
1125 (define-key Info-mode-map "d" 'Info-directory)
1126 (define-key Info-mode-map "e" 'Info-edit)
1127 (define-key Info-mode-map "f" 'Info-follow-reference)
1128 (define-key Info-mode-map "g" 'Info-goto-node)
1129 (define-key Info-mode-map "h" 'Info-help)
1130 (define-key Info-mode-map "i" 'Info-index)
1131 (define-key Info-mode-map "l" 'Info-last)
1132 (define-key Info-mode-map "m" 'Info-menu)
1133 (define-key Info-mode-map "n" 'Info-next)
1134 (define-key Info-mode-map "p" 'Info-prev)
1135 (define-key Info-mode-map "q" 'Info-exit)
1136 (define-key Info-mode-map "s" 'Info-search)
1137 (define-key Info-mode-map "t" 'Info-top-node)
1138 (define-key Info-mode-map "u" 'Info-up)
1139 (define-key Info-mode-map "," 'Info-index-next)
1140 (define-key Info-mode-map "\177" 'Info-scroll-down)
1141 (define-key Info-mode-map [mouse-3] 'Info-follow-nearest-node)
1144 ;; Info mode is suitable only for specially formatted data.
1145 (put 'info-mode 'mode-class 'special)
1147 (defun Info-mode ()
1148 "\\<Info-mode-map>
1149 Info mode provides commands for browsing through the Info documentation tree.
1150 Documentation in Info is divided into \"nodes\", each of which discusses
1151 one topic and contains references to other nodes which discuss related
1152 topics. Info has commands to follow the references and show you other nodes.
1154 \\[Info-help] Invoke the Info tutorial.
1156 Selecting other nodes:
1157 \\[Info-next] Move to the \"next\" node of this node.
1158 \\[Info-prev] Move to the \"previous\" node of this node.
1159 \\[Info-up] Move \"up\" from this node.
1160 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1161 Picking a menu item causes another node to be selected.
1162 \\[Info-directory] Go to the Info directory node.
1163 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1164 \\[Info-last] Move to the last node you were at.
1165 \\[Info-index] Look up a topic in this file's Index and move to that node.
1166 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1168 Moving within a node:
1169 \\[scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1170 already visible, try to go to the next menu entry, or up if there is none.
1171 \\[scroll-down] Normally, scroll backward. If the beginning of the buffer is
1172 already visible, try to go to the previous menu entry, or up if there is none.
1173 \\[beginning-of-buffer] Go to beginning of node.
1175 Advanced commands:
1176 \\[Info-exit] Quit Info: reselect previously selected buffer.
1177 \\[Info-edit] Edit contents of selected node.
1178 1 Pick first item in node's menu.
1179 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1180 \\[Info-goto-node] Move to node specified by name.
1181 You may include a filename as well, as (FILENAME)NODENAME.
1182 \\[Info-search] Search through this Info file for specified regexp,
1183 and select the node in which the next occurrence is found.
1184 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1185 and if that fails try to move up, and if that fails, tell user
1186 he/she is done reading."
1187 (kill-all-local-variables)
1188 (setq major-mode 'Info-mode)
1189 (setq mode-name "Info")
1190 (use-local-map Info-mode-map)
1191 (set-syntax-table text-mode-syntax-table)
1192 (setq local-abbrev-table text-mode-abbrev-table)
1193 (setq case-fold-search t)
1194 (setq buffer-read-only t)
1195 (make-local-variable 'Info-current-file)
1196 (make-local-variable 'Info-current-subfile)
1197 (make-local-variable 'Info-current-node)
1198 (make-local-variable 'Info-tag-table-marker)
1199 (make-local-variable 'Info-history)
1200 (make-local-variable 'Info-index-alternatives)
1201 (Info-set-mode-line)
1202 (run-hooks 'Info-mode-hook))
1204 (defvar Info-edit-map nil
1205 "Local keymap used within `e' command of Info.")
1206 (if Info-edit-map
1208 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1209 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1211 ;; Info-edit mode is suitable only for specially formatted data.
1212 (put 'info-edit-mode 'mode-class 'special)
1214 (defun Info-edit-mode ()
1215 "Major mode for editing the contents of an Info node.
1216 Like text mode with the addition of `Info-cease-edit'
1217 which returns to Info mode for browsing.
1218 \\{Info-edit-map}"
1221 (defun Info-edit ()
1222 "Edit the contents of this Info node.
1223 Allowed only if variable `Info-enable-edit' is non-nil."
1224 (interactive)
1225 (or Info-enable-edit
1226 (error "Editing info nodes is not enabled"))
1227 (use-local-map Info-edit-map)
1228 (setq major-mode 'Info-edit-mode)
1229 (setq mode-name "Info Edit")
1230 (kill-local-variable 'mode-line-buffer-identification)
1231 (setq buffer-read-only nil)
1232 ;; Make mode line update.
1233 (set-buffer-modified-p (buffer-modified-p))
1234 (message (substitute-command-keys
1235 "Editing: Type \\<Info-mode-map>\\[Info-cease-edit] to return to info")))
1237 (defun Info-cease-edit ()
1238 "Finish editing Info node; switch back to Info proper."
1239 (interactive)
1240 ;; Do this first, so nothing has changed if user C-g's at query.
1241 (and (buffer-modified-p)
1242 (y-or-n-p "Save the file? ")
1243 (save-buffer))
1244 (use-local-map Info-mode-map)
1245 (setq major-mode 'Info-mode)
1246 (setq mode-name "Info")
1247 (Info-set-mode-line)
1248 (setq buffer-read-only t)
1249 ;; Make mode line update.
1250 (set-buffer-modified-p (buffer-modified-p))
1251 (and (marker-position Info-tag-table-marker)
1252 (buffer-modified-p)
1253 (message "Tags may have changed. Use Info-tagify if necessary")))
1255 (defun Info-find-emacs-command-nodes (command)
1256 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1257 The locations are of the format used in Info-history, i.e.
1258 \(FILENAME NODENAME BUFFERPOS\)."
1259 (require 'info)
1260 (let ((where '())
1261 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1262 ":\\s *\\(.*\\)\\.$")))
1263 (save-excursion
1264 (Info-find-node "emacs" "Command Index")
1265 ;; Take the index node off the Info history.
1266 (setq Info-history (cdr Info-history))
1267 (goto-char (point-max))
1268 (while (re-search-backward cmd-desc nil t)
1269 (setq where (cons (list Info-current-file
1270 (buffer-substring
1271 (match-beginning 1)
1272 (match-end 1))
1274 where)))
1275 where)))
1277 ;;;###autoload
1278 (defun Info-goto-emacs-command-node (command)
1279 "Go to the Info node in the Emacs manual for command COMMAND."
1280 (interactive "CFind documentation for command: ")
1281 (or (commandp command)
1282 (signal 'wrong-type-argument (list 'commandp command)))
1283 (let ((where (Info-find-emacs-command-nodes command)))
1284 (if where
1285 (let ((num-matches (length where)))
1286 ;; Get Info running, and pop to it in another window.
1287 (save-window-excursion
1288 (info))
1289 (pop-to-buffer "*info*")
1290 (Info-find-node (car (car where))
1291 (car (cdr (car where))))
1292 (if (> num-matches 1)
1293 (progn
1294 ;; Info-find-node already pushed (car where) onto
1295 ;; Info-history. Put the other nodes that were found on
1296 ;; the history.
1297 (setq Info-history (nconc (cdr where) Info-history))
1298 (message (substitute-command-keys
1299 "Found %d other entr%. Use \\[Info-last] to see %s."
1300 (1- num-matches)
1301 (if (> num-matches 2) "ies" "y")
1302 (if (> num-matches 2) "them" "it"))))))
1303 (error "Couldn't find documentation for %s." command))))
1305 ;;;###autoload
1306 (defun Info-goto-emacs-key-command-node (key)
1307 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1308 Interactively, if the binding is execute-extended-command, a command is read."
1309 (interactive "kFind documentation for key:")
1310 (let ((command (key-binding key)))
1311 (cond ((null command)
1312 (message "%s is undefined" (key-description key)))
1313 ((and (interactive-p)
1314 (eq command 'execute-extended-command))
1315 (Info-goto-emacs-command-node
1316 (read-command "Find documentation for command: ")))
1318 (Info-goto-emacs-command-node command)))))
1320 (provide 'info)
1322 ;;; info.el ends here