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