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