]> code.delx.au - gnu-emacs/blob - lisp/info.el
(Info-directory-list): For msdos, don't check for
[gnu-emacs] / lisp / info.el
1 ;;; info.el --- info package for Emacs.
2
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: help
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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.
23
24 ;;; Commentary:
25
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
27
28 ;;; Code:
29
30 (defvar Info-history nil
31 "List of info nodes user has visited.
32 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
33
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.")
40
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.")
44
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.")
49
50 (defvar Info-fontify t
51 "*Non-nil enables highlighting and fonts in Info nodes.")
52
53 (defvar Info-directory-list
54 (let ((path (getenv "INFOPATH"))
55 (sep (if (eq system-type 'ms-dos) ";" ":"))
56 (sibling (expand-file-name "../info/" (invocation-directory))))
57 (if path
58 (let ((list nil)
59 idx)
60 (while (> (length path) 0)
61 (setq idx (or (string-match sep path) (length path))
62 list (cons (substring path 0 idx) list)
63 path (substring path (min (1+ idx)
64 (length path)))))
65 (nreverse list))
66 (if (or (member sibling Info-default-directory-list)
67 (not (file-exists-p sibling))
68 ;; On MS-DOS, we use movable executables always,
69 ;; and we must always find the Info dir at run time.
70 (if (eq system-type 'ms-dos)
71 nil
72 ;; Use invocation-directory for Info only if we used it for
73 ;; exec-directory also.
74 (not (string= exec-directory
75 (expand-file-name "../lib-src/"
76 (invocation-directory))))))
77 Info-default-directory-list
78 (reverse (cons sibling (cdr (reverse Info-default-directory-list)))))))
79 "List of directories to search for Info documentation files.
80 nil means not yet initialized. In this case, Info uses the environment
81 variable INFOPATH to initialize it, or `Info-default-directory-list'
82 if there is no INFOPATH variable in the environment.
83 The last element of `Info-default-directory-list' is the directory
84 where Emacs installs the Info files that come with it.
85 If Emacs finds it has been installed elsewhere, or not yet installed,
86 it replaces that element with the directory that its Info files are in.")
87
88 (defvar Info-current-file nil
89 "Info file that Info is now looking at, or nil.")
90
91 (defvar Info-current-subfile nil
92 "Info subfile that is actually in the *info* buffer now,
93 or nil if current info file is not split into subfiles.")
94
95 (defvar Info-current-node nil
96 "Name of node that Info is now looking at, or nil.")
97
98 (defvar Info-tag-table-marker (make-marker)
99 "Marker pointing at beginning of current Info file's tag table.
100 Marker points nowhere if file has no tag table.")
101
102 (defvar Info-current-file-completions nil
103 "Cached completion list for current Info file.")
104
105 (defvar Info-index-alternatives nil
106 "List of possible matches for last Info-index command.")
107
108 (defvar Info-standalone nil
109 "Non-nil if Emacs was started solely as an Info browser.")
110
111 (defvar Info-suffix-list '( (".info.Z" . "uncompress")
112 (".info.Y" . "unyabba")
113 (".info.gz" . "gunzip")
114 (".info.z" . "gunzip")
115 (".info" . nil)
116 (".Z" . "uncompress")
117 (".Y" . "unyabba")
118 (".gz" . "gunzip")
119 (".z" . "gunzip")
120 ("" . nil))
121 "List of file name suffixes and associated decoding commands.
122 Each entry should be (SUFFIX . STRING); the file is given to
123 the command as standard input. If STRING is nil, no decoding is done.
124 Because the SUFFIXes are tried in order, the empty string should
125 be last in the list.")
126
127 (defun info-insert-file-contents (filename &optional visit)
128 "Insert the contents of an info file in the current buffer.
129 Do the right thing if the file has been compressed or zipped."
130 (let ((tail Info-suffix-list)
131 fullname decoder)
132 (if (file-exists-p filename)
133 (progn
134 (while (and tail
135 (not (string-match
136 (concat (regexp-quote (car (car tail))) "$")
137 filename)))
138 (setq tail (cdr tail)))
139 (setq fullname filename
140 decoder (cdr (car tail))))
141 (while (and tail
142 (not (file-exists-p (concat filename (car (car tail))))))
143 (setq tail (cdr tail)))
144 (setq fullname (concat filename (car (car tail)))
145 decoder (cdr (car tail)))
146 ;; check for conflict with jka-compr
147 (if (and (featurep 'jka-compr)
148 (jka-compr-installed-p)
149 (jka-compr-get-compression-info (concat filename
150 (car (car tail)))))
151 (setq decoder nil))
152 (or tail
153 (error "Can't find %s or any compressed version of it!" filename)))
154 (insert-file-contents fullname visit)
155 (if decoder
156 (let ((buffer-read-only nil))
157 (shell-command-on-region (point-min) (point-max) decoder t)))))
158
159 ;;;###autoload
160 (defun info (&optional file)
161 "Enter Info, the documentation browser.
162 Optional argument FILE specifies the file to examine;
163 the default is the top-level directory of Info.
164
165 In interactive use, a prefix argument directs this command
166 to read a file name from the minibuffer."
167 (interactive (if current-prefix-arg
168 (list (read-file-name "Info file name: " nil nil t))))
169 (if file
170 (Info-goto-node (concat "(" file ")"))
171 (if (get-buffer "*info*")
172 (switch-to-buffer "*info*")
173 (Info-directory))))
174
175 ;;;###autoload
176 (defun info-standalone ()
177 "Run Emacs as a standalone Info reader.
178 Usage: emacs -f info-standalone [filename]
179 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
180 (setq Info-standalone t)
181 (if (and command-line-args-left
182 (not (string-match "^-" (car command-line-args-left))))
183 (condition-case err
184 (progn
185 (info (car command-line-args-left))
186 (setq command-line-args-left (cdr command-line-args-left)))
187 (error (send-string-to-terminal
188 (format "%s\n" (if (eq (car-safe err) 'error)
189 (nth 1 err) err)))
190 (save-buffers-kill-emacs)))
191 (info)))
192
193 ;; Go to an info node specified as separate filename and nodename.
194 ;; no-going-back is non-nil if recovering from an error in this function;
195 ;; it says do not attempt further (recursive) error recovery.
196 (defun Info-find-node (filename nodename &optional no-going-back)
197 ;; Convert filename to lower case if not found as specified.
198 ;; Expand it.
199 (if filename
200 (let (temp temp-downcase found)
201 (setq filename (substitute-in-file-name filename))
202 (if (string= (downcase (file-name-nondirectory filename)) "dir")
203 (setq found t)
204 (let ((dirs (if (string-match "^\\./" filename)
205 ;; If specified name starts with `./'
206 ;; then just try current directory.
207 '("./")
208 Info-directory-list)))
209 ;; Search the directory list for file FILENAME.
210 (while (and dirs (not found))
211 (setq temp (expand-file-name filename (car dirs)))
212 (setq temp-downcase
213 (expand-file-name (downcase filename) (car dirs)))
214 ;; Try several variants of specified name.
215 (catch 'foundit
216 (mapcar
217 (function
218 (lambda (x)
219 (if (file-exists-p (concat temp (car x)))
220 (progn
221 (setq found temp)
222 (throw 'foundit nil)))
223 (if (file-exists-p (concat temp-downcase (car x)))
224 (progn
225 (setq found temp-downcase)
226 (throw 'foundit nil)))))
227 Info-suffix-list))
228 (setq dirs (cdr dirs)))))
229 (if found
230 (setq filename found)
231 (error "Info file %s does not exist" filename))))
232 ;; Record the node we are leaving.
233 (if (and Info-current-file (not no-going-back))
234 (setq Info-history
235 (cons (list Info-current-file Info-current-node (point))
236 Info-history)))
237 ;; Go into info buffer.
238 (switch-to-buffer "*info*")
239 (buffer-disable-undo (current-buffer))
240 (or (eq major-mode 'Info-mode)
241 (Info-mode))
242 (widen)
243 (setq Info-current-node nil)
244 (unwind-protect
245 (progn
246 ;; Switch files if necessary
247 (or (null filename)
248 (equal Info-current-file filename)
249 (let ((buffer-read-only nil))
250 (setq Info-current-file nil
251 Info-current-subfile nil
252 Info-current-file-completions nil
253 Info-index-alternatives nil
254 buffer-file-name nil)
255 (erase-buffer)
256 (if (eq filename t)
257 (Info-insert-dir)
258 (info-insert-file-contents filename t)
259 (setq default-directory (file-name-directory filename)))
260 (set-buffer-modified-p nil)
261 ;; See whether file has a tag table. Record the location if yes.
262 (set-marker Info-tag-table-marker nil)
263 (goto-char (point-max))
264 (forward-line -8)
265 (or (equal nodename "*")
266 (not (search-forward "\^_\nEnd tag table\n" nil t))
267 (let (pos)
268 ;; We have a tag table. Find its beginning.
269 ;; Is this an indirect file?
270 (search-backward "\nTag table:\n")
271 (setq pos (point))
272 (if (save-excursion
273 (forward-line 2)
274 (looking-at "(Indirect)\n"))
275 ;; It is indirect. Copy it to another buffer
276 ;; and record that the tag table is in that buffer.
277 (save-excursion
278 (let ((buf (current-buffer)))
279 (set-buffer (get-buffer-create " *info tag table*"))
280 (buffer-disable-undo (current-buffer))
281 (setq case-fold-search t)
282 (erase-buffer)
283 (insert-buffer-substring buf)
284 (set-marker Info-tag-table-marker
285 (match-end 0))))
286 (set-marker Info-tag-table-marker pos))))
287 (setq Info-current-file
288 (if (eq filename t) "dir"
289 (file-name-sans-versions buffer-file-name)))))
290 (if (equal nodename "*")
291 (progn (setq Info-current-node nodename)
292 (Info-set-mode-line))
293 ;; Search file for a suitable node.
294 (let ((guesspos (point-min))
295 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
296 ;; First get advice from tag table if file has one.
297 ;; Also, if this is an indirect info file,
298 ;; read the proper subfile into this buffer.
299 (if (marker-position Info-tag-table-marker)
300 (save-excursion
301 (set-buffer (marker-buffer Info-tag-table-marker))
302 (goto-char Info-tag-table-marker)
303 (if (re-search-forward regexp nil t)
304 (progn
305 (setq guesspos (read (current-buffer)))
306 ;; If this is an indirect file,
307 ;; determine which file really holds this node
308 ;; and read it in.
309 (if (not (eq (current-buffer) (get-buffer "*info*")))
310 (setq guesspos
311 (Info-read-subfile guesspos))))
312 (error "No such node: \"%s\"" nodename))))
313 (goto-char (max (point-min) (- guesspos 1000)))
314 ;; Now search from our advised position (or from beg of buffer)
315 ;; to find the actual node.
316 (catch 'foo
317 (while (search-forward "\n\^_" nil t)
318 (forward-line 1)
319 (let ((beg (point)))
320 (forward-line 1)
321 (if (re-search-backward regexp beg t)
322 (throw 'foo t))))
323 (error "No such node: %s" nodename)))
324 (Info-select-node)))
325 ;; If we did not finish finding the specified node,
326 ;; go back to the previous one.
327 (or Info-current-node no-going-back (null Info-history)
328 (let ((hist (car Info-history)))
329 (setq Info-history (cdr Info-history))
330 (Info-find-node (nth 0 hist) (nth 1 hist) t)
331 (goto-char (nth 2 hist)))))
332 (goto-char (point-min)))
333
334 ;; Cache the contents of the (virtual) dir file, once we have merged
335 ;; it for the first time, so we can save time subsequently.
336 (defvar Info-dir-contents nil)
337
338 ;; Cache for the directory we decided to use for the default-directory
339 ;; of the merged dir text.
340 (defvar Info-dir-contents-directory nil)
341
342 ;; Record the file attributes of all the files from which we
343 ;; constructed Info-dir-contents.
344 (defvar Info-dir-file-attributes nil)
345
346 ;; Construct the Info directory node by merging the files named `dir'
347 ;; from various directories. Set the *info* buffer's
348 ;; default-directory to the first directory we actually get any text
349 ;; from.
350 (defun Info-insert-dir ()
351 (if (and Info-dir-contents Info-dir-file-attributes
352 ;; Verify that none of the files we used has changed
353 ;; since we used it.
354 (eval (cons 'and
355 (mapcar '(lambda (elt)
356 (let ((curr (file-attributes (car elt))))
357 ;; Don't compare the access time.
358 (if curr (setcar (nthcdr 4 curr) 0))
359 (setcar (nthcdr 4 (cdr elt)) 0)
360 (equal (cdr elt) curr)))
361 Info-dir-file-attributes))))
362 (insert Info-dir-contents)
363 (let ((dirs Info-directory-list)
364 buffers buffer others nodes dirs-done)
365
366 (setq Info-dir-file-attributes nil)
367
368 ;; Search the directory list for the directory file.
369 (while dirs
370 (let ((truename (file-truename (expand-file-name (car dirs)))))
371 (or (member truename dirs-done)
372 (member (directory-file-name truename) dirs-done)
373 ;; Try several variants of specified name.
374 ;; Try upcasing, appending `.info', or both.
375 (let* (file
376 (attrs
377 (or
378 (progn (setq file (expand-file-name "dir" truename))
379 (file-attributes file))
380 (progn (setq file (expand-file-name "DIR" truename))
381 (file-attributes file))
382 (progn (setq file (expand-file-name "dir.info" truename))
383 (file-attributes file))
384 (progn (setq file (expand-file-name "DIR.INFO" truename))
385 (file-attributes file)))))
386 (setq dirs-done
387 (cons truename
388 (cons (directory-file-name truename)
389 dirs-done)))
390 (if attrs
391 (save-excursion
392 (or buffers
393 (message "Composing main Info directory..."))
394 (set-buffer (generate-new-buffer "info dir"))
395 (insert-file-contents file)
396 (setq buffers (cons (current-buffer) buffers)
397 Info-dir-file-attributes
398 (cons (cons file attrs)
399 Info-dir-file-attributes))))))
400 (setq dirs (cdr dirs))))
401
402 (or buffers
403 (error "Can't find the info directory node"))
404 ;; Distinguish the dir file that comes with Emacs from all the
405 ;; others. Yes, that is really what this is supposed to do.
406 ;; If it doesn't work, fix it.
407 (setq buffer (car buffers)
408 others (cdr buffers))
409
410 ;; Insert the entire original dir file as a start; use its
411 ;; default directory as the default directory for the whole
412 ;; concatenation.
413 (insert-buffer buffer)
414 (setq Info-dir-contents-directory (save-excursion
415 (set-buffer buffer)
416 default-directory))
417
418 ;; Look at each of the other buffers one by one.
419 (while others
420 (let ((other (car others)))
421 ;; In each, find all the menus.
422 (save-excursion
423 (set-buffer other)
424 (goto-char (point-min))
425 ;; Find each menu, and add an elt to NODES for it.
426 (while (re-search-forward "^\\* Menu:" nil t)
427 (let (beg nodename end)
428 (forward-line 1)
429 (setq beg (point))
430 (search-backward "\n\^_")
431 (search-forward "Node: ")
432 (setq nodename (Info-following-node-name))
433 (search-forward "\n\^_" nil 'move)
434 (beginning-of-line)
435 (setq end (point))
436 (setq nodes (cons (list nodename other beg end) nodes))))))
437 (setq others (cdr others)))
438 ;; Add to the main menu a menu item for each other node.
439 (re-search-forward "^\\* Menu:")
440 (forward-line 1)
441 (let ((menu-items '("top"))
442 (nodes nodes)
443 (case-fold-search t)
444 (end (save-excursion (search-forward "\^_" nil t) (point))))
445 (while nodes
446 (let ((nodename (car (car nodes))))
447 (save-excursion
448 (or (member (downcase nodename) menu-items)
449 (re-search-forward (concat "^\\* "
450 (regexp-quote nodename)
451 "::")
452 end t)
453 (progn
454 (insert "* " nodename "::" "\n")
455 (setq menu-items (cons nodename menu-items))))))
456 (setq nodes (cdr nodes))))
457 ;; Now take each node of each of the other buffers
458 ;; and merge it into the main buffer.
459 (while nodes
460 (let ((nodename (car (car nodes))))
461 (goto-char (point-min))
462 ;; Find the like-named node in the main buffer.
463 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
464 (regexp-quote nodename)
465 "[,\n\t]")
466 nil t)
467 (progn
468 (search-forward "\n\^_" nil 'move)
469 (beginning-of-line))
470 ;; If none exists, add one.
471 (goto-char (point-max))
472 (insert "\^_\nFile: dir\tnode: " nodename "\n\n* Menu:\n\n"))
473 ;; Merge the text from the other buffer's menu
474 ;; into the menu in the like-named node in the main buffer.
475 (apply 'insert-buffer-substring (cdr (car nodes)))
476 (insert "\n"))
477 (setq nodes (cdr nodes)))
478 ;; Kill all the buffers we just made.
479 (while buffers
480 (kill-buffer (car buffers))
481 (setq buffers (cdr buffers)))
482 (message "Composing main Info directory...done"))
483 (setq Info-dir-contents (buffer-string)))
484 (setq default-directory Info-dir-contents-directory))
485
486 (defun Info-read-subfile (nodepos)
487 (set-buffer (marker-buffer Info-tag-table-marker))
488 (goto-char (point-min))
489 (search-forward "\n\^_")
490 (let (lastfilepos
491 lastfilename)
492 (forward-line 2)
493 (catch 'foo
494 (while (not (looking-at "\^_"))
495 (if (not (eolp))
496 (let ((beg (point))
497 thisfilepos thisfilename)
498 (search-forward ": ")
499 (setq thisfilename (buffer-substring beg (- (point) 2)))
500 (setq thisfilepos (read (current-buffer)))
501 ;; read in version 19 stops at the end of number.
502 ;; Advance to the next line.
503 (forward-line 1)
504 (if (> thisfilepos nodepos)
505 (throw 'foo t))
506 (setq lastfilename thisfilename)
507 (setq lastfilepos thisfilepos))
508 (forward-line 1))))
509 (set-buffer (get-buffer "*info*"))
510 (or (equal Info-current-subfile lastfilename)
511 (let ((buffer-read-only nil))
512 (setq buffer-file-name nil)
513 (widen)
514 (erase-buffer)
515 (info-insert-file-contents lastfilename)
516 (set-buffer-modified-p nil)
517 (setq Info-current-subfile lastfilename)))
518 (goto-char (point-min))
519 (search-forward "\n\^_")
520 (+ (- nodepos lastfilepos) (point))))
521
522 ;; Select the info node that point is in.
523 (defun Info-select-node ()
524 (save-excursion
525 ;; Find beginning of node.
526 (search-backward "\n\^_")
527 (forward-line 2)
528 ;; Get nodename spelled as it is in the node.
529 (re-search-forward "Node:[ \t]*")
530 (setq Info-current-node
531 (buffer-substring (point)
532 (progn
533 (skip-chars-forward "^,\t\n")
534 (point))))
535 (Info-set-mode-line)
536 ;; Find the end of it, and narrow.
537 (beginning-of-line)
538 (let (active-expression)
539 (narrow-to-region (point)
540 (if (re-search-forward "\n[\^_\f]" nil t)
541 (prog1
542 (1- (point))
543 (if (looking-at "[\n\^_\f]*execute: ")
544 (progn
545 (goto-char (match-end 0))
546 (setq active-expression
547 (read (current-buffer))))))
548 (point-max)))
549 (if Info-enable-active-nodes (eval active-expression))
550 (if Info-fontify (Info-fontify-node))
551 (run-hooks 'Info-selection-hook))))
552
553 (defun Info-set-mode-line ()
554 (setq mode-line-buffer-identification
555 (concat
556 "Info: ("
557 (if Info-current-file
558 (file-name-nondirectory Info-current-file)
559 "")
560 ")"
561 (or Info-current-node ""))))
562 \f
563 ;; Go to an info node specified with a filename-and-nodename string
564 ;; of the sort that is found in pointers in nodes.
565
566 (defun Info-goto-node (nodename)
567 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
568 (interactive (list (Info-read-node-name "Goto node: ")))
569 (let (filename)
570 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
571 nodename)
572 (setq filename (if (= (match-beginning 1) (match-end 1))
573 ""
574 (substring nodename (match-beginning 2) (match-end 2)))
575 nodename (substring nodename (match-beginning 3) (match-end 3)))
576 (let ((trim (string-match "\\s *\\'" filename)))
577 (if trim (setq filename (substring filename 0 trim))))
578 (let ((trim (string-match "\\s *\\'" nodename)))
579 (if trim (setq nodename (substring nodename 0 trim))))
580 (Info-find-node (if (equal filename "") nil filename)
581 (if (equal nodename "") "Top" nodename))))
582
583 (defun Info-read-node-name (prompt &optional default)
584 (let* ((completion-ignore-case t)
585 (nodename (completing-read prompt (Info-build-node-completions))))
586 (if (equal nodename "")
587 (or default
588 (Info-read-node-name prompt))
589 nodename)))
590
591 (defun Info-build-node-completions ()
592 (or Info-current-file-completions
593 (let ((compl nil))
594 (save-excursion
595 (save-restriction
596 (if (marker-buffer Info-tag-table-marker)
597 (progn
598 (set-buffer (marker-buffer Info-tag-table-marker))
599 (widen)
600 (goto-char Info-tag-table-marker)
601 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
602 (setq compl
603 (cons (list (buffer-substring (match-beginning 1)
604 (match-end 1)))
605 compl))))
606 (widen)
607 (goto-char (point-min))
608 (while (search-forward "\n\^_" nil t)
609 (forward-line 1)
610 (let ((beg (point)))
611 (forward-line 1)
612 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
613 beg t)
614 (setq compl
615 (cons (list (buffer-substring (match-beginning 1)
616 (match-end 1)))
617 compl))))))))
618 (setq Info-current-file-completions compl))))
619 \f
620 (defun Info-restore-point (hl)
621 "If this node has been visited, restore the point value when we left."
622 (while hl
623 (if (and (equal (nth 0 (car hl)) Info-current-file)
624 (equal (nth 1 (car hl)) Info-current-node))
625 (progn
626 (goto-char (nth 2 (car hl)))
627 (setq hl nil)) ;terminate the while at next iter
628 (setq hl (cdr hl)))))
629 \f
630 (defvar Info-last-search nil
631 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
632
633 (defun Info-search (regexp)
634 "Search for REGEXP, starting from point, and select node it's found in."
635 (interactive "sSearch (regexp): ")
636 (if (equal regexp "")
637 (setq regexp Info-last-search)
638 (setq Info-last-search regexp))
639 (let ((found ()) current
640 (onode Info-current-node)
641 (ofile Info-current-file)
642 (opoint (point))
643 (osubfile Info-current-subfile))
644 (save-excursion
645 (save-restriction
646 (widen)
647 (if (null Info-current-subfile)
648 (progn (re-search-forward regexp) (setq found (point)))
649 (condition-case err
650 (progn (re-search-forward regexp) (setq found (point)))
651 (search-failed nil)))))
652 (if (not found) ;can only happen in subfile case -- else would have erred
653 (unwind-protect
654 (let ((list ()))
655 (set-buffer (marker-buffer Info-tag-table-marker))
656 (goto-char (point-min))
657 (search-forward "\n\^_\nIndirect:")
658 (save-restriction
659 (narrow-to-region (point)
660 (progn (search-forward "\n\^_")
661 (1- (point))))
662 (goto-char (point-min))
663 (search-forward (concat "\n" osubfile ": "))
664 (beginning-of-line)
665 (while (not (eobp))
666 (re-search-forward "\\(^.*\\): [0-9]+$")
667 (goto-char (+ (match-end 1) 2))
668 (setq list (cons (cons (read (current-buffer))
669 (buffer-substring (match-beginning 1)
670 (match-end 1)))
671 list))
672 (goto-char (1+ (match-end 0))))
673 (setq list (nreverse list)
674 current (car (car list))
675 list (cdr list)))
676 (while list
677 (message "Searching subfile %s..." (cdr (car list)))
678 (Info-read-subfile (car (car list)))
679 (setq list (cdr list))
680 (goto-char (point-min))
681 (if (re-search-forward regexp nil t)
682 (setq found (point) list ())))
683 (if found
684 (message "")
685 (signal 'search-failed (list regexp))))
686 (if (not found)
687 (progn (Info-read-subfile opoint)
688 (goto-char opoint)
689 (Info-select-node)))))
690 (widen)
691 (goto-char found)
692 (Info-select-node)
693 (or (and (equal onode Info-current-node)
694 (equal ofile Info-current-file))
695 (setq Info-history (cons (list ofile onode opoint)
696 Info-history)))))
697 \f
698 ;; Extract the value of the node-pointer named NAME.
699 ;; If there is none, use ERRORNAME in the error message;
700 ;; if ERRORNAME is nil, just return nil.
701 (defun Info-extract-pointer (name &optional errorname)
702 (save-excursion
703 (goto-char (point-min))
704 (forward-line 1)
705 (if (re-search-backward (concat name ":") nil t)
706 (progn
707 (goto-char (match-end 0))
708 (Info-following-node-name))
709 (if (eq errorname t)
710 nil
711 (error (concat "Node has no " (capitalize (or errorname name))))))))
712
713 ;; Return the node name in the buffer following point.
714 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
715 ;; saying which chas may appear in the node name.
716 (defun Info-following-node-name (&optional allowedchars)
717 (skip-chars-forward " \t")
718 (buffer-substring
719 (point)
720 (progn
721 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
722 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
723 (if (looking-at "(")
724 (skip-chars-forward "^)")))
725 (skip-chars-backward " ")
726 (point))))
727
728 (defun Info-next ()
729 "Go to the next node of this node."
730 (interactive)
731 (Info-goto-node (Info-extract-pointer "next")))
732
733 (defun Info-prev ()
734 "Go to the previous node of this node."
735 (interactive)
736 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
737
738 (defun Info-up ()
739 "Go to the superior node of this node."
740 (interactive)
741 (Info-goto-node (Info-extract-pointer "up"))
742 (Info-restore-point Info-history))
743
744 (defun Info-last ()
745 "Go back to the last node visited."
746 (interactive)
747 (or Info-history
748 (error "This is the first Info node you looked at"))
749 (let (filename nodename opoint)
750 (setq filename (car (car Info-history)))
751 (setq nodename (car (cdr (car Info-history))))
752 (setq opoint (car (cdr (cdr (car Info-history)))))
753 (setq Info-history (cdr Info-history))
754 (Info-find-node filename nodename)
755 (setq Info-history (cdr Info-history))
756 (goto-char opoint)))
757
758 (defun Info-directory ()
759 "Go to the Info directory node."
760 (interactive)
761 (Info-find-node "dir" "top"))
762 \f
763 (defun Info-follow-reference (footnotename)
764 "Follow cross reference named NAME to the node it refers to.
765 NAME may be an abbreviation of the reference name."
766 (interactive
767 (let ((completion-ignore-case t)
768 completions default alt-default (start-point (point)) str i bol eol)
769 (save-excursion
770 ;; Store end and beginning of line.
771 (end-of-line)
772 (setq eol (point))
773 (beginning-of-line)
774 (setq bol (point))
775
776 (goto-char (point-min))
777 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
778 (setq str (buffer-substring
779 (match-beginning 1)
780 (1- (point))))
781 ;; See if this one should be the default.
782 (and (null default)
783 (<= (match-beginning 0) start-point)
784 (<= start-point (point))
785 (setq default t))
786 ;; See if this one should be the alternate default.
787 (and (null alt-default)
788 (and (<= bol (match-beginning 0))
789 (<= (point) eol))
790 (setq alt-default t))
791 (setq i 0)
792 (while (setq i (string-match "[ \n\t]+" str i))
793 (setq str (concat (substring str 0 i) " "
794 (substring str (match-end 0))))
795 (setq i (1+ i)))
796 ;; Record as a completion and perhaps as default.
797 (if (eq default t) (setq default str))
798 (if (eq alt-default t) (setq alt-default str))
799 (setq completions
800 (cons (cons str nil)
801 completions))))
802 ;; If no good default was found, try an alternate.
803 (or default
804 (setq default alt-default))
805 ;; If only one cross-reference found, then make it default.
806 (if (eq (length completions) 1)
807 (setq default (car (car completions))))
808 (if completions
809 (let ((input (completing-read (if default
810 (concat "Follow reference named: ("
811 default ") ")
812 "Follow reference named: ")
813 completions nil t)))
814 (list (if (equal input "")
815 default input)))
816 (error "No cross-references in this node"))))
817 (let (target beg i (str (concat "\\*note " footnotename)))
818 (while (setq i (string-match " " str i))
819 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
820 (setq i (+ i 6)))
821 (save-excursion
822 (goto-char (point-min))
823 (or (re-search-forward str nil t)
824 (error "No cross-reference named %s" footnotename))
825 (goto-char (+ (match-beginning 0) 5))
826 (setq target
827 (Info-extract-menu-node-name "Bad format cross reference" t)))
828 (while (setq i (string-match "[ \t\n]+" target i))
829 (setq target (concat (substring target 0 i) " "
830 (substring target (match-end 0))))
831 (setq i (+ i 1)))
832 (Info-goto-node target)))
833
834 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
835 (skip-chars-forward " \t\n")
836 (let ((beg (point))
837 str i)
838 (skip-chars-forward "^:")
839 (forward-char 1)
840 (setq str
841 (if (looking-at ":")
842 (buffer-substring beg (1- (point)))
843 (skip-chars-forward " \t\n")
844 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
845 (while (setq i (string-match "\n" str i))
846 (aset str i ?\ ))
847 str))
848
849 ;; No one calls this.
850 ;;(defun Info-menu-item-sequence (list)
851 ;; (while list
852 ;; (Info-menu (car list))
853 ;; (setq list (cdr list))))
854
855 (defun Info-complete-menu-item (string predicate action)
856 (let ((case-fold-search t))
857 (cond ((eq action nil)
858 (let (completions
859 (pattern (concat "\n\\* \\("
860 (regexp-quote string)
861 "[^:\t\n]*\\):")))
862 (save-excursion
863 (set-buffer Info-complete-menu-buffer)
864 (goto-char (point-min))
865 (while (re-search-forward pattern nil t)
866 (setq completions (cons (cons (format "%s"
867 (buffer-substring
868 (match-beginning 1)
869 (match-end 1)))
870 (match-beginning 1))
871 completions))))
872 (try-completion string completions predicate)))
873 ((eq action t)
874 (let (completions
875 (pattern (concat "\n\\* \\("
876 (regexp-quote string)
877 "[^:\t\n]*\\):")))
878 (save-excursion
879 (set-buffer Info-complete-menu-buffer)
880 (goto-char (point-min))
881 (while (re-search-forward pattern nil t)
882 (setq completions (cons (cons (format "%s"
883 (buffer-substring
884 (match-beginning 1)
885 (match-end 1)))
886 (match-beginning 1))
887 completions))))
888 (all-completions string completions predicate)))
889 (t
890 (save-excursion
891 (set-buffer Info-complete-menu-buffer)
892 (goto-char (point-min))
893 (re-search-forward (concat "\n\\* "
894 (regexp-quote string)
895 ":")
896 nil t))))))
897
898
899 (defun Info-menu (menu-item)
900 "Go to node for menu item named (or abbreviated) NAME.
901 Completion is allowed, and the menu item point is on is the default."
902 (interactive
903 (let ((completions '())
904 ;; If point is within a menu item, use that item as the default
905 (default nil)
906 (p (point))
907 (last nil))
908 (save-excursion
909 (goto-char (point-min))
910 (if (not (search-forward "\n* menu:" nil t))
911 (error "No menu in this node"))
912 (setq beg (point))
913 (and (< (point) p)
914 (save-excursion
915 (goto-char p)
916 (end-of-line)
917 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t)
918 (setq default (format "%s" (buffer-substring
919 (match-beginning 1)
920 (match-end 1)))))))
921 (let ((item nil))
922 (while (null item)
923 (setq item (let ((completion-ignore-case t)
924 (Info-complete-menu-buffer (current-buffer)))
925 (completing-read (if default
926 (format "Menu item (default %s): "
927 default)
928 "Menu item: ")
929 'Info-complete-menu-item nil t)))
930 ;; we rely on the fact that completing-read accepts an input
931 ;; of "" even when the require-match argument is true and ""
932 ;; is not a valid possibility
933 (if (string= item "")
934 (if default
935 (setq item default)
936 ;; ask again
937 (setq item nil))))
938 (list item))))
939 ;; there is a problem here in that if several menu items have the same
940 ;; name you can only go to the node of the first with this command.
941 (Info-goto-node (Info-extract-menu-item menu-item)))
942
943 (defun Info-extract-menu-item (menu-item)
944 (setq menu-item (regexp-quote menu-item))
945 (save-excursion
946 (goto-char (point-min))
947 (or (search-forward "\n* menu:" nil t)
948 (error "No menu in this node"))
949 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
950 (re-search-forward (concat "\n\\* " menu-item) nil t)
951 (error "No such item in menu"))
952 (beginning-of-line)
953 (forward-char 2)
954 (Info-extract-menu-node-name)))
955
956 ;; If COUNT is nil, use the last item in the menu.
957 (defun Info-extract-menu-counting (count)
958 (save-excursion
959 (goto-char (point-min))
960 (or (search-forward "\n* menu:" nil t)
961 (error "No menu in this node"))
962 (if count
963 (or (search-forward "\n* " nil t count)
964 (error "Too few items in menu"))
965 (while (search-forward "\n* " nil t)
966 nil))
967 (Info-extract-menu-node-name)))
968
969 (defun Info-nth-menu-item ()
970 "Go to the node of the Nth menu item.
971 N is the digit argument used to invoke this command."
972 (interactive)
973 (Info-goto-node
974 (Info-extract-menu-counting
975 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
976
977 (defun Info-top-node ()
978 "Go to the Top node of this file."
979 (interactive)
980 (Info-goto-node "Top"))
981
982 (defun Info-final-node ()
983 "Go to the final node in this file."
984 (interactive)
985 (Info-goto-node "Top")
986 (let (Info-history)
987 ;; Go to the last node in the menu of Top.
988 (Info-goto-node (Info-extract-menu-counting nil))
989 ;; If the last node in the menu is not last in pointer structure,
990 ;; move forward until we can't go any farther.
991 (while (Info-forward-node t t) nil)
992 ;; Then keep moving down to last subnode, unless we reach an index.
993 (while (and (not (string-match "\\<index\\>" Info-current-node))
994 (save-excursion (search-forward "\n* Menu:" nil t)))
995 (Info-goto-node (Info-extract-menu-counting nil)))))
996
997 (defun Info-forward-node (&optional not-down no-error)
998 "Go forward one node, considering all nodes as forming one sequence."
999 (interactive)
1000 (goto-char (point-min))
1001 (forward-line 1)
1002 ;; three possibilities, in order of priority:
1003 ;; 1. next node is in a menu in this node (but not in an index)
1004 ;; 2. next node is next at same level
1005 ;; 3. next node is up and next
1006 (cond ((and (not not-down)
1007 (save-excursion (search-forward "\n* menu:" nil t))
1008 (not (string-match "\\<index\\>" Info-current-node)))
1009 (Info-goto-node (Info-extract-menu-counting 1))
1010 t)
1011 ((save-excursion (search-backward "next:" nil t))
1012 (Info-next)
1013 t)
1014 ((and (save-excursion (search-backward "up:" nil t))
1015 (not (equal (downcase (Info-extract-pointer "up")) "top")))
1016 (let ((old-node Info-current-node))
1017 (Info-up)
1018 (let (Info-history success)
1019 (unwind-protect
1020 (setq success (Info-forward-node t no-error))
1021 (or success (Info-goto-node old-node))))))
1022 (no-error nil)
1023 (t (error "No pointer forward from this node"))))
1024
1025 (defun Info-backward-node ()
1026 "Go backward one node, considering all nodes as forming one sequence."
1027 (interactive)
1028 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1029 (upnode (Info-extract-pointer "up" t)))
1030 (cond ((and upnode (string-match "(" upnode))
1031 (error "First node in file"))
1032 ((and upnode (or (null prevnode)
1033 (equal (downcase prevnode) (downcase upnode))))
1034 (Info-up))
1035 (prevnode
1036 ;; If we move back at the same level,
1037 ;; go down to find the last subnode*.
1038 (Info-prev)
1039 (let (Info-history)
1040 (while (and (not (string-match "\\<index\\>" Info-current-node))
1041 (save-excursion (search-forward "\n* Menu:" nil t)))
1042 (Info-goto-node (Info-extract-menu-counting nil)))))
1043 (t
1044 (error "No pointer backward from this node")))))
1045
1046 (defun Info-exit ()
1047 "Exit Info by selecting some other buffer."
1048 (interactive)
1049 (if Info-standalone
1050 (save-buffers-kill-emacs)
1051 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1052 (bury-buffer (current-buffer))))))
1053
1054 (defun Info-next-menu-item ()
1055 (interactive)
1056 (save-excursion
1057 (forward-line -1)
1058 (search-forward "\n* menu:" nil t)
1059 (or (search-forward "\n* " nil t)
1060 (error "No more items in menu"))
1061 (Info-goto-node (Info-extract-menu-node-name))))
1062
1063 (defun Info-last-menu-item ()
1064 (interactive)
1065 (save-excursion
1066 (forward-line 1)
1067 (search-backward "\n* menu:" nil t)
1068 (or (search-backward "\n* " nil t)
1069 (error "No previous items in menu"))
1070 (Info-goto-node (Info-extract-menu-node-name))))
1071
1072 (defmacro Info-no-error (&rest body)
1073 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1074
1075 (defun Info-next-preorder ()
1076 "Go to the next node, popping up a level if there is none."
1077 (interactive)
1078 (cond ((Info-no-error (Info-next-menu-item)) )
1079 ((Info-no-error (Info-up)) (forward-line 1))
1080 (t (error "No more nodes"))))
1081
1082 (defun Info-last-preorder ()
1083 "Go to the last node, popping up a level if there is none."
1084 (interactive)
1085 (cond ((Info-no-error (Info-last-menu-item)) )
1086 ((Info-no-error (Info-up)) (forward-line -1))
1087 (t (error "No previous nodes"))))
1088
1089 (defun Info-scroll-up ()
1090 "Read the next screen. If end of buffer is visible, go to next entry."
1091 (interactive)
1092 (if (pos-visible-in-window-p (point-max))
1093 (Info-next-preorder)
1094 (scroll-up)))
1095
1096 (defun Info-scroll-down ()
1097 "Read the previous screen. If start of buffer is visible, go to last entry."
1098 (interactive)
1099 (if (pos-visible-in-window-p (point-min))
1100 (Info-last-preorder)
1101 (scroll-down)))
1102
1103 (defun Info-next-reference ()
1104 "Move cursor to the next cross-reference or menu item in the node."
1105 (interactive)
1106 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1107 (old-pt (point)))
1108 (or (eobp) (forward-char 1))
1109 (or (re-search-forward pat nil t)
1110 (progn
1111 (goto-char (point-min))
1112 (or (re-search-forward pat nil t)
1113 (progn
1114 (goto-char old-pt)
1115 (error "No cross references in this node")))))
1116 (goto-char (match-beginning 0))
1117 (if (looking-at "\\* Menu:")
1118 (Info-next-reference))))
1119
1120 (defun Info-prev-reference ()
1121 "Move cursor to the previous cross-reference or menu item in the node."
1122 (interactive)
1123 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1124 (old-pt (point)))
1125 (or (re-search-backward pat nil t)
1126 (progn
1127 (goto-char (point-max))
1128 (or (re-search-backward pat nil t)
1129 (progn
1130 (goto-char old-pt)
1131 (error "No cross references in this node")))))
1132 (goto-char (match-beginning 0))
1133 (if (looking-at "\\* Menu:")
1134 (Info-prev-reference))))
1135
1136 (defun Info-index (topic)
1137 "Look up a string in the index for this file.
1138 The index is defined as the first node in the top-level menu whose
1139 name contains the word \"Index\", plus any immediately following
1140 nodes whose names also contain the word \"Index\".
1141 If there are no exact matches to the specified topic, this chooses
1142 the first match which is a case-insensitive substring of a topic.
1143 Use the `,' command to see the other matches.
1144 Give a blank topic name to go to the Index node itself."
1145 (interactive "sIndex topic: ")
1146 (let ((orignode Info-current-node)
1147 (rnode nil)
1148 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
1149 (regexp-quote topic)))
1150 node)
1151 (Info-goto-node "Top")
1152 (or (search-forward "\n* menu:" nil t)
1153 (error "No index"))
1154 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1155 (error "No index"))
1156 (goto-char (match-beginning 1))
1157 (let ((Info-keeping-history nil))
1158 (Info-goto-node (Info-extract-menu-node-name)))
1159 (or (equal topic "")
1160 (let ((matches nil)
1161 (exact nil)
1162 (Info-keeping-history nil)
1163 found)
1164 (while
1165 (progn
1166 (goto-char (point-min))
1167 (while (re-search-forward pattern nil t)
1168 (setq matches
1169 (cons (list (buffer-substring (match-beginning 1)
1170 (match-end 1))
1171 (buffer-substring (match-beginning 2)
1172 (match-end 2))
1173 Info-current-node
1174 (string-to-int (concat "0"
1175 (buffer-substring
1176 (match-beginning 3)
1177 (match-end 3)))))
1178 matches)))
1179 (and (setq node (Info-extract-pointer "next" t))
1180 (string-match "\\<Index\\>" node)))
1181 (Info-goto-node node))
1182 (or matches
1183 (progn
1184 (Info-last)
1185 (error "No \"%s\" in index" topic)))
1186 ;; Here it is a feature that assoc is case-sensitive.
1187 (while (setq found (assoc topic matches))
1188 (setq exact (cons found exact)
1189 matches (delq found matches)))
1190 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1191 (Info-index-next 0)))))
1192
1193 (defun Info-index-next (num)
1194 "Go to the next matching index item from the last `i' command."
1195 (interactive "p")
1196 (or Info-index-alternatives
1197 (error "No previous `i' command in this file"))
1198 (while (< num 0)
1199 (setq num (+ num (length Info-index-alternatives))))
1200 (while (> num 0)
1201 (setq Info-index-alternatives
1202 (nconc (cdr Info-index-alternatives)
1203 (list (car Info-index-alternatives)))
1204 num (1- num)))
1205 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1206 (if (> (nth 3 (car Info-index-alternatives)) 0)
1207 (forward-line (nth 3 (car Info-index-alternatives)))
1208 (forward-line 3) ; don't search in headers
1209 (let ((name (car (car Info-index-alternatives))))
1210 (if (or (re-search-forward (format
1211 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1212 (regexp-quote name)) nil t)
1213 (search-forward (format "`%s'" name) nil t)
1214 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1215 (search-forward
1216 (format "`%s'" (substring name 0 (match-beginning 1)))
1217 nil t))
1218 (search-forward name nil t))
1219 (beginning-of-line)
1220 (goto-char (point-min)))))
1221 (message "Found \"%s\" in %s. %s"
1222 (car (car Info-index-alternatives))
1223 (nth 2 (car Info-index-alternatives))
1224 (if (cdr Info-index-alternatives)
1225 "(Press `,' for more)"
1226 "(Only match)")))
1227
1228 (defun Info-undefined ()
1229 "Make command be undefined in Info."
1230 (interactive)
1231 (ding))
1232
1233 (defun Info-help ()
1234 "Enter the Info tutorial."
1235 (interactive)
1236 (delete-other-windows)
1237 (Info-find-node "info"
1238 (if (< (window-height) 23)
1239 "Help-Small-Screen"
1240 "Help")))
1241
1242 (defun Info-summary ()
1243 "Display a brief summary of all Info commands."
1244 (interactive)
1245 (save-window-excursion
1246 (switch-to-buffer "*Help*")
1247 (erase-buffer)
1248 (insert (documentation 'Info-mode))
1249 (goto-char (point-min))
1250 (let (ch flag)
1251 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1252 (message (if flag "Type Space to see more"
1253 "Type Space to return to Info"))
1254 (if (not (eq ?\ (setq ch (read-event))))
1255 (progn (setq unread-command-events (list ch)) nil)
1256 flag))
1257 (scroll-up)))
1258 (bury-buffer "*Help*")))
1259 \f
1260 (defun Info-get-token (pos start all &optional errorstring)
1261 "Return the token around POS,
1262 POS must be somewhere inside the token
1263 START is a regular expression which will match the
1264 beginning of the tokens delimited string
1265 ALL is a regular expression with a single
1266 parenthized subpattern which is the token to be
1267 returned. E.g. '{\(.*\)}' would return any string
1268 enclosed in braces around POS.
1269 SIG optional fourth argument, controls action on no match
1270 nil: return nil
1271 t: beep
1272 a string: signal an error, using that string."
1273 (save-excursion
1274 (goto-char pos)
1275 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1276 (let (found)
1277 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1278 (not (setq found (and (<= (match-beginning 0) pos)
1279 (> (match-end 0) pos))))))
1280 (if (and found (<= (match-beginning 0) pos)
1281 (> (match-end 0) pos))
1282 (buffer-substring (match-beginning 1) (match-end 1))
1283 (cond ((null errorstring)
1284 nil)
1285 ((eq errorstring t)
1286 (beep)
1287 nil)
1288 (t
1289 (error "No %s around position %d" errorstring pos)))))))
1290
1291 (defun Info-mouse-follow-nearest-node (click)
1292 "\\<Info-mode-map>Follow a node reference near point.
1293 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1294 At end of the node's text, moves to the next node, or up if none."
1295 (interactive "e")
1296 (let* ((start (event-start click))
1297 (window (car start))
1298 (pos (car (cdr start))))
1299 (select-window window)
1300 (goto-char pos))
1301 (and (not (Info-try-follow-nearest-node))
1302 (save-excursion (forward-line 1) (eobp))
1303 (Info-next-preorder)))
1304
1305 (defun Info-follow-nearest-node ()
1306 "\\<Info-mode-map>Follow a node reference near point.
1307 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1308 If no reference to follow, moves to the next node, or up if none."
1309 (interactive)
1310 (or (Info-try-follow-nearest-node)
1311 (Info-next-preorder)))
1312
1313 ;; Common subroutine.
1314 (defun Info-try-follow-nearest-node ()
1315 "Follow a node reference near point. Return non-nil if successful."
1316 (let (node)
1317 (cond
1318 ((setq node (Info-get-token (point) "\\*note[ \n]"
1319 "\\*note[ \n]\\([^:]*\\):"))
1320 (Info-follow-reference node))
1321 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1322 (Info-goto-node node))
1323 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1324 (Info-menu node))
1325 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1326 (Info-goto-node node))
1327 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1328 (Info-goto-node node))
1329 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1330 (Info-goto-node "Top"))
1331 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1332 (Info-goto-node node)))
1333 node))
1334 \f
1335 (defvar Info-mode-map nil
1336 "Keymap containing Info commands.")
1337 (if Info-mode-map
1338 nil
1339 (setq Info-mode-map (make-keymap))
1340 (suppress-keymap Info-mode-map)
1341 (define-key Info-mode-map "." 'beginning-of-buffer)
1342 (define-key Info-mode-map " " 'Info-scroll-up)
1343 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1344 (define-key Info-mode-map "\t" 'Info-next-reference)
1345 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1346 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1347 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1348 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1349 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1350 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1351 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1352 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1353 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1354 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1355 (define-key Info-mode-map "0" 'undefined)
1356 (define-key Info-mode-map "?" 'Info-summary)
1357 (define-key Info-mode-map "]" 'Info-forward-node)
1358 (define-key Info-mode-map "[" 'Info-backward-node)
1359 (define-key Info-mode-map "<" 'Info-top-node)
1360 (define-key Info-mode-map ">" 'Info-final-node)
1361 (define-key Info-mode-map "b" 'beginning-of-buffer)
1362 (define-key Info-mode-map "d" 'Info-directory)
1363 (define-key Info-mode-map "e" 'Info-edit)
1364 (define-key Info-mode-map "f" 'Info-follow-reference)
1365 (define-key Info-mode-map "g" 'Info-goto-node)
1366 (define-key Info-mode-map "h" 'Info-help)
1367 (define-key Info-mode-map "i" 'Info-index)
1368 (define-key Info-mode-map "l" 'Info-last)
1369 (define-key Info-mode-map "m" 'Info-menu)
1370 (define-key Info-mode-map "n" 'Info-next)
1371 (define-key Info-mode-map "p" 'Info-prev)
1372 (define-key Info-mode-map "q" 'Info-exit)
1373 (define-key Info-mode-map "s" 'Info-search)
1374 (define-key Info-mode-map "t" 'Info-top-node)
1375 (define-key Info-mode-map "u" 'Info-up)
1376 (define-key Info-mode-map "," 'Info-index-next)
1377 (define-key Info-mode-map "\177" 'Info-scroll-down)
1378 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1379 )
1380 \f
1381 ;; Info mode is suitable only for specially formatted data.
1382 (put 'info-mode 'mode-class 'special)
1383
1384 (defun Info-mode ()
1385 "\\<Info-mode-map>
1386 Info mode provides commands for browsing through the Info documentation tree.
1387 Documentation in Info is divided into \"nodes\", each of which discusses
1388 one topic and contains references to other nodes which discuss related
1389 topics. Info has commands to follow the references and show you other nodes.
1390
1391 \\[Info-help] Invoke the Info tutorial.
1392
1393 Selecting other nodes:
1394 \\[Info-next] Move to the \"next\" node of this node.
1395 \\[Info-prev] Move to the \"previous\" node of this node.
1396 \\[Info-up] Move \"up\" from this node.
1397 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1398 Picking a menu item causes another node to be selected.
1399 \\[Info-directory] Go to the Info directory node.
1400 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1401 \\[Info-last] Move to the last node you were at.
1402 \\[Info-index] Look up a topic in this file's Index and move to that node.
1403 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1404
1405 Moving within a node:
1406 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1407 already visible, try to go to the next menu entry, or up if there is none.
1408 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1409 already visible, try to go to the previous menu entry, or up if there is none.
1410 \\[beginning-of-buffer] Go to beginning of node.
1411
1412 Advanced commands:
1413 \\[Info-exit] Quit Info: reselect previously selected buffer.
1414 \\[Info-edit] Edit contents of selected node.
1415 1 Pick first item in node's menu.
1416 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1417 \\[Info-goto-node] Move to node specified by name.
1418 You may include a filename as well, as (FILENAME)NODENAME.
1419 \\[universal-argument] \\[info] Move to new Info file with completion.
1420 \\[Info-search] Search through this Info file for specified regexp,
1421 and select the node in which the next occurrence is found.
1422 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1423 and if that fails try to move up, and if that fails, tell user
1424 he/she is done reading.
1425 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1426 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1427 (kill-all-local-variables)
1428 (setq major-mode 'Info-mode)
1429 (setq mode-name "Info")
1430 (use-local-map Info-mode-map)
1431 (set-syntax-table text-mode-syntax-table)
1432 (setq local-abbrev-table text-mode-abbrev-table)
1433 (setq case-fold-search t)
1434 (setq buffer-read-only t)
1435 (make-local-variable 'Info-current-file)
1436 (make-local-variable 'Info-current-subfile)
1437 (make-local-variable 'Info-current-node)
1438 (make-local-variable 'Info-tag-table-marker)
1439 (make-local-variable 'Info-history)
1440 (make-local-variable 'Info-index-alternatives)
1441 (if (fboundp 'make-face)
1442 (progn
1443 (make-face 'info-node)
1444 (make-face 'info-menu-5)
1445 (make-face 'info-xref)
1446 (or (face-differs-from-default-p 'info-node)
1447 (if (face-differs-from-default-p 'bold-italic)
1448 (copy-face 'bold-italic 'info-node)
1449 (copy-face 'bold 'info-node)))
1450 (or (face-differs-from-default-p 'info-menu-5)
1451 (set-face-underline-p 'info-menu-5 t))
1452 (or (face-differs-from-default-p 'info-xref)
1453 (copy-face 'bold 'info-xref)))
1454 (setq Info-fontify nil))
1455 (Info-set-mode-line)
1456 (run-hooks 'Info-mode-hook))
1457
1458 (defvar Info-edit-map nil
1459 "Local keymap used within `e' command of Info.")
1460 (if Info-edit-map
1461 nil
1462 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1463 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1464
1465 ;; Info-edit mode is suitable only for specially formatted data.
1466 (put 'info-edit-mode 'mode-class 'special)
1467
1468 (defun Info-edit-mode ()
1469 "Major mode for editing the contents of an Info node.
1470 Like text mode with the addition of `Info-cease-edit'
1471 which returns to Info mode for browsing.
1472 \\{Info-edit-map}"
1473 )
1474
1475 (defun Info-edit ()
1476 "Edit the contents of this Info node.
1477 Allowed only if variable `Info-enable-edit' is non-nil."
1478 (interactive)
1479 (or Info-enable-edit
1480 (error "Editing info nodes is not enabled"))
1481 (use-local-map Info-edit-map)
1482 (setq major-mode 'Info-edit-mode)
1483 (setq mode-name "Info Edit")
1484 (kill-local-variable 'mode-line-buffer-identification)
1485 (setq buffer-read-only nil)
1486 ;; Make mode line update.
1487 (set-buffer-modified-p (buffer-modified-p))
1488 (message (substitute-command-keys
1489 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1490
1491 (defun Info-cease-edit ()
1492 "Finish editing Info node; switch back to Info proper."
1493 (interactive)
1494 ;; Do this first, so nothing has changed if user C-g's at query.
1495 (and (buffer-modified-p)
1496 (y-or-n-p "Save the file? ")
1497 (save-buffer))
1498 (use-local-map Info-mode-map)
1499 (setq major-mode 'Info-mode)
1500 (setq mode-name "Info")
1501 (Info-set-mode-line)
1502 (setq buffer-read-only t)
1503 ;; Make mode line update.
1504 (set-buffer-modified-p (buffer-modified-p))
1505 (and (marker-position Info-tag-table-marker)
1506 (buffer-modified-p)
1507 (message "Tags may have changed. Use Info-tagify if necessary")))
1508 \f
1509 (defun Info-find-emacs-command-nodes (command)
1510 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1511 The locations are of the format used in Info-history, i.e.
1512 \(FILENAME NODENAME BUFFERPOS\)."
1513 (require 'info)
1514 (let ((where '())
1515 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1516 ":\\s *\\(.*\\)\\.$")))
1517 (save-excursion
1518 (Info-find-node "emacs" "Command Index")
1519 ;; Take the index node off the Info history.
1520 (setq Info-history (cdr Info-history))
1521 (goto-char (point-max))
1522 (while (re-search-backward cmd-desc nil t)
1523 (setq where (cons (list Info-current-file
1524 (buffer-substring
1525 (match-beginning 1)
1526 (match-end 1))
1527 0)
1528 where)))
1529 where)))
1530
1531 ;;;###autoload
1532 (defun Info-goto-emacs-command-node (command)
1533 "Go to the Info node in the Emacs manual for command COMMAND.
1534 The command is found by looking up in Emacs manual's Command Index."
1535 (interactive "CFind documentation for command: ")
1536 (or (commandp command)
1537 (signal 'wrong-type-argument (list 'commandp command)))
1538 (let ((where (Info-find-emacs-command-nodes command)))
1539 (if where
1540 (let ((num-matches (length where)))
1541 ;; Get Info running, and pop to it in another window.
1542 (save-window-excursion
1543 (info))
1544 (pop-to-buffer "*info*")
1545 (Info-find-node (car (car where))
1546 (car (cdr (car where))))
1547 (if (> num-matches 1)
1548 (progn
1549 ;; Info-find-node already pushed (car where) onto
1550 ;; Info-history. Put the other nodes that were found on
1551 ;; the history.
1552 (setq Info-history (nconc (cdr where) Info-history))
1553 (message (substitute-command-keys
1554 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1555 (1- num-matches)
1556 (if (> num-matches 2) "ies" "y")
1557 (if (> num-matches 2) "them" "it")))))
1558 (error "Couldn't find documentation for %s." command))))
1559
1560 ;;;###autoload
1561 (defun Info-goto-emacs-key-command-node (key)
1562 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1563 Interactively, if the binding is execute-extended-command, a command is read.
1564 The command is found by looking up in Emacs manual's Command Index."
1565 (interactive "kFind documentation for key:")
1566 (let ((command (key-binding key)))
1567 (cond ((null command)
1568 (message "%s is undefined" (key-description key)))
1569 ((and (interactive-p)
1570 (eq command 'execute-extended-command))
1571 (Info-goto-emacs-command-node
1572 (read-command "Find documentation for command: ")))
1573 (t
1574 (Info-goto-emacs-command-node command)))))
1575 \f
1576 (defun Info-fontify-node ()
1577 (save-excursion
1578 (let ((buffer-read-only nil))
1579 (goto-char (point-min))
1580 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1581 (progn
1582 (goto-char (match-end 0))
1583 (while
1584 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1585 (goto-char (match-end 0))
1586 (put-text-property (match-beginning 1) (match-end 1)
1587 'face 'info-xref)
1588 (put-text-property (match-beginning 1) (match-end 1)
1589 'mouse-face 'highlight))))
1590 (goto-char (point-min))
1591 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
1592 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1593 nil
1594 (put-text-property (match-beginning 1) (match-end 1)
1595 'face 'info-xref)
1596 (put-text-property (match-beginning 1) (match-end 1)
1597 'mouse-face 'highlight)))
1598 (goto-char (point-min))
1599 (if (and (search-forward "\n* Menu:" nil t)
1600 (not (string-match "\\<Index\\>" Info-current-node))
1601 ;; Don't take time to annotate huge menus
1602 (< (- (point-max) (point)) 30000))
1603 (let ((n 0))
1604 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1605 (setq n (1+ n))
1606 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
1607 (put-text-property (match-beginning 0)
1608 (1+ (match-beginning 0))
1609 'face 'info-menu-5))
1610 (put-text-property (match-beginning 1) (match-end 1)
1611 'face 'info-node)
1612 (put-text-property (match-beginning 1) (match-end 1)
1613 'mouse-face 'highlight))))
1614 (set-buffer-modified-p nil))))
1615
1616 (provide 'info)
1617
1618 ;;; info.el ends here