]> code.delx.au - gnu-emacs/blob - lisp/info.el
Use cl only at compile time.
[gnu-emacs] / lisp / info.el
1 ;;; info.el --- info package for Emacs.
2
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97 Free Software
4 ;; Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: help
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29
30 ;;; Code:
31
32 (defgroup info nil
33 "Info subsystem"
34 :group 'help
35 :group 'docs)
36
37
38 (defvar Info-history nil
39 "List of info nodes user has visited.
40 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
41
42 (defcustom Info-enable-edit nil
43 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
44 This is convenient if you want to write info files by hand.
45 However, we recommend that you not do this.
46 It is better to write a Texinfo file and generate the Info file from that,
47 because that gives you a printed manual as well."
48 :type 'boolean
49 :group 'info)
50
51 (defvar Info-enable-active-nodes nil
52 "Non-nil allows Info to execute Lisp code associated with nodes.
53 The Lisp code is executed when the node is selected.")
54 (put 'Info-enable-active-nodes 'risky-local-variable t)
55
56 (defcustom Info-fontify t
57 "*Non-nil enables highlighting and fonts in Info nodes."
58 :type 'boolean
59 :group 'info)
60
61 (defcustom Info-fontify-maximum-menu-size 30000
62 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
63 :type 'integer
64 :group 'info)
65
66 (defvar Info-directory-list
67 (let ((path (getenv "INFOPATH"))
68 ;; This is for older Emacs versions
69 ;; which might get this info.el from the Texinfo distribution.
70 (path-separator (if (boundp 'path-separator) path-separator
71 (if (eq system-type 'ms-dos) ";" ":")))
72 (source (expand-file-name "info/" source-directory))
73 (sibling (if installation-directory
74 (expand-file-name "info/" installation-directory)))
75 alternative)
76 (if path
77 (let ((list nil)
78 idx)
79 (while (> (length path) 0)
80 (setq idx (or (string-match path-separator path) (length path))
81 list (cons (substring path 0 idx) list)
82 path (substring path (min (1+ idx)
83 (length path)))))
84 (nreverse list))
85 (if (and sibling (file-exists-p sibling))
86 (setq alternative sibling)
87 (setq alternative source))
88 (if (or (member alternative Info-default-directory-list)
89 (not (file-exists-p alternative))
90 ;; On DOS/NT, we use movable executables always,
91 ;; and we must always find the Info dir at run time.
92 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
93 nil
94 ;; Use invocation-directory for Info only if we used it for
95 ;; exec-directory also.
96 (not (string= exec-directory
97 (expand-file-name "lib-src/"
98 installation-directory)))))
99 Info-default-directory-list
100 (reverse (cons alternative
101 (cdr (reverse Info-default-directory-list)))))))
102 "List of directories to search for Info documentation files.
103 nil means not yet initialized. In this case, Info uses the environment
104 variable INFOPATH to initialize it, or `Info-default-directory-list'
105 if there is no INFOPATH variable in the environment.
106 The last element of `Info-default-directory-list' is the directory
107 where Emacs installs the Info files that come with it.
108
109 If you run the Emacs executable from the `src' directory in the Emacs
110 source tree, the `info' directory in the source tree is used as the last
111 element, in place of the installation Info directory. This is useful
112 when you run a version of Emacs without installing it.")
113
114 (defcustom Info-additional-directory-list nil
115 "List of additional directories to search for Info documentation files.
116 These directories are not searched for merging the `dir' file."
117 :type '(repeat directory)
118 :group 'info)
119
120 (defvar Info-current-file nil
121 "Info file that Info is now looking at, or nil.
122 This is the name that was specified in Info, not the actual file name.
123 It doesn't contain directory names or file name extensions added by Info.")
124
125 (defvar Info-current-subfile nil
126 "Info subfile that is actually in the *info* buffer now,
127 or nil if current info file is not split into subfiles.")
128
129 (defvar Info-current-node nil
130 "Name of node that Info is now looking at, or nil.")
131
132 (defvar Info-tag-table-marker nil
133 "Marker pointing at beginning of current Info file's tag table.
134 Marker points nowhere if file has no tag table.")
135
136 (defvar Info-tag-table-buffer nil
137 "Buffer used for indirect tag tables.")
138
139 (defvar Info-current-file-completions nil
140 "Cached completion list for current Info file.")
141
142 (defvar Info-index-alternatives nil
143 "List of possible matches for last Info-index command.")
144
145 (defvar Info-standalone nil
146 "Non-nil if Emacs was started solely as an Info browser.")
147
148 (defvar Info-suffix-list
149 (if (eq system-type 'ms-dos)
150 '( (".gz" . "gunzip")
151 (".z" . "gunzip")
152 (".inf" . nil)
153 ("" . nil))
154 '( (".info.Z" . "uncompress")
155 (".info.Y" . "unyabba")
156 (".info.gz" . "gunzip")
157 (".info.z" . "gunzip")
158 (".info" . nil)
159 (".Z" . "uncompress")
160 (".Y" . "unyabba")
161 (".gz" . "gunzip")
162 (".z" . "gunzip")
163 ("" . nil)))
164 "List of file name suffixes and associated decoding commands.
165 Each entry should be (SUFFIX . STRING); the file is given to
166 the command as standard input. If STRING is nil, no decoding is done.
167 Because the SUFFIXes are tried in order, the empty string should
168 be last in the list.")
169
170 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
171 ;; First, on ms-dos, delete some of the extension in FILENAME
172 ;; to make room.
173 (defun info-insert-file-contents-1 (filename suffix)
174 (if (not (eq system-type 'ms-dos))
175 (concat filename suffix)
176 (let* ((sans-exts (file-name-sans-extension filename))
177 ;; How long is the extension in FILENAME (not counting the dot).
178 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
179 ext-left)
180 ;; SUFFIX starts with a dot. If FILENAME already has one,
181 ;; get rid of the one in SUFFIX (unless suffix is empty).
182 (or (and (<= ext-len 0)
183 (not (eq (aref filename (1- (length filename))) ?.)))
184 (= (length suffix) 0)
185 (setq suffix (substring suffix 1)))
186 ;; How many chars of that extension should we keep?
187 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
188 ;; Get rid of the rest of the extension, and add SUFFIX.
189 (concat (substring filename 0 (- (length filename)
190 (- ext-len ext-left)))
191 suffix))))
192
193 (defun info-insert-file-contents (filename &optional visit)
194 "Insert the contents of an info file in the current buffer.
195 Do the right thing if the file has been compressed or zipped."
196 (let ((tail Info-suffix-list)
197 fullname decoder)
198 (if (file-exists-p filename)
199 ;; FILENAME exists--see if that name contains a suffix.
200 ;; If so, set DECODE accordingly.
201 (progn
202 (while (and tail
203 (not (string-match
204 (concat (regexp-quote (car (car tail))) "$")
205 filename)))
206 (setq tail (cdr tail)))
207 (setq fullname filename
208 decoder (cdr (car tail))))
209 ;; Try adding suffixes to FILENAME and see if we can find something.
210 (while (and tail
211 (not (file-exists-p (info-insert-file-contents-1
212 filename (car (car tail))))))
213 (setq tail (cdr tail)))
214 ;; If we found a file with a suffix, set DECODER according to the suffix
215 ;; and set FULLNAME to the file's actual name.
216 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
217 decoder (cdr (car tail)))
218 (or tail
219 (error "Can't find %s or any compressed version of it" filename)))
220 ;; check for conflict with jka-compr
221 (if (and (featurep 'jka-compr)
222 (jka-compr-installed-p)
223 (jka-compr-get-compression-info fullname))
224 (setq decoder nil))
225 (insert-file-contents fullname visit)
226 (if decoder
227 (let ((buffer-read-only nil)
228 (default-directory (or (file-name-directory fullname)
229 default-directory)))
230 (call-process-region (point-min) (point-max) decoder t t)))))
231
232 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
233
234 ;;;###autoload
235 (defun info (&optional file)
236 "Enter Info, the documentation browser.
237 Optional argument FILE specifies the file to examine;
238 the default is the top-level directory of Info.
239
240 In interactive use, a prefix argument directs this command
241 to read a file name from the minibuffer.
242
243 The search path for Info files is in the variable `Info-directory-list'.
244 The top-level Info directory is made by combining all the files named `dir'
245 in all the directories in that path."
246 (interactive (if current-prefix-arg
247 (list (read-file-name "Info file name: " nil nil t))))
248 (if file
249 (Info-goto-node (concat "(" file ")"))
250 (if (get-buffer "*info*")
251 (pop-to-buffer "*info*")
252 (Info-directory))))
253
254 ;;;###autoload
255 (defun info-standalone ()
256 "Run Emacs as a standalone Info reader.
257 Usage: emacs -f info-standalone [filename]
258 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
259 (setq Info-standalone t)
260 (if (and command-line-args-left
261 (not (string-match "^-" (car command-line-args-left))))
262 (condition-case err
263 (progn
264 (info (car command-line-args-left))
265 (setq command-line-args-left (cdr command-line-args-left)))
266 (error (send-string-to-terminal
267 (format "%s\n" (if (eq (car-safe err) 'error)
268 (nth 1 err) err)))
269 (save-buffers-kill-emacs)))
270 (info)))
271
272 ;; Go to an info node specified as separate filename and nodename.
273 ;; no-going-back is non-nil if recovering from an error in this function;
274 ;; it says do not attempt further (recursive) error recovery.
275 (defun Info-find-node (filename nodename &optional no-going-back)
276 ;; Convert filename to lower case if not found as specified.
277 ;; Expand it.
278 (if filename
279 (let (temp temp-downcase found)
280 (setq filename (substitute-in-file-name filename))
281 (if (string= (downcase filename) "dir")
282 (setq found t)
283 (let ((dirs (if (string-match "^\\./" filename)
284 ;; If specified name starts with `./'
285 ;; then just try current directory.
286 '("./")
287 (if (file-name-absolute-p filename)
288 ;; No point in searching for an
289 ;; absolute file name
290 '(nil)
291 (if Info-additional-directory-list
292 (append Info-directory-list
293 Info-additional-directory-list)
294 Info-directory-list)))))
295 ;; Search the directory list for file FILENAME.
296 (while (and dirs (not found))
297 (setq temp (expand-file-name filename (car dirs)))
298 (setq temp-downcase
299 (expand-file-name (downcase filename) (car dirs)))
300 ;; Try several variants of specified name.
301 (let ((suffix-list Info-suffix-list))
302 (while (and suffix-list (not found))
303 (cond ((file-exists-p
304 (info-insert-file-contents-1
305 temp (car (car suffix-list))))
306 (setq found temp))
307 ((file-exists-p
308 (info-insert-file-contents-1
309 temp-downcase (car (car suffix-list))))
310 (setq found temp-downcase)))
311 (setq suffix-list (cdr suffix-list))))
312 (setq dirs (cdr dirs)))))
313 (if found
314 (setq filename found)
315 (error "Info file %s does not exist" filename))))
316 ;; Record the node we are leaving.
317 (if (and Info-current-file (not no-going-back))
318 (setq Info-history
319 (cons (list Info-current-file Info-current-node (point))
320 Info-history)))
321 ;; Go into info buffer.
322 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
323 (buffer-disable-undo (current-buffer))
324 (or (eq major-mode 'Info-mode)
325 (Info-mode))
326 (widen)
327 (setq Info-current-node nil)
328 (unwind-protect
329 (progn
330 ;; Switch files if necessary
331 (or (null filename)
332 (equal Info-current-file filename)
333 (let ((buffer-read-only nil))
334 (setq Info-current-file nil
335 Info-current-subfile nil
336 Info-current-file-completions nil
337 buffer-file-name nil)
338 (erase-buffer)
339 (if (eq filename t)
340 (Info-insert-dir)
341 (info-insert-file-contents filename t)
342 (setq default-directory (file-name-directory filename)))
343 (set-buffer-modified-p nil)
344 ;; See whether file has a tag table. Record the location if yes.
345 (goto-char (point-max))
346 (forward-line -8)
347 ;; Use string-equal, not equal, to ignore text props.
348 (if (not (or (string-equal nodename "*")
349 (not
350 (search-forward "\^_\nEnd tag table\n" nil t))))
351 (let (pos)
352 ;; We have a tag table. Find its beginning.
353 ;; Is this an indirect file?
354 (search-backward "\nTag table:\n")
355 (setq pos (point))
356 (if (save-excursion
357 (forward-line 2)
358 (looking-at "(Indirect)\n"))
359 ;; It is indirect. Copy it to another buffer
360 ;; and record that the tag table is in that buffer.
361 (let ((buf (current-buffer))
362 (tagbuf
363 (or Info-tag-table-buffer
364 (generate-new-buffer " *info tag table*"))))
365 (setq Info-tag-table-buffer tagbuf)
366 (save-excursion
367 (set-buffer tagbuf)
368 (buffer-disable-undo (current-buffer))
369 (setq case-fold-search t)
370 (erase-buffer)
371 (insert-buffer-substring buf))
372 (set-marker Info-tag-table-marker
373 (match-end 0) tagbuf))
374 (set-marker Info-tag-table-marker pos)))
375 (set-marker Info-tag-table-marker nil))
376 (setq Info-current-file
377 (if (eq filename t) "dir" filename))))
378 ;; Use string-equal, not equal, to ignore text props.
379 (if (string-equal nodename "*")
380 (progn (setq Info-current-node nodename)
381 (Info-set-mode-line))
382 ;; Search file for a suitable node.
383 (let ((guesspos (point-min))
384 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
385 ;; First get advice from tag table if file has one.
386 ;; Also, if this is an indirect info file,
387 ;; read the proper subfile into this buffer.
388 (if (marker-position Info-tag-table-marker)
389 (save-excursion
390 (let ((m Info-tag-table-marker)
391 found found-mode)
392 (save-excursion
393 (set-buffer (marker-buffer m))
394 (goto-char m)
395 (beginning-of-line) ;so re-search will work.
396 (setq found (re-search-forward regexp nil t))
397 (if found
398 (setq guesspos (read (current-buffer))))
399 (setq found-mode major-mode))
400 (if found
401 (progn
402 ;; If this is an indirect file, determine
403 ;; which file really holds this node and
404 ;; read it in.
405 (if (not (eq found-mode 'Info-mode))
406 ;; Note that the current buffer must be
407 ;; the *info* buffer on entry to
408 ;; Info-read-subfile. Thus the hackery
409 ;; above.
410 (setq guesspos (Info-read-subfile guesspos))))
411 (error "No such node: %s" nodename)))))
412 (goto-char (max (point-min) (- guesspos 1000)))
413 ;; Now search from our advised position (or from beg of buffer)
414 ;; to find the actual node.
415 (catch 'foo
416 (while (search-forward "\n\^_" nil t)
417 (forward-line 1)
418 (let ((beg (point)))
419 (forward-line 1)
420 (if (re-search-backward regexp beg t)
421 (throw 'foo t))))
422 (error "No such node: %s" nodename)))
423 (Info-select-node)))
424 ;; If we did not finish finding the specified node,
425 ;; go back to the previous one.
426 (or Info-current-node no-going-back (null Info-history)
427 (let ((hist (car Info-history)))
428 (setq Info-history (cdr Info-history))
429 (Info-find-node (nth 0 hist) (nth 1 hist) t)
430 (goto-char (nth 2 hist)))))
431 (goto-char (point-min)))
432
433 ;; Cache the contents of the (virtual) dir file, once we have merged
434 ;; it for the first time, so we can save time subsequently.
435 (defvar Info-dir-contents nil)
436
437 ;; Cache for the directory we decided to use for the default-directory
438 ;; of the merged dir text.
439 (defvar Info-dir-contents-directory nil)
440
441 ;; Record the file attributes of all the files from which we
442 ;; constructed Info-dir-contents.
443 (defvar Info-dir-file-attributes nil)
444
445 ;; Construct the Info directory node by merging the files named `dir'
446 ;; from various directories. Set the *info* buffer's
447 ;; default-directory to the first directory we actually get any text
448 ;; from.
449 (defun Info-insert-dir ()
450 (if (and Info-dir-contents Info-dir-file-attributes
451 ;; Verify that none of the files we used has changed
452 ;; since we used it.
453 (eval (cons 'and
454 (mapcar '(lambda (elt)
455 (let ((curr (file-attributes (car elt))))
456 ;; Don't compare the access time.
457 (if curr (setcar (nthcdr 4 curr) 0))
458 (setcar (nthcdr 4 (cdr elt)) 0)
459 (equal (cdr elt) curr)))
460 Info-dir-file-attributes))))
461 (insert Info-dir-contents)
462 (let ((dirs Info-directory-list)
463 buffers buffer others nodes dirs-done)
464
465 (setq Info-dir-file-attributes nil)
466
467 ;; Search the directory list for the directory file.
468 (while dirs
469 (let ((truename (file-truename (expand-file-name (car dirs)))))
470 (or (member truename dirs-done)
471 (member (directory-file-name truename) dirs-done)
472 ;; Try several variants of specified name.
473 ;; Try upcasing, appending `.info', or both.
474 (let* (file
475 (attrs
476 (or
477 (progn (setq file (expand-file-name "dir" truename))
478 (file-attributes file))
479 (progn (setq file (expand-file-name "DIR" truename))
480 (file-attributes file))
481 (progn (setq file (expand-file-name "dir.info" truename))
482 (file-attributes file))
483 (progn (setq file (expand-file-name "DIR.INFO" truename))
484 (file-attributes file)))))
485 (setq dirs-done
486 (cons truename
487 (cons (directory-file-name truename)
488 dirs-done)))
489 (if attrs
490 (save-excursion
491 (or buffers
492 (message "Composing main Info directory..."))
493 (set-buffer (generate-new-buffer "info dir"))
494 (insert-file-contents file)
495 (setq buffers (cons (current-buffer) buffers)
496 Info-dir-file-attributes
497 (cons (cons file attrs)
498 Info-dir-file-attributes))))))
499 (or (cdr dirs) (setq Info-dir-contents-directory
500 (file-name-as-directory (car dirs))))
501 (setq dirs (cdr dirs))))
502
503 (or buffers
504 (error "Can't find the Info directory node"))
505 ;; Distinguish the dir file that comes with Emacs from all the
506 ;; others. Yes, that is really what this is supposed to do.
507 ;; If it doesn't work, fix it.
508 (setq buffer (car buffers)
509 others (cdr buffers))
510
511 ;; Insert the entire original dir file as a start; note that we've
512 ;; already saved its default directory to use as the default
513 ;; directory for the whole concatenation.
514 (insert-buffer buffer)
515
516 ;; Look at each of the other buffers one by one.
517 (while others
518 (let ((other (car others)))
519 ;; In each, find all the menus.
520 (save-excursion
521 (set-buffer other)
522 (goto-char (point-min))
523 ;; Find each menu, and add an elt to NODES for it.
524 (while (re-search-forward "^\\* Menu:" nil t)
525 (let (beg nodename end)
526 (forward-line 1)
527 (setq beg (point))
528 (search-backward "\n\^_")
529 (search-forward "Node: ")
530 (setq nodename (Info-following-node-name))
531 (search-forward "\n\^_" nil 'move)
532 (beginning-of-line)
533 (setq end (point))
534 (setq nodes (cons (list nodename other beg end) nodes))))))
535 (setq others (cdr others)))
536 ;; Add to the main menu a menu item for each other node.
537 (re-search-forward "^\\* Menu:")
538 (forward-line 1)
539 (let ((menu-items '("top"))
540 (nodes nodes)
541 (case-fold-search t)
542 (end (save-excursion (search-forward "\^_" nil t) (point))))
543 (while nodes
544 (let ((nodename (car (car nodes))))
545 (save-excursion
546 (or (member (downcase nodename) menu-items)
547 (re-search-forward (concat "^\\* "
548 (regexp-quote nodename)
549 "::")
550 end t)
551 (progn
552 (insert "* " nodename "::" "\n")
553 (setq menu-items (cons nodename menu-items))))))
554 (setq nodes (cdr nodes))))
555 ;; Now take each node of each of the other buffers
556 ;; and merge it into the main buffer.
557 (while nodes
558 (let ((nodename (car (car nodes))))
559 (goto-char (point-min))
560 ;; Find the like-named node in the main buffer.
561 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
562 (regexp-quote nodename)
563 "[,\n\t]")
564 nil t)
565 (progn
566 (search-forward "\n\^_" nil 'move)
567 (beginning-of-line)
568 (insert "\n"))
569 ;; If none exists, add one.
570 (goto-char (point-max))
571 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
572 ;; Merge the text from the other buffer's menu
573 ;; into the menu in the like-named node in the main buffer.
574 (apply 'insert-buffer-substring (cdr (car nodes))))
575 (setq nodes (cdr nodes)))
576 ;; Kill all the buffers we just made.
577 (while buffers
578 (kill-buffer (car buffers))
579 (setq buffers (cdr buffers)))
580 (message "Composing main Info directory...done"))
581 (setq Info-dir-contents (buffer-string)))
582 (setq default-directory Info-dir-contents-directory))
583
584 ;; Note that on entry to this function the current-buffer must be the
585 ;; *info* buffer; not the info tags buffer.
586 (defun Info-read-subfile (nodepos)
587 ;; NODEPOS is either a position (in the Info file as a whole,
588 ;; not relative to a subfile) or the name of a subfile.
589 (let (lastfilepos
590 lastfilename)
591 (if (numberp nodepos)
592 (save-excursion
593 (set-buffer (marker-buffer Info-tag-table-marker))
594 (goto-char (point-min))
595 (search-forward "\n\^_")
596 (forward-line 2)
597 (catch 'foo
598 (while (not (looking-at "\^_"))
599 (if (not (eolp))
600 (let ((beg (point))
601 thisfilepos thisfilename)
602 (search-forward ": ")
603 (setq thisfilename (buffer-substring beg (- (point) 2)))
604 (setq thisfilepos (read (current-buffer)))
605 ;; read in version 19 stops at the end of number.
606 ;; Advance to the next line.
607 (forward-line 1)
608 (if (> thisfilepos nodepos)
609 (throw 'foo t))
610 (setq lastfilename thisfilename)
611 (setq lastfilepos thisfilepos))
612 (forward-line 1)))))
613 (setq lastfilename nodepos)
614 (setq lastfilepos 0))
615 ;; Assume previous buffer is in Info-mode.
616 ;; (set-buffer (get-buffer "*info*"))
617 (or (equal Info-current-subfile lastfilename)
618 (let ((buffer-read-only nil))
619 (setq buffer-file-name nil)
620 (widen)
621 (erase-buffer)
622 (info-insert-file-contents lastfilename)
623 (set-buffer-modified-p nil)
624 (setq Info-current-subfile lastfilename)))
625 (goto-char (point-min))
626 (search-forward "\n\^_")
627 (if (numberp nodepos)
628 (+ (- nodepos lastfilepos) (point)))))
629
630 ;; Select the info node that point is in.
631 (defun Info-select-node ()
632 (save-excursion
633 ;; Find beginning of node.
634 (search-backward "\n\^_")
635 (forward-line 2)
636 ;; Get nodename spelled as it is in the node.
637 (re-search-forward "Node:[ \t]*")
638 (setq Info-current-node
639 (buffer-substring-no-properties (point)
640 (progn
641 (skip-chars-forward "^,\t\n")
642 (point))))
643 (Info-set-mode-line)
644 ;; Find the end of it, and narrow.
645 (beginning-of-line)
646 (let (active-expression)
647 (narrow-to-region (point)
648 (if (re-search-forward "\n[\^_\f]" nil t)
649 (prog1
650 (1- (point))
651 (if (looking-at "[\n\^_\f]*execute: ")
652 (progn
653 (goto-char (match-end 0))
654 (setq active-expression
655 (read (current-buffer))))))
656 (point-max)))
657 (if Info-enable-active-nodes (eval active-expression))
658 (if Info-fontify (Info-fontify-node))
659 (run-hooks 'Info-selection-hook))))
660
661 (defun Info-set-mode-line ()
662 (setq mode-line-buffer-identification
663 (concat
664 "Info: ("
665 (if Info-current-file
666 (file-name-nondirectory Info-current-file)
667 "")
668 ")"
669 (or Info-current-node ""))))
670 \f
671 ;; Go to an info node specified with a filename-and-nodename string
672 ;; of the sort that is found in pointers in nodes.
673
674 (defun Info-goto-node (nodename)
675 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
676 (interactive (list (Info-read-node-name "Goto node: ")))
677 (let (filename)
678 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
679 nodename)
680 (setq filename (if (= (match-beginning 1) (match-end 1))
681 ""
682 (substring nodename (match-beginning 2) (match-end 2)))
683 nodename (substring nodename (match-beginning 3) (match-end 3)))
684 (let ((trim (string-match "\\s *\\'" filename)))
685 (if trim (setq filename (substring filename 0 trim))))
686 (let ((trim (string-match "\\s *\\'" nodename)))
687 (if trim (setq nodename (substring nodename 0 trim))))
688 (if transient-mark-mode (deactivate-mark))
689 (Info-find-node (if (equal filename "") nil filename)
690 (if (equal nodename "") "Top" nodename))))
691
692 ;; This function is used as the "completion table" while reading a node name.
693 ;; It does completion using the alist in completion-table
694 ;; unless STRING starts with an open-paren.
695 (defun Info-read-node-name-1 (string predicate code)
696 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
697 (cond ((eq code nil)
698 (if no-completion
699 string
700 (try-completion string completion-table predicate)))
701 ((eq code t)
702 (if no-completion
703 nil
704 (all-completions string completion-table predicate)))
705 ((eq code 'lambda)
706 (if no-completion
707 t
708 (assoc string completion-table))))))
709
710 (defun Info-read-node-name (prompt &optional default)
711 (let* ((completion-ignore-case t)
712 (completion-table (Info-build-node-completions))
713 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
714 (if (equal nodename "")
715 (or default
716 (Info-read-node-name prompt))
717 nodename)))
718
719 (defun Info-build-node-completions ()
720 (or Info-current-file-completions
721 (let ((compl nil))
722 (save-excursion
723 (save-restriction
724 (if (marker-buffer Info-tag-table-marker)
725 (let ((marker Info-tag-table-marker))
726 (set-buffer (marker-buffer marker))
727 (widen)
728 (goto-char marker)
729 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
730 (setq compl
731 (cons (list (buffer-substring (match-beginning 1)
732 (match-end 1)))
733 compl))))
734 (widen)
735 (goto-char (point-min))
736 (while (search-forward "\n\^_" nil t)
737 (forward-line 1)
738 (let ((beg (point)))
739 (forward-line 1)
740 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
741 beg t)
742 (setq compl
743 (cons (list (buffer-substring (match-beginning 1)
744 (match-end 1)))
745 compl))))))))
746 (setq Info-current-file-completions compl))))
747 \f
748 (defun Info-restore-point (hl)
749 "If this node has been visited, restore the point value when we left."
750 (while hl
751 (if (and (equal (nth 0 (car hl)) Info-current-file)
752 ;; Use string-equal, not equal, to ignore text props.
753 (string-equal (nth 1 (car hl)) Info-current-node))
754 (progn
755 (goto-char (nth 2 (car hl)))
756 (setq hl nil)) ;terminate the while at next iter
757 (setq hl (cdr hl)))))
758 \f
759 (defvar Info-last-search nil
760 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
761
762 (defun Info-search (regexp)
763 "Search for REGEXP, starting from point, and select node it's found in."
764 (interactive "sSearch (regexp): ")
765 (if transient-mark-mode (deactivate-mark))
766 (if (equal regexp "")
767 (setq regexp Info-last-search)
768 (setq Info-last-search regexp))
769 (let ((found ()) current
770 (onode Info-current-node)
771 (ofile Info-current-file)
772 (opoint (point))
773 (ostart (window-start))
774 (osubfile Info-current-subfile))
775 (save-excursion
776 (save-restriction
777 (widen)
778 (if (null Info-current-subfile)
779 (progn (re-search-forward regexp) (setq found (point)))
780 (condition-case err
781 (progn (re-search-forward regexp) (setq found (point)))
782 (search-failed nil)))))
783 (if (not found) ;can only happen in subfile case -- else would have erred
784 (unwind-protect
785 (let ((list ()))
786 (save-excursion
787 (set-buffer (marker-buffer Info-tag-table-marker))
788 (goto-char (point-min))
789 (search-forward "\n\^_\nIndirect:")
790 (save-restriction
791 (narrow-to-region (point)
792 (progn (search-forward "\n\^_")
793 (1- (point))))
794 (goto-char (point-min))
795 (search-forward (concat "\n" osubfile ": "))
796 (beginning-of-line)
797 (while (not (eobp))
798 (re-search-forward "\\(^.*\\): [0-9]+$")
799 (goto-char (+ (match-end 1) 2))
800 (setq list (cons (cons (read (current-buffer))
801 (buffer-substring
802 (match-beginning 1) (match-end 1)))
803 list))
804 (goto-char (1+ (match-end 0))))
805 (setq list (nreverse list)
806 current (car (car list))
807 list (cdr list))))
808 (while list
809 (message "Searching subfile %s..." (cdr (car list)))
810 (Info-read-subfile (car (car list)))
811 (setq list (cdr list))
812 ;; (goto-char (point-min))
813 (if (re-search-forward regexp nil t)
814 (setq found (point) list ())))
815 (if found
816 (message "")
817 (signal 'search-failed (list regexp))))
818 (if (not found)
819 (progn (Info-read-subfile osubfile)
820 (goto-char opoint)
821 (Info-select-node)
822 (set-window-start (selected-window) ostart)))))
823 (widen)
824 (goto-char found)
825 (Info-select-node)
826 ;; Use string-equal, not equal, to ignore text props.
827 (or (and (string-equal onode Info-current-node)
828 (equal ofile Info-current-file))
829 (setq Info-history (cons (list ofile onode opoint)
830 Info-history)))))
831 \f
832 ;; Extract the value of the node-pointer named NAME.
833 ;; If there is none, use ERRORNAME in the error message;
834 ;; if ERRORNAME is nil, just return nil.
835 (defun Info-extract-pointer (name &optional errorname)
836 (save-excursion
837 (goto-char (point-min))
838 (forward-line 1)
839 (if (re-search-backward (concat name ":") nil t)
840 (progn
841 (goto-char (match-end 0))
842 (Info-following-node-name))
843 (if (eq errorname t)
844 nil
845 (error "Node has no %s" (capitalize (or errorname name)))))))
846
847 ;; Return the node name in the buffer following point.
848 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
849 ;; saying which chars may appear in the node name.
850 (defun Info-following-node-name (&optional allowedchars)
851 (skip-chars-forward " \t")
852 (buffer-substring-no-properties
853 (point)
854 (progn
855 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
856 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
857 (if (looking-at "(")
858 (skip-chars-forward "^)")))
859 (skip-chars-backward " ")
860 (point))))
861
862 (defun Info-next ()
863 "Go to the next node of this node."
864 (interactive)
865 (Info-goto-node (Info-extract-pointer "next")))
866
867 (defun Info-prev ()
868 "Go to the previous node of this node."
869 (interactive)
870 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
871
872 (defun Info-up ()
873 "Go to the superior node of this node."
874 (interactive)
875 (Info-goto-node (Info-extract-pointer "up"))
876 (Info-restore-point Info-history))
877
878 (defun Info-last ()
879 "Go back to the last node visited."
880 (interactive)
881 (or Info-history
882 (error "This is the first Info node you looked at"))
883 (let (filename nodename opoint)
884 (setq filename (car (car Info-history)))
885 (setq nodename (car (cdr (car Info-history))))
886 (setq opoint (car (cdr (cdr (car Info-history)))))
887 (setq Info-history (cdr Info-history))
888 (Info-find-node filename nodename)
889 (setq Info-history (cdr Info-history))
890 (goto-char opoint)))
891
892 (defun Info-directory ()
893 "Go to the Info directory node."
894 (interactive)
895 (Info-find-node "dir" "top"))
896 \f
897 (defun Info-follow-reference (footnotename)
898 "Follow cross reference named NAME to the node it refers to.
899 NAME may be an abbreviation of the reference name."
900 (interactive
901 (let ((completion-ignore-case t)
902 completions default alt-default (start-point (point)) str i bol eol)
903 (save-excursion
904 ;; Store end and beginning of line.
905 (end-of-line)
906 (setq eol (point))
907 (beginning-of-line)
908 (setq bol (point))
909
910 (goto-char (point-min))
911 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
912 (setq str (buffer-substring
913 (match-beginning 1)
914 (1- (point))))
915 ;; See if this one should be the default.
916 (and (null default)
917 (<= (match-beginning 0) start-point)
918 (<= start-point (point))
919 (setq default t))
920 ;; See if this one should be the alternate default.
921 (and (null alt-default)
922 (and (<= bol (match-beginning 0))
923 (<= (point) eol))
924 (setq alt-default t))
925 (setq i 0)
926 (while (setq i (string-match "[ \n\t]+" str i))
927 (setq str (concat (substring str 0 i) " "
928 (substring str (match-end 0))))
929 (setq i (1+ i)))
930 ;; Record as a completion and perhaps as default.
931 (if (eq default t) (setq default str))
932 (if (eq alt-default t) (setq alt-default str))
933 ;; Don't add this string if it's a duplicate.
934 ;; We use a loop instead of "(assoc str completions)" because
935 ;; we want to do a case-insensitive compare.
936 (let ((tail completions)
937 (tem (downcase str)))
938 (while (and tail
939 (not (string-equal tem (downcase (car (car tail))))))
940 (setq tail (cdr tail)))
941 (or tail
942 (setq completions
943 (cons (cons str nil)
944 completions))))))
945 ;; If no good default was found, try an alternate.
946 (or default
947 (setq default alt-default))
948 ;; If only one cross-reference found, then make it default.
949 (if (eq (length completions) 1)
950 (setq default (car (car completions))))
951 (if completions
952 (let ((input (completing-read (if default
953 (concat "Follow reference named: ("
954 default ") ")
955 "Follow reference named: ")
956 completions nil t)))
957 (list (if (equal input "")
958 default input)))
959 (error "No cross-references in this node"))))
960 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename))))
961 (while (setq i (string-match " " str i))
962 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
963 (setq i (+ i 6)))
964 (save-excursion
965 (goto-char (point-min))
966 (or (re-search-forward str nil t)
967 (error "No cross-reference named %s" footnotename))
968 (goto-char (+ (match-beginning 0) 5))
969 (setq target
970 (Info-extract-menu-node-name "Bad format cross reference" t)))
971 (while (setq i (string-match "[ \t\n]+" target i))
972 (setq target (concat (substring target 0 i) " "
973 (substring target (match-end 0))))
974 (setq i (+ i 1)))
975 (Info-goto-node target)))
976
977 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
978 (skip-chars-forward " \t\n")
979 (let ((beg (point))
980 str i)
981 (skip-chars-forward "^:")
982 (forward-char 1)
983 (setq str
984 (if (looking-at ":")
985 (buffer-substring-no-properties beg (1- (point)))
986 (skip-chars-forward " \t\n")
987 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
988 (while (setq i (string-match "\n" str i))
989 (aset str i ?\ ))
990 ;; Collapse multiple spaces.
991 (while (string-match " +" str)
992 (setq str (replace-match " " t t str)))
993 str))
994
995 ;; No one calls this.
996 ;;(defun Info-menu-item-sequence (list)
997 ;; (while list
998 ;; (Info-menu (car list))
999 ;; (setq list (cdr list))))
1000
1001 (defun Info-complete-menu-item (string predicate action)
1002 (let ((case-fold-search t))
1003 (cond ((eq action nil)
1004 (let (completions
1005 (pattern (concat "\n\\* \\("
1006 (regexp-quote string)
1007 "[^:\t\n]*\\):")))
1008 (save-excursion
1009 (set-buffer Info-complete-menu-buffer)
1010 (goto-char (point-min))
1011 (search-forward "\n* Menu:")
1012 (while (re-search-forward pattern nil t)
1013 (setq completions (cons (cons (format "%s"
1014 (buffer-substring
1015 (match-beginning 1)
1016 (match-end 1)))
1017 (match-beginning 1))
1018 completions))))
1019 (try-completion string completions predicate)))
1020 ((eq action t)
1021 (let (completions
1022 (pattern (concat "\n\\* \\("
1023 (regexp-quote string)
1024 "[^:\t\n]*\\):")))
1025 (save-excursion
1026 (set-buffer Info-complete-menu-buffer)
1027 (goto-char (point-min))
1028 (search-forward "\n* Menu:")
1029 (while (re-search-forward pattern nil t)
1030 (setq completions (cons (cons (format "%s"
1031 (buffer-substring
1032 (match-beginning 1)
1033 (match-end 1)))
1034 (match-beginning 1))
1035 completions))))
1036 (all-completions string completions predicate)))
1037 (t
1038 (save-excursion
1039 (set-buffer Info-complete-menu-buffer)
1040 (goto-char (point-min))
1041 (search-forward "\n* Menu:")
1042 (re-search-forward (concat "\n\\* "
1043 (regexp-quote string)
1044 ":")
1045 nil t))))))
1046
1047
1048 (defun Info-menu (menu-item)
1049 "Go to node for menu item named (or abbreviated) NAME.
1050 Completion is allowed, and the menu item point is on is the default."
1051 (interactive
1052 (let ((completions '())
1053 ;; If point is within a menu item, use that item as the default
1054 (default nil)
1055 (p (point))
1056 beg
1057 (last nil))
1058 (save-excursion
1059 (goto-char (point-min))
1060 (if (not (search-forward "\n* menu:" nil t))
1061 (error "No menu in this node"))
1062 (setq beg (point))
1063 (and (< (point) p)
1064 (save-excursion
1065 (goto-char p)
1066 (end-of-line)
1067 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t)
1068 (setq default (format "%s" (buffer-substring
1069 (match-beginning 1)
1070 (match-end 1)))))))
1071 (let ((item nil))
1072 (while (null item)
1073 (setq item (let ((completion-ignore-case t)
1074 (Info-complete-menu-buffer (current-buffer)))
1075 (completing-read (if default
1076 (format "Menu item (default %s): "
1077 default)
1078 "Menu item: ")
1079 'Info-complete-menu-item nil t)))
1080 ;; we rely on the fact that completing-read accepts an input
1081 ;; of "" even when the require-match argument is true and ""
1082 ;; is not a valid possibility
1083 (if (string= item "")
1084 (if default
1085 (setq item default)
1086 ;; ask again
1087 (setq item nil))))
1088 (list item))))
1089 ;; there is a problem here in that if several menu items have the same
1090 ;; name you can only go to the node of the first with this command.
1091 (Info-goto-node (Info-extract-menu-item menu-item)))
1092
1093 (defun Info-extract-menu-item (menu-item)
1094 (setq menu-item (regexp-quote menu-item))
1095 (save-excursion
1096 (goto-char (point-min))
1097 (or (search-forward "\n* menu:" nil t)
1098 (error "No menu in this node"))
1099 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
1100 (re-search-forward (concat "\n\\* " menu-item) nil t)
1101 (error "No such item in menu"))
1102 (beginning-of-line)
1103 (forward-char 2)
1104 (Info-extract-menu-node-name)))
1105
1106 ;; If COUNT is nil, use the last item in the menu.
1107 (defun Info-extract-menu-counting (count)
1108 (save-excursion
1109 (goto-char (point-min))
1110 (or (search-forward "\n* menu:" nil t)
1111 (error "No menu in this node"))
1112 (if count
1113 (or (search-forward "\n* " nil t count)
1114 (error "Too few items in menu"))
1115 (while (search-forward "\n* " nil t)
1116 nil))
1117 (Info-extract-menu-node-name)))
1118
1119 (defun Info-nth-menu-item ()
1120 "Go to the node of the Nth menu item.
1121 N is the digit argument used to invoke this command."
1122 (interactive)
1123 (Info-goto-node
1124 (Info-extract-menu-counting
1125 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1126
1127 (defun Info-top-node ()
1128 "Go to the Top node of this file."
1129 (interactive)
1130 (Info-goto-node "Top"))
1131
1132 (defun Info-final-node ()
1133 "Go to the final node in this file."
1134 (interactive)
1135 (Info-goto-node "Top")
1136 (let (Info-history)
1137 ;; Go to the last node in the menu of Top.
1138 (Info-goto-node (Info-extract-menu-counting nil))
1139 ;; If the last node in the menu is not last in pointer structure,
1140 ;; move forward until we can't go any farther.
1141 (while (Info-forward-node t t) nil)
1142 ;; Then keep moving down to last subnode, unless we reach an index.
1143 (while (and (not (string-match "\\<index\\>" Info-current-node))
1144 (save-excursion (search-forward "\n* Menu:" nil t)))
1145 (Info-goto-node (Info-extract-menu-counting nil)))))
1146
1147 (defun Info-forward-node (&optional not-down no-error)
1148 "Go forward one node, considering all nodes as forming one sequence."
1149 (interactive)
1150 (goto-char (point-min))
1151 (forward-line 1)
1152 ;; three possibilities, in order of priority:
1153 ;; 1. next node is in a menu in this node (but not in an index)
1154 ;; 2. next node is next at same level
1155 ;; 3. next node is up and next
1156 (cond ((and (not not-down)
1157 (save-excursion (search-forward "\n* menu:" nil t))
1158 (not (string-match "\\<index\\>" Info-current-node)))
1159 (Info-goto-node (Info-extract-menu-counting 1))
1160 t)
1161 ((save-excursion (search-backward "next:" nil t))
1162 (Info-next)
1163 t)
1164 ((and (save-excursion (search-backward "up:" nil t))
1165 ;; Use string-equal, not equal, to ignore text props.
1166 (not (string-equal (downcase (Info-extract-pointer "up"))
1167 "top")))
1168 (let ((old-node Info-current-node))
1169 (Info-up)
1170 (let (Info-history success)
1171 (unwind-protect
1172 (setq success (Info-forward-node t no-error))
1173 (or success (Info-goto-node old-node))))))
1174 (no-error nil)
1175 (t (error "No pointer forward from this node"))))
1176
1177 (defun Info-backward-node ()
1178 "Go backward one node, considering all nodes as forming one sequence."
1179 (interactive)
1180 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1181 (upnode (Info-extract-pointer "up" t)))
1182 (cond ((and upnode (string-match "(" upnode))
1183 (error "First node in file"))
1184 ((and upnode (or (null prevnode)
1185 ;; Use string-equal, not equal,
1186 ;; to ignore text properties.
1187 (string-equal (downcase prevnode)
1188 (downcase upnode))))
1189 (Info-up))
1190 (prevnode
1191 ;; If we move back at the same level,
1192 ;; go down to find the last subnode*.
1193 (Info-prev)
1194 (let (Info-history)
1195 (while (and (not (string-match "\\<index\\>" Info-current-node))
1196 (save-excursion (search-forward "\n* Menu:" nil t)))
1197 (Info-goto-node (Info-extract-menu-counting nil)))))
1198 (t
1199 (error "No pointer backward from this node")))))
1200
1201 (defun Info-exit ()
1202 "Exit Info by selecting some other buffer."
1203 (interactive)
1204 (if Info-standalone
1205 (save-buffers-kill-emacs)
1206 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1207 (bury-buffer (current-buffer))))))
1208
1209 (defun Info-next-menu-item ()
1210 (interactive)
1211 (save-excursion
1212 (forward-line -1)
1213 (search-forward "\n* menu:" nil t)
1214 (or (search-forward "\n* " nil t)
1215 (error "No more items in menu"))
1216 (Info-goto-node (Info-extract-menu-node-name))))
1217
1218 (defun Info-last-menu-item ()
1219 (interactive)
1220 (save-excursion
1221 (forward-line 1)
1222 (let ((beg (save-excursion
1223 (and (search-backward "\n* menu:" nil t)
1224 (point)))))
1225 (or (and beg (search-backward "\n* " beg t))
1226 (error "No previous items in menu")))
1227 (Info-goto-node (save-excursion
1228 (goto-char (match-end 0))
1229 (Info-extract-menu-node-name)))))
1230
1231 (defmacro Info-no-error (&rest body)
1232 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1233
1234 (defun Info-next-preorder ()
1235 "Go to the next subnode or the next node, or go up a level."
1236 (interactive)
1237 (cond ((Info-no-error (Info-next-menu-item)))
1238 ((Info-no-error (Info-next)))
1239 ((Info-no-error (Info-up))
1240 ;; Since we have already gone thru all the items in this menu,
1241 ;; go up to the end of this node.
1242 (goto-char (point-max))
1243 ;; Since logically we are done with the node with that menu,
1244 ;; move on from it.
1245 (Info-next-preorder))
1246 (t
1247 (error "No more nodes"))))
1248
1249 (defun Info-last-preorder ()
1250 "Go to the last node, popping up a level if there is none."
1251 (interactive)
1252 (cond ((Info-no-error
1253 (Info-last-menu-item)
1254 ;; If we go down a menu item, go to the end of the node
1255 ;; so we can scroll back through it.
1256 (goto-char (point-max)))
1257 ;; Keep going down, as long as there are nested menu nodes.
1258 (while (Info-no-error
1259 (Info-last-menu-item)
1260 ;; If we go down a menu item, go to the end of the node
1261 ;; so we can scroll back through it.
1262 (goto-char (point-max))))
1263 (recenter -1))
1264 ((Info-no-error (Info-prev))
1265 (goto-char (point-max))
1266 (while (Info-no-error
1267 (Info-last-menu-item)
1268 ;; If we go down a menu item, go to the end of the node
1269 ;; so we can scroll back through it.
1270 (goto-char (point-max))))
1271 (recenter -1))
1272 ((Info-no-error (Info-up))
1273 (goto-char (point-min))
1274 (or (search-forward "\n* Menu:" nil t)
1275 (goto-char (point-max))))
1276 (t (error "No previous nodes"))))
1277
1278 (defun Info-scroll-up ()
1279 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1280 Once you scroll far enough in a node that its menu appears on the screen
1281 but after point, the next scroll moves into its first subnode.
1282
1283 When you scroll past the end of a node, that goes to the next node; if
1284 this node has no successor, it moves to the parent node's successor,
1285 and so on. If point is inside the menu of a node, it moves to
1286 subnode indicated by the following menu item. (That case won't
1287 normally result from this command, but can happen in other ways.)"
1288
1289 (interactive)
1290 (if (or (< (window-start) (point-min))
1291 (> (window-start) (point-max)))
1292 (set-window-start (selected-window) (point)))
1293 (let ((virtual-end (save-excursion
1294 (goto-char (point-min))
1295 (if (search-forward "\n* Menu:" nil t)
1296 (point)
1297 (point-max)))))
1298 (if (or (< virtual-end (window-start))
1299 (pos-visible-in-window-p virtual-end))
1300 (Info-next-preorder)
1301 (scroll-up))))
1302
1303 (defun Info-scroll-down ()
1304 "Scroll one screenful back in Info, considering all nodes as one sequence.
1305 Within the menu of a node, this goes to its last subnode.
1306 When you scroll past the beginning of a node, that goes to the
1307 previous node or back up to the parent node."
1308 (interactive)
1309 (if (or (< (window-start) (point-min))
1310 (> (window-start) (point-max)))
1311 (set-window-start (selected-window) (point)))
1312 (let* ((current-point (point))
1313 (virtual-end (save-excursion
1314 (beginning-of-line)
1315 (setq current-point (point))
1316 (goto-char (point-min))
1317 (search-forward "\n* Menu:"
1318 current-point
1319 t))))
1320 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1321 (Info-last-preorder)
1322 (scroll-down))))
1323
1324 (defun Info-next-reference (&optional recur)
1325 "Move cursor to the next cross-reference or menu item in the node."
1326 (interactive)
1327 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1328 (old-pt (point)))
1329 (or (eobp) (forward-char 1))
1330 (or (re-search-forward pat nil t)
1331 (progn
1332 (goto-char (point-min))
1333 (or (re-search-forward pat nil t)
1334 (progn
1335 (goto-char old-pt)
1336 (error "No cross references in this node")))))
1337 (goto-char (match-beginning 0))
1338 (if (looking-at "\\* Menu:")
1339 (if recur
1340 (error "No cross references in this node")
1341 (Info-next-reference t)))))
1342
1343 (defun Info-prev-reference (&optional recur)
1344 "Move cursor to the previous cross-reference or menu item in the node."
1345 (interactive)
1346 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1347 (old-pt (point)))
1348 (or (re-search-backward pat nil t)
1349 (progn
1350 (goto-char (point-max))
1351 (or (re-search-backward pat nil t)
1352 (progn
1353 (goto-char old-pt)
1354 (error "No cross references in this node")))))
1355 (goto-char (match-beginning 0))
1356 (if (looking-at "\\* Menu:")
1357 (if recur
1358 (error "No cross references in this node")
1359 (Info-prev-reference t)))))
1360
1361 (defun Info-index (topic)
1362 "Look up a string in the index for this file.
1363 The index is defined as the first node in the top-level menu whose
1364 name contains the word \"Index\", plus any immediately following
1365 nodes whose names also contain the word \"Index\".
1366 If there are no exact matches to the specified topic, this chooses
1367 the first match which is a case-insensitive substring of a topic.
1368 Use the `,' command to see the other matches.
1369 Give a blank topic name to go to the Index node itself."
1370 (interactive "sIndex topic: ")
1371 (let ((orignode Info-current-node)
1372 (rnode nil)
1373 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1374 (regexp-quote topic)))
1375 node)
1376 (Info-goto-node "Top")
1377 (or (search-forward "\n* menu:" nil t)
1378 (error "No index"))
1379 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1380 (error "No index"))
1381 (goto-char (match-beginning 1))
1382 ;; Here, and subsequently in this function,
1383 ;; we bind Info-history to nil for internal node-switches
1384 ;; so that we don't put junk in the history.
1385 ;; In the first Info-goto-node call, above, we do update the history
1386 ;; because that is what the user's previous node choice into it.
1387 (let ((Info-history nil))
1388 (Info-goto-node (Info-extract-menu-node-name)))
1389 (or (equal topic "")
1390 (let ((matches nil)
1391 (exact nil)
1392 (Info-history nil)
1393 found)
1394 (while
1395 (progn
1396 (goto-char (point-min))
1397 (while (re-search-forward pattern nil t)
1398 (setq matches
1399 (cons (list (buffer-substring (match-beginning 1)
1400 (match-end 1))
1401 (buffer-substring (match-beginning 2)
1402 (match-end 2))
1403 Info-current-node
1404 (string-to-int (concat "0"
1405 (buffer-substring
1406 (match-beginning 3)
1407 (match-end 3)))))
1408 matches)))
1409 (and (setq node (Info-extract-pointer "next" t))
1410 (string-match "\\<Index\\>" node)))
1411 (Info-goto-node node))
1412 (or matches
1413 (progn
1414 (Info-goto-node orignode)
1415 (error "No `%s' in index" topic)))
1416 ;; Here it is a feature that assoc is case-sensitive.
1417 (while (setq found (assoc topic matches))
1418 (setq exact (cons found exact)
1419 matches (delq found matches)))
1420 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1421 (Info-index-next 0)))))
1422
1423 (defun Info-index-next (num)
1424 "Go to the next matching index item from the last `i' command."
1425 (interactive "p")
1426 (or Info-index-alternatives
1427 (error "No previous `i' command"))
1428 (while (< num 0)
1429 (setq num (+ num (length Info-index-alternatives))))
1430 (while (> num 0)
1431 (setq Info-index-alternatives
1432 (nconc (cdr Info-index-alternatives)
1433 (list (car Info-index-alternatives)))
1434 num (1- num)))
1435 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1436 (if (> (nth 3 (car Info-index-alternatives)) 0)
1437 (forward-line (nth 3 (car Info-index-alternatives)))
1438 (forward-line 3) ; don't search in headers
1439 (let ((name (car (car Info-index-alternatives))))
1440 (Info-find-index-name name)))
1441 (message "Found `%s' in %s. %s"
1442 (car (car Info-index-alternatives))
1443 (nth 2 (car Info-index-alternatives))
1444 (if (cdr Info-index-alternatives)
1445 "(Press `,' for more)"
1446 "(Only match)")))
1447
1448 (defun Info-find-index-name (name)
1449 "Move point to the place within the current node where NAME is defined."
1450 (if (or (re-search-forward (format
1451 "[a-zA-Z]+: %s\\( \\|$\\)"
1452 (regexp-quote name)) nil t)
1453 (search-forward (format "`%s'" name) nil t)
1454 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1455 (search-forward
1456 (format "`%s'" (substring name 0 (match-beginning 1)))
1457 nil t))
1458 (search-forward name nil t))
1459 (beginning-of-line)
1460 (goto-char (point-min))))
1461
1462 (defun Info-undefined ()
1463 "Make command be undefined in Info."
1464 (interactive)
1465 (ding))
1466
1467 (defun Info-help ()
1468 "Enter the Info tutorial."
1469 (interactive)
1470 (delete-other-windows)
1471 (Info-find-node "info"
1472 (if (< (window-height) 23)
1473 "Help-Small-Screen"
1474 "Help")))
1475
1476 (defun Info-summary ()
1477 "Display a brief summary of all Info commands."
1478 (interactive)
1479 (save-window-excursion
1480 (switch-to-buffer "*Help*")
1481 (erase-buffer)
1482 (insert (documentation 'Info-mode))
1483 (help-mode)
1484 (goto-char (point-min))
1485 (let (ch flag)
1486 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1487 (message (if flag "Type Space to see more"
1488 "Type Space to return to Info"))
1489 (if (not (eq ?\ (setq ch (read-event))))
1490 (progn (setq unread-command-events (list ch)) nil)
1491 flag))
1492 (scroll-up)))
1493 (bury-buffer "*Help*")))
1494 \f
1495 (defun Info-get-token (pos start all &optional errorstring)
1496 "Return the token around POS,
1497 POS must be somewhere inside the token
1498 START is a regular expression which will match the
1499 beginning of the tokens delimited string
1500 ALL is a regular expression with a single
1501 parenthesized subpattern which is the token to be
1502 returned. E.g. '{\(.*\)}' would return any string
1503 enclosed in braces around POS.
1504 SIG optional fourth argument, controls action on no match
1505 nil: return nil
1506 t: beep
1507 a string: signal an error, using that string."
1508 (save-excursion
1509 (goto-char pos)
1510 ;; First look for a match for START that goes across POS.
1511 (while (and (not (bobp)) (> (point) (- pos (length start)))
1512 (not (looking-at start)))
1513 (forward-char -1))
1514 ;; If we did not find one, search back for START
1515 ;; (this finds only matches that end at or before POS).
1516 (or (looking-at start)
1517 (progn
1518 (goto-char pos)
1519 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1520 (let (found)
1521 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1522 (not (setq found (and (<= (match-beginning 0) pos)
1523 (> (match-end 0) pos))))))
1524 (if (and found (<= (match-beginning 0) pos)
1525 (> (match-end 0) pos))
1526 (buffer-substring (match-beginning 1) (match-end 1))
1527 (cond ((null errorstring)
1528 nil)
1529 ((eq errorstring t)
1530 (beep)
1531 nil)
1532 (t
1533 (error "No %s around position %d" errorstring pos)))))))
1534
1535 (defun Info-mouse-follow-nearest-node (click)
1536 "\\<Info-mode-map>Follow a node reference near point.
1537 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1538 At end of the node's text, moves to the next node, or up if none."
1539 (interactive "e")
1540 (let* ((start (event-start click))
1541 (window (car start))
1542 (pos (car (cdr start))))
1543 (select-window window)
1544 (goto-char pos))
1545 (and (not (Info-try-follow-nearest-node))
1546 (save-excursion (forward-line 1) (eobp))
1547 (Info-next-preorder)))
1548
1549 (defun Info-follow-nearest-node ()
1550 "\\<Info-mode-map>Follow a node reference near point.
1551 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1552 If no reference to follow, moves to the next node, or up if none."
1553 (interactive)
1554 (or (Info-try-follow-nearest-node)
1555 (Info-next-preorder)))
1556
1557 ;; Common subroutine.
1558 (defun Info-try-follow-nearest-node ()
1559 "Follow a node reference near point. Return non-nil if successful."
1560 (let (node)
1561 (cond
1562 ((setq node (Info-get-token (point) "\\*note[ \n]"
1563 "\\*note[ \n]\\([^:]*\\):"))
1564 (Info-follow-reference node))
1565 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1566 (Info-goto-node node))
1567 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1568 (Info-menu node))
1569 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1570 (Info-goto-node node))
1571 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1572 (Info-goto-node node))
1573 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1574 (Info-goto-node "Top"))
1575 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1576 (Info-goto-node node)))
1577 node))
1578 \f
1579 (defvar Info-mode-map nil
1580 "Keymap containing Info commands.")
1581 (if Info-mode-map
1582 nil
1583 (setq Info-mode-map (make-keymap))
1584 (suppress-keymap Info-mode-map)
1585 (define-key Info-mode-map "." 'beginning-of-buffer)
1586 (define-key Info-mode-map " " 'Info-scroll-up)
1587 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1588 (define-key Info-mode-map "\t" 'Info-next-reference)
1589 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1590 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1591 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1592 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1593 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1594 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1595 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1596 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1597 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1598 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1599 (define-key Info-mode-map "0" 'undefined)
1600 (define-key Info-mode-map "?" 'Info-summary)
1601 (define-key Info-mode-map "]" 'Info-forward-node)
1602 (define-key Info-mode-map "[" 'Info-backward-node)
1603 (define-key Info-mode-map "<" 'Info-top-node)
1604 (define-key Info-mode-map ">" 'Info-final-node)
1605 (define-key Info-mode-map "b" 'beginning-of-buffer)
1606 (define-key Info-mode-map "d" 'Info-directory)
1607 (define-key Info-mode-map "e" 'Info-edit)
1608 (define-key Info-mode-map "f" 'Info-follow-reference)
1609 (define-key Info-mode-map "g" 'Info-goto-node)
1610 (define-key Info-mode-map "h" 'Info-help)
1611 (define-key Info-mode-map "i" 'Info-index)
1612 (define-key Info-mode-map "l" 'Info-last)
1613 (define-key Info-mode-map "m" 'Info-menu)
1614 (define-key Info-mode-map "n" 'Info-next)
1615 (define-key Info-mode-map "p" 'Info-prev)
1616 (define-key Info-mode-map "q" 'Info-exit)
1617 (define-key Info-mode-map "s" 'Info-search)
1618 ;; For consistency with Rmail.
1619 (define-key Info-mode-map "\M-s" 'Info-search)
1620 (define-key Info-mode-map "t" 'Info-top-node)
1621 (define-key Info-mode-map "u" 'Info-up)
1622 (define-key Info-mode-map "," 'Info-index-next)
1623 (define-key Info-mode-map "\177" 'Info-scroll-down)
1624 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1625 )
1626
1627 (defun Info-check-pointer (item)
1628 ;; Non-nil if ITEM is present in this node.
1629 (condition-case nil
1630 (Info-extract-pointer item)
1631 (error nil)))
1632
1633 (easy-menu-define Info-mode-menu Info-mode-map
1634 "Menu for info files."
1635 '("Info"
1636 ["Up" Info-up (Info-check-pointer "up")]
1637 ["Next" Info-next (Info-check-pointer "next")]
1638 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1639 ("Menu item" ["You should never see this" report-emacs-bug t])
1640 ("Reference" ["You should never see this" report-emacs-bug t])
1641 ["Search..." Info-search t]
1642 ["Goto node..." Info-goto-node t]
1643 ["Last" Info-last Info-history]
1644 ["Exit" Info-exit t]))
1645
1646 (defvar Info-menu-last-node nil)
1647 ;; Last node the menu was created for.
1648
1649 (defun Info-menu-update ()
1650 ;; Update the Info menu for the current node.
1651 (condition-case nil
1652 (if (or (not (eq major-mode 'Info-mode))
1653 (eq Info-current-node Info-menu-last-node))
1654 ()
1655 ;; Update menu menu.
1656 (let* ((Info-complete-menu-buffer (current-buffer))
1657 (items (nreverse (condition-case nil
1658 (Info-complete-menu-item
1659 "" (lambda (e) t) t)
1660 (error nil))))
1661 entries current
1662 (number 0))
1663 (while (and items (< number 9))
1664 (setq current (car items)
1665 items (cdr items)
1666 number (1+ number))
1667 (setq entries (cons `[,current
1668 (Info-menu ,current)
1669 :keys ,(format "%d" number)]
1670 entries)))
1671 (if items
1672 (setq entries (cons ["Other..." Info-menu t] entries)))
1673 (or entries
1674 (setq entries (list ["No menu" nil nil])))
1675 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1676 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1677 (let ((items nil)
1678 str i entries current
1679 (number 0))
1680 (save-excursion
1681 (goto-char (point-min))
1682 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1683 (setq str (buffer-substring
1684 (match-beginning 1)
1685 (1- (point))))
1686 (setq i 0)
1687 (while (setq i (string-match "[ \n\t]+" str i))
1688 (setq str (concat (substring str 0 i) " "
1689 (substring str (match-end 0))))
1690 (setq i (1+ i)))
1691 (setq items
1692 (cons str items))))
1693 (while (and items (< number 9))
1694 (setq current (car items)
1695 items (cdr items)
1696 number (1+ number))
1697 (setq entries (cons `[,current
1698 (Info-follow-reference ,current)
1699 t]
1700 entries)))
1701 (if items
1702 (setq entries (cons ["Other..." Info-follow-reference t]
1703 entries)))
1704 (or entries
1705 (setq entries (list ["No references" nil nil])))
1706 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1707 ;; Update last seen node.
1708 (setq Info-menu-last-node (current-buffer)))
1709 ;; Try to avoid entering infinite beep mode in case of errors.
1710 (error (ding))))
1711
1712 \f
1713 ;; Info mode is suitable only for specially formatted data.
1714 (put 'info-mode 'mode-class 'special)
1715
1716 (defun Info-mode ()
1717 "\\<Info-mode-map>
1718 Info mode provides commands for browsing through the Info documentation tree.
1719 Documentation in Info is divided into \"nodes\", each of which discusses
1720 one topic and contains references to other nodes which discuss related
1721 topics. Info has commands to follow the references and show you other nodes.
1722
1723 \\[Info-help] Invoke the Info tutorial.
1724
1725 Selecting other nodes:
1726 \\[Info-mouse-follow-nearest-node]
1727 Follow a node reference you click on.
1728 This works with menu items, cross references, and
1729 the \"next\", \"previous\" and \"up\", depending on where you click.
1730 \\[Info-next] Move to the \"next\" node of this node.
1731 \\[Info-prev] Move to the \"previous\" node of this node.
1732 \\[Info-up] Move \"up\" from this node.
1733 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1734 Picking a menu item causes another node to be selected.
1735 \\[Info-directory] Go to the Info directory node.
1736 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1737 \\[Info-last] Move to the last node you were at.
1738 \\[Info-index] Look up a topic in this file's Index and move to that node.
1739 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1740
1741 Moving within a node:
1742 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1743 already visible, try to go to the next menu entry, or up if there is none.
1744 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1745 already visible, try to go to the previous menu entry, or up if there is none.
1746 \\[beginning-of-buffer] Go to beginning of node.
1747
1748 Advanced commands:
1749 \\[Info-exit] Quit Info: reselect previously selected buffer.
1750 \\[Info-edit] Edit contents of selected node.
1751 1 Pick first item in node's menu.
1752 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1753 \\[Info-goto-node] Move to node specified by name.
1754 You may include a filename as well, as (FILENAME)NODENAME.
1755 \\[universal-argument] \\[info] Move to new Info file with completion.
1756 \\[Info-search] Search through this Info file for specified regexp,
1757 and select the node in which the next occurrence is found.
1758 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1759 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1760 (kill-all-local-variables)
1761 (setq major-mode 'Info-mode)
1762 (setq mode-name "Info")
1763 (setq tab-width 8)
1764 (use-local-map Info-mode-map)
1765 (make-local-hook 'activate-menubar-hook)
1766 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1767 (set-syntax-table text-mode-syntax-table)
1768 (setq local-abbrev-table text-mode-abbrev-table)
1769 (setq case-fold-search t)
1770 (setq buffer-read-only t)
1771 (make-local-variable 'Info-current-file)
1772 (make-local-variable 'Info-current-subfile)
1773 (make-local-variable 'Info-current-node)
1774 (make-local-variable 'Info-tag-table-marker)
1775 (setq Info-tag-table-marker (make-marker))
1776 (make-local-variable 'Info-tag-table-buffer)
1777 (setq Info-tag-table-buffer nil)
1778 (make-local-variable 'Info-history)
1779 (make-local-variable 'Info-index-alternatives)
1780 (if (memq (framep (selected-frame)) '(x pc w32))
1781 (progn
1782 (make-face 'info-node)
1783 (make-face 'info-menu-5)
1784 (make-face 'info-xref)
1785 (or (face-differs-from-default-p 'info-node)
1786 (if (face-differs-from-default-p 'bold-italic)
1787 (copy-face 'bold-italic 'info-node)
1788 (copy-face 'bold 'info-node)))
1789 (or (face-differs-from-default-p 'info-menu-5)
1790 (set-face-underline-p 'info-menu-5 t))
1791 (or (face-differs-from-default-p 'info-xref)
1792 (copy-face 'bold 'info-xref)))
1793 (setq Info-fontify nil))
1794 (Info-set-mode-line)
1795 (run-hooks 'Info-mode-hook))
1796
1797 (defvar Info-edit-map nil
1798 "Local keymap used within `e' command of Info.")
1799 (if Info-edit-map
1800 nil
1801 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1802 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1803
1804 ;; Info-edit mode is suitable only for specially formatted data.
1805 (put 'info-edit-mode 'mode-class 'special)
1806
1807 (defun Info-edit-mode ()
1808 "Major mode for editing the contents of an Info node.
1809 Like text mode with the addition of `Info-cease-edit'
1810 which returns to Info mode for browsing.
1811 \\{Info-edit-map}"
1812 (use-local-map Info-edit-map)
1813 (setq major-mode 'Info-edit-mode)
1814 (setq mode-name "Info Edit")
1815 (kill-local-variable 'mode-line-buffer-identification)
1816 (setq buffer-read-only nil)
1817 (force-mode-line-update)
1818 (buffer-enable-undo (current-buffer))
1819 (run-hooks 'Info-edit-mode-hook))
1820
1821 (defun Info-edit ()
1822 "Edit the contents of this Info node.
1823 Allowed only if variable `Info-enable-edit' is non-nil."
1824 (interactive)
1825 (or Info-enable-edit
1826 (error "Editing info nodes is not enabled"))
1827 (Info-edit-mode)
1828 (message "%s" (substitute-command-keys
1829 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1830
1831 (defun Info-cease-edit ()
1832 "Finish editing Info node; switch back to Info proper."
1833 (interactive)
1834 ;; Do this first, so nothing has changed if user C-g's at query.
1835 (and (buffer-modified-p)
1836 (y-or-n-p "Save the file? ")
1837 (save-buffer))
1838 (use-local-map Info-mode-map)
1839 (setq major-mode 'Info-mode)
1840 (setq mode-name "Info")
1841 (Info-set-mode-line)
1842 (setq buffer-read-only t)
1843 (force-mode-line-update)
1844 (and (marker-position Info-tag-table-marker)
1845 (buffer-modified-p)
1846 (message "Tags may have changed. Use Info-tagify if necessary")))
1847 \f
1848 (defvar Info-file-list-for-emacs
1849 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1850 "List of Info files that describe Emacs commands.
1851 An element can be a file name, or a list of the form (PREFIX . FILE)
1852 where PREFIX is a name prefix and FILE is the file to look in.
1853 If the element is just a file name, the file name also serves as the prefix.")
1854
1855 (defun Info-find-emacs-command-nodes (command)
1856 "Return a list of locations documenting COMMAND.
1857 The `info-file' property of COMMAND says which Info manual to search.
1858 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1859 defines heuristics for which Info manual to try.
1860 The locations are of the format used in Info-history, i.e.
1861 \(FILENAME NODENAME BUFFERPOS\)."
1862 (let ((where '())
1863 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1864 ":\\s *\\(.*\\)\\.$"))
1865 (info-file "emacs")) ;default
1866 ;; Determine which info file this command is documented in.
1867 (if (get command 'info-file)
1868 (setq info-file (get command 'info-file))
1869 ;; If it doesn't say explicitly, test its name against
1870 ;; various prefixes that we know.
1871 (let ((file-list Info-file-list-for-emacs))
1872 (while file-list
1873 (let* ((elt (car file-list))
1874 (name (if (consp elt)
1875 (car elt)
1876 elt))
1877 (file (if (consp elt) (cdr elt) elt))
1878 (regexp (concat "\\`" (regexp-quote name)
1879 "\\(\\'\\|-\\)")))
1880 (if (string-match regexp (symbol-name command))
1881 (setq info-file file file-list nil))
1882 (setq file-list (cdr file-list))))))
1883 (save-excursion
1884 (condition-case nil
1885 (Info-find-node info-file "Command Index")
1886 ;; Some manuals may not have a separate Command Index node,
1887 ;; so try just Index instead.
1888 (error
1889 (Info-find-node info-file "Index")))
1890 ;; Take the index node off the Info history.
1891 (setq Info-history (cdr Info-history))
1892 (goto-char (point-max))
1893 (while (re-search-backward cmd-desc nil t)
1894 (setq where (cons (list Info-current-file
1895 (buffer-substring
1896 (match-beginning 1)
1897 (match-end 1))
1898 0)
1899 where)))
1900 where)))
1901
1902 ;;;###autoload
1903 (defun Info-goto-emacs-command-node (command)
1904 "Go to the Info node in the Emacs manual for command COMMAND.
1905 The command is found by looking up in Emacs manual's Command Index
1906 or in another manual found via COMMAND's `info-file' property or
1907 the variable `Info-file-list-for-emacs'."
1908 (interactive "CFind documentation for command: ")
1909 (or (commandp command)
1910 (signal 'wrong-type-argument (list 'commandp command)))
1911 (let ((where (Info-find-emacs-command-nodes command)))
1912 (if where
1913 (let ((num-matches (length where)))
1914 ;; Get Info running, and pop to it in another window.
1915 (save-window-excursion
1916 (info))
1917 ;; FIXME It would be cool if this could use a buffer other
1918 ;; than *info*.
1919 (pop-to-buffer "*info*")
1920 (Info-find-node (car (car where))
1921 (car (cdr (car where))))
1922 (if (> num-matches 1)
1923 (progn
1924 ;; Info-find-node already pushed (car where) onto
1925 ;; Info-history. Put the other nodes that were found on
1926 ;; the history.
1927 (setq Info-history (nconc (cdr where) Info-history))
1928 (message "Found %d other entr%s. Use %s to see %s."
1929 (1- num-matches)
1930 (if (> num-matches 2) "ies" "y")
1931 (substitute-command-keys "\\[Info-last]")
1932 (if (> num-matches 2) "them" "it")))))
1933 (error "Couldn't find documentation for %s" command))))
1934
1935 ;;;###autoload
1936 (defun Info-goto-emacs-key-command-node (key)
1937 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1938 Interactively, if the binding is execute-extended-command, a command is read.
1939 The command is found by looking up in Emacs manual's Command Index
1940 or in another manual found via COMMAND's `info-file' property or
1941 the variable `Info-file-list-for-emacs'."
1942 (interactive "kFind documentation for key:")
1943 (let ((command (key-binding key)))
1944 (cond ((null command)
1945 (message "%s is undefined" (key-description key)))
1946 ((and (interactive-p)
1947 (eq command 'execute-extended-command))
1948 (Info-goto-emacs-command-node
1949 (read-command "Find documentation for command: ")))
1950 (t
1951 (Info-goto-emacs-command-node command)))))
1952 \f
1953 (defcustom Info-title-face-alist
1954 '((?* bold underline)
1955 (?= bold-italic underline)
1956 (?- italic underline))
1957 "*Alist of face or list of faces to use for pseudo-underlined titles.
1958 The alist key is the character the title is underlined with (?*, ?= or ?-)."
1959 :type '(repeat (list character face face))
1960 :group 'info)
1961
1962 (defun Info-fontify-node ()
1963 (save-excursion
1964 (let ((buffer-read-only nil))
1965 (goto-char (point-min))
1966 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1967 (progn
1968 (goto-char (match-end 0))
1969 (while
1970 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1971 (goto-char (match-end 0))
1972 (put-text-property (match-beginning 1) (match-end 1)
1973 'face 'info-xref)
1974 (put-text-property (match-beginning 1) (match-end 1)
1975 'mouse-face 'highlight))))
1976 (goto-char (point-min))
1977 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
1978 nil t)
1979 (put-text-property (match-beginning 1) (match-end 1)
1980 'face
1981 (cdr (assq (preceding-char) Info-title-face-alist)))
1982 (put-text-property (match-end 1) (match-end 2)
1983 'invisible t))
1984 (goto-char (point-min))
1985 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
1986 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1987 nil
1988 (put-text-property (match-beginning 1) (match-end 1)
1989 'face 'info-xref)
1990 (put-text-property (match-beginning 1) (match-end 1)
1991 'mouse-face 'highlight)))
1992 (goto-char (point-min))
1993 (if (and (search-forward "\n* Menu:" nil t)
1994 (not (string-match "\\<Index\\>" Info-current-node))
1995 ;; Don't take time to annotate huge menus
1996 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
1997 (let ((n 0))
1998 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1999 (setq n (1+ n))
2000 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2001 (put-text-property (match-beginning 0)
2002 (1+ (match-beginning 0))
2003 'face 'info-menu-5))
2004 (put-text-property (match-beginning 1) (match-end 1)
2005 'face 'info-node)
2006 (put-text-property (match-beginning 1) (match-end 1)
2007 'mouse-face 'highlight))))
2008 (set-buffer-modified-p nil))))
2009 \f
2010
2011 ;; When an Info buffer is killed, make sure the associated tags buffer
2012 ;; is killed too.
2013 (defun Info-kill-buffer ()
2014 (and (eq major-mode 'Info-mode)
2015 Info-tag-table-buffer
2016 (kill-buffer Info-tag-table-buffer)))
2017
2018 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2019
2020
2021 (provide 'info)
2022
2023 ;;; info.el ends here