(Info-menu-entry-name-re): Allow newlines in menu entry names.
[emacs.git] / lisp / info.el
blob3082aa7231ca69c007ebbc9216e3d88bbcc997ad
1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
4 ;; 2002, 2003
5 ;; Free Software Foundation, Inc.
7 ;; Maintainer: FSF
8 ;; Keywords: help
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; Note that nowadays we expect info files to be made using makeinfo.
30 ;; In particular we make these assumptions:
31 ;; - a menu item MAY contain colons but not colon-space ": "
32 ;; - a menu item ending with ": " (but not ":: ") is an index entry
33 ;; - a node name MAY NOT contain a colon
34 ;; This distinction is to support indexing of computer programming
35 ;; language terms that may contain ":" but not ": ".
37 ;;; Code:
39 (eval-when-compile (require 'jka-compr))
41 (defgroup info nil
42 "Info subsystem"
43 :group 'help
44 :group 'docs)
47 (defvar Info-history nil
48 "List of info nodes user has visited.
49 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
51 (defcustom Info-enable-edit nil
52 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
53 This is convenient if you want to write info files by hand.
54 However, we recommend that you not do this.
55 It is better to write a Texinfo file and generate the Info file from that,
56 because that gives you a printed manual as well."
57 :type 'boolean
58 :group 'info)
60 (defvar Info-enable-active-nodes nil
61 "Non-nil allows Info to execute Lisp code associated with nodes.
62 The Lisp code is executed when the node is selected.")
63 (put 'Info-enable-active-nodes 'risky-local-variable t)
65 (defface info-node
66 '((((class color) (background light)) (:foreground "brown" :weight bold :slant italic))
67 (((class color) (background dark)) (:foreground "white" :weight bold :slant italic))
68 (t (:weight bold :slant italic)))
69 "Face for Info node names."
70 :group 'info)
72 (defface info-menu-5
73 '((((class color)) (:foreground "red1"))
74 (t (:underline t)))
75 "Face for every third `*' in an Info menu."
76 :group 'info)
78 (defface info-xref
79 '((((class color) (background light)) (:foreground "magenta4" :weight bold))
80 (((class color) (background dark)) (:foreground "cyan" :weight bold))
81 (t (:weight bold)))
82 "Face for Info cross-references."
83 :group 'info)
85 (defcustom Info-fontify-maximum-menu-size 100000
86 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
87 :type 'integer
88 :group 'info)
90 (defcustom Info-use-header-line t
91 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
92 A header-line does not scroll with the rest of the buffer."
93 :type 'boolean
94 :group 'info)
96 (defface info-header-xref
97 '((t (:inherit info-xref)))
98 "Face for Info cross-references in a node header."
99 :group 'info)
101 (defface info-header-node
102 '((t (:inherit info-node)))
103 "Face for Info nodes in a node header."
104 :group 'info)
106 (defvar Info-directory-list nil
107 "List of directories to search for Info documentation files.
108 If nil, meaning not yet initialized, Info uses the environment
109 variable INFOPATH to initialize it, or `Info-default-directory-list'
110 if there is no INFOPATH variable in the environment, or the
111 concatenation of the two if INFOPATH ends with a colon.
113 When `Info-directory-list' is initialized from the value of
114 `Info-default-directory-list', and Emacs is installed in one of the
115 standard directories, the directory of Info files that come with Emacs
116 is put last (so that local Info files override standard ones).
118 When `Info-directory-list' is initialized from the value of
119 `Info-default-directory-list', and Emacs is not installed in one
120 of the standard directories, the first element of the resulting
121 list is the directory where Emacs installs the Info files that
122 come with it. This is so that Emacs's own manual, which suits the
123 version of Emacs you are using, will always be found first. This
124 is useful when you install an experimental version of Emacs without
125 removing the standard installation.
127 If you want to override the order of directories in
128 `Info-default-directory-list', set INFOPATH in the environment.
130 If you run the Emacs executable from the `src' directory in the Emacs
131 source tree, and INFOPATH is not defined, the `info' directory in the
132 source tree is used as the first element of `Info-directory-list', in
133 place of the installation Info directory. This is useful when you run
134 a version of Emacs without installing it.")
136 (defcustom Info-additional-directory-list nil
137 "List of additional directories to search for Info documentation files.
138 These directories are searched after those in `Info-directory-list'."
139 :type '(repeat directory)
140 :group 'info)
142 (defcustom Info-scroll-prefer-subnodes nil
143 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
144 If this is non-nil, and you scroll far enough in a node that its menu
145 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
146 moves to a subnode indicated by the following menu item. This means
147 that you visit a subnode before getting to the end of the menu.
149 Setting this option to nil results in behavior similar to the stand-alone
150 Info reader program, which visits the first subnode from the menu only
151 when you hit the end of the current node."
152 :type 'boolean
153 :group 'info)
155 (defcustom Info-hide-note-references t
156 "*If non-nil, hide the tag and section reference in *note and * menu items.
157 Also replaces the \"*note\" text with \"see\".
158 If value is non-nil but not t, the reference section is still shown."
159 :version "21.4"
160 :type '(choice (const :tag "No reformatting" nil)
161 (const :tag "Replace tag and hide reference" t)
162 (other :tag "Replace only tag" tag))
163 :group 'info)
165 (defcustom Info-refill-paragraphs nil
166 "*If non-nil, attempt to refill paragraphs with hidden references.
167 This refilling may accidentally remove explicit line breaks in the info
168 file, so be prepared for a few surprises if you enable this feature."
169 :version "21.4"
170 :type 'boolean
171 :group 'info)
173 (defcustom Info-mode-hook
174 ;; Try to obey obsolete Info-fontify settings.
175 (unless (and (boundp 'Info-fontify) (null Info-fontify))
176 '(turn-on-font-lock))
177 "Hooks run when `info-mode' is called."
178 :type 'hook
179 :group 'info)
181 (defvar Info-current-file nil
182 "Info file that Info is now looking at, or nil.
183 This is the name that was specified in Info, not the actual file name.
184 It doesn't contain directory names or file name extensions added by Info.
185 Can also be t when using `Info-on-current-buffer'.")
187 (defvar Info-current-subfile nil
188 "Info subfile that is actually in the *info* buffer now.
189 nil if current info file is not split into subfiles.")
191 (defvar Info-current-node nil
192 "Name of node that Info is now looking at, or nil.")
194 (defvar Info-tag-table-marker nil
195 "Marker pointing at beginning of current Info file's tag table.
196 Marker points nowhere if file has no tag table.")
198 (defvar Info-tag-table-buffer nil
199 "Buffer used for indirect tag tables.")
201 (defvar Info-current-file-completions nil
202 "Cached completion list for current Info file.")
204 (defvar Info-index-alternatives nil
205 "List of possible matches for last `Info-index' command.")
207 (defvar Info-standalone nil
208 "Non-nil if Emacs was started solely as an Info browser.")
210 (defvar Info-suffix-list
211 ;; The MS-DOS list should work both when long file names are
212 ;; supported (Windows 9X), and when only 8+3 file names are available.
213 (if (eq system-type 'ms-dos)
214 '( (".gz" . "gunzip")
215 (".z" . "gunzip")
216 (".bz2" . ("bzip2" "-dc"))
217 (".inz" . "gunzip")
218 (".igz" . "gunzip")
219 (".info.Z" . "gunzip")
220 (".info.gz" . "gunzip")
221 ("-info.Z" . "gunzip")
222 ("-info.gz" . "gunzip")
223 ("/index.gz". "gunzip")
224 ("/index.z" . "gunzip")
225 (".inf" . nil)
226 (".info" . nil)
227 ("-info" . nil)
228 ("/index" . nil)
229 ("" . nil))
230 '( (".info.Z". "uncompress")
231 (".info.Y". "unyabba")
232 (".info.gz". "gunzip")
233 (".info.z". "gunzip")
234 (".info.bz2" . ("bzip2" "-dc"))
235 (".info". nil)
236 ("-info.Z". "uncompress")
237 ("-info.Y". "unyabba")
238 ("-info.gz". "gunzip")
239 ("-info.bz2" . ("bzip2" "-dc"))
240 ("-info.z". "gunzip")
241 ("-info". nil)
242 ("/index.Z". "uncompress")
243 ("/index.Y". "unyabba")
244 ("/index.gz". "gunzip")
245 ("/index.z". "gunzip")
246 ("/index.bz2". ("bzip2" "-dc"))
247 ("/index". nil)
248 (".Z". "uncompress")
249 (".Y". "unyabba")
250 (".gz". "gunzip")
251 (".z". "gunzip")
252 (".bz2" . ("bzip2" "-dc"))
253 ("". nil)))
254 "List of file name suffixes and associated decoding commands.
255 Each entry should be (SUFFIX . STRING); the file is given to
256 the command as standard input.
258 STRING may be a list of strings. In that case, the first element is
259 the command name, and the rest are arguments to that command.
261 If STRING is nil, no decoding is done.
262 Because the SUFFIXes are tried in order, the empty string should
263 be last in the list.")
265 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
266 ;; First, on MS-DOS with no long file names support, delete some of
267 ;; the extension in FILENAME to make room.
268 (defun info-insert-file-contents-1 (filename suffix lfn)
269 (if lfn ; long file names are supported
270 (concat filename suffix)
271 (let* ((sans-exts (file-name-sans-extension filename))
272 ;; How long is the extension in FILENAME (not counting the dot).
273 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
274 ext-left)
275 ;; SUFFIX starts with a dot. If FILENAME already has one,
276 ;; get rid of the one in SUFFIX (unless suffix is empty).
277 (or (and (<= ext-len 0)
278 (not (eq (aref filename (1- (length filename))) ?.)))
279 (= (length suffix) 0)
280 (setq suffix (substring suffix 1)))
281 ;; How many chars of that extension should we keep?
282 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
283 ;; Get rid of the rest of the extension, and add SUFFIX.
284 (concat (substring filename 0 (- (length filename)
285 (- ext-len ext-left)))
286 suffix))))
288 (defun info-file-exists-p (filename)
289 (and (file-exists-p filename)
290 (not (file-directory-p filename))))
292 (defun info-insert-file-contents (filename &optional visit)
293 "Insert the contents of an info file in the current buffer.
294 Do the right thing if the file has been compressed or zipped."
295 (let* ((tail Info-suffix-list)
296 (lfn (if (fboundp 'msdos-long-file-names)
297 (msdos-long-file-names)
299 (check-short (and (fboundp 'msdos-long-file-names)
300 lfn))
301 fullname decoder done)
302 (if (info-file-exists-p filename)
303 ;; FILENAME exists--see if that name contains a suffix.
304 ;; If so, set DECODE accordingly.
305 (progn
306 (while (and tail
307 (not (string-match
308 (concat (regexp-quote (car (car tail))) "$")
309 filename)))
310 (setq tail (cdr tail)))
311 (setq fullname filename
312 decoder (cdr (car tail))))
313 ;; Try adding suffixes to FILENAME and see if we can find something.
314 (while (and tail (not done))
315 (setq fullname (info-insert-file-contents-1 filename
316 (car (car tail)) lfn))
317 (if (info-file-exists-p fullname)
318 (setq done t
319 ;; If we found a file with a suffix, set DECODER
320 ;; according to the suffix.
321 decoder (cdr (car tail)))
322 ;; When the MS-DOS port runs on Windows, we need to check
323 ;; the short variant of a long file name as well.
324 (when check-short
325 (setq fullname (info-insert-file-contents-1 filename
326 (car (car tail)) nil))
327 (if (info-file-exists-p fullname)
328 (setq done t
329 decoder (cdr (car tail))))))
330 (setq tail (cdr tail)))
331 (or tail
332 (error "Can't find %s or any compressed version of it" filename)))
333 ;; check for conflict with jka-compr
334 (if (and (featurep 'jka-compr)
335 (jka-compr-installed-p)
336 (jka-compr-get-compression-info fullname))
337 (setq decoder nil))
338 (if decoder
339 (progn
340 (insert-file-contents-literally fullname visit)
341 (let ((buffer-read-only nil)
342 (coding-system-for-write 'no-conversion)
343 (default-directory (or (file-name-directory fullname)
344 default-directory)))
345 (or (consp decoder)
346 (setq decoder (list decoder)))
347 (apply 'call-process-region (point-min) (point-max)
348 (car decoder) t t nil (cdr decoder))))
349 (insert-file-contents fullname visit))))
351 (defun Info-default-dirs ()
352 (let ((source (expand-file-name "info/" source-directory))
353 (sibling (if installation-directory
354 (expand-file-name "info/" installation-directory)
355 (if invocation-directory
356 (let ((infodir (expand-file-name
357 "../info/"
358 invocation-directory)))
359 (if (file-exists-p infodir)
360 infodir
361 (setq infodir (expand-file-name
362 "../../../info/"
363 invocation-directory))
364 (and (file-exists-p infodir)
365 infodir))))))
366 alternative)
367 (setq alternative
368 (if (and sibling (file-exists-p sibling))
369 ;; Uninstalled, Emacs builddir != srcdir.
370 sibling
371 ;; Uninstalled, builddir == srcdir
372 source))
373 (if (or (member alternative Info-default-directory-list)
374 ;; On DOS/NT, we use movable executables always,
375 ;; and we must always find the Info dir at run time.
376 (if (memq system-type '(ms-dos windows-nt))
378 ;; Use invocation-directory for Info
379 ;; only if we used it for exec-directory also.
380 (not (string= exec-directory
381 (expand-file-name "lib-src/"
382 installation-directory))))
383 (not (file-exists-p alternative)))
384 Info-default-directory-list
385 ;; `alternative' contains the Info files that came with this
386 ;; version, so we should look there first. `Info-insert-dir'
387 ;; currently expects to find `alternative' first on the list.
388 (cons alternative
389 (reverse (cdr (reverse Info-default-directory-list)))))))
391 (defun info-initialize ()
392 "Initialize `Info-directory-list', if that hasn't been done yet."
393 (unless Info-directory-list
394 (let ((path (getenv "INFOPATH")))
395 (setq Info-directory-list
396 (prune-directory-list
397 (if path
398 (if (string-match ":\\'" path)
399 (append (split-string (substring path 0 -1)
400 (regexp-quote path-separator))
401 (Info-default-dirs))
402 (split-string path (regexp-quote path-separator)))
403 (Info-default-dirs)))))))
405 ;;;###autoload
406 (defun info-other-window (&optional file)
407 "Like `info' but show the Info buffer in another window."
408 (interactive (if current-prefix-arg
409 (list (read-file-name "Info file name: " nil nil t))))
410 (let (same-window-buffer-names)
411 (info file)))
413 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
415 ;;;###autoload
416 (defun info (&optional file)
417 "Enter Info, the documentation browser.
418 Optional argument FILE specifies the file to examine;
419 the default is the top-level directory of Info.
420 Called from a program, FILE may specify an Info node of the form
421 `(FILENAME)NODENAME'.
423 In interactive use, a prefix argument directs this command
424 to read a file name from the minibuffer.
426 The search path for Info files is in the variable `Info-directory-list'.
427 The top-level Info directory is made by combining all the files named `dir'
428 in all the directories in that path."
429 (interactive (if current-prefix-arg
430 (list (read-file-name "Info file name: " nil nil t))))
431 (if file
432 (progn
433 (pop-to-buffer "*info*")
434 ;; If argument already contains parentheses, don't add another set
435 ;; since the argument will then be parsed improperly. This also
436 ;; has the added benefit of allowing node names to be included
437 ;; following the parenthesized filename.
438 (if (and (stringp file) (string-match "(.*)" file))
439 (Info-goto-node file)
440 (Info-goto-node (concat "(" file ")"))))
441 (if (get-buffer "*info*")
442 (pop-to-buffer "*info*")
443 (Info-directory))))
445 ;;;###autoload
446 (defun info-emacs-manual ()
447 "Display the Emacs manual in Info mode."
448 (interactive)
449 (info "emacs"))
451 ;;;###autoload
452 (defun info-standalone ()
453 "Run Emacs as a standalone Info reader.
454 Usage: emacs -f info-standalone [filename]
455 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
456 (setq Info-standalone t)
457 (if (and command-line-args-left
458 (not (string-match "^-" (car command-line-args-left))))
459 (condition-case err
460 (progn
461 (info (car command-line-args-left))
462 (setq command-line-args-left (cdr command-line-args-left)))
463 (error (send-string-to-terminal
464 (format "%s\n" (if (eq (car-safe err) 'error)
465 (nth 1 err) err)))
466 (save-buffers-kill-emacs)))
467 (info)))
469 ;; See if the accessible portion of the buffer begins with a node
470 ;; delimiter, and the node header line which follows matches REGEXP.
471 ;; Typically, this test will be followed by a loop that examines the
472 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
473 ;; to have the overhead of this special test inside the loop.
475 ;; This function changes match-data, but supposedly the caller might
476 ;; want to use the results of re-search-backward.
478 ;; The return value is the value of point at the beginning of matching
479 ;; REGEXP, if the function succeeds, nil otherwise.
480 (defun Info-node-at-bob-matching (regexp)
481 (and (bobp) ; are we at beginning of buffer?
482 (looking-at "\^_") ; does it begin with node delimiter?
483 (let (beg)
484 (forward-line 1)
485 (setq beg (point))
486 (forward-line 1) ; does the line after delimiter match REGEXP?
487 (re-search-backward regexp beg t))))
489 (defun Info-find-node (filename nodename &optional no-going-back)
490 "Go to an info node specified as separate FILENAME and NODENAME.
491 NO-GOING-BACK is non-nil if recovering from an error in this function;
492 it says do not attempt further (recursive) error recovery."
493 (info-initialize)
494 ;; Convert filename to lower case if not found as specified.
495 ;; Expand it.
496 (if (stringp filename)
497 (let (temp temp-downcase found)
498 (setq filename (substitute-in-file-name filename))
499 (if (string= (downcase filename) "dir")
500 (setq found t)
501 (let ((dirs (if (string-match "^\\./" filename)
502 ;; If specified name starts with `./'
503 ;; then just try current directory.
504 '("./")
505 (if (file-name-absolute-p filename)
506 ;; No point in searching for an
507 ;; absolute file name
508 '(nil)
509 (if Info-additional-directory-list
510 (append Info-directory-list
511 Info-additional-directory-list)
512 Info-directory-list)))))
513 ;; Search the directory list for file FILENAME.
514 (while (and dirs (not found))
515 (setq temp (expand-file-name filename (car dirs)))
516 (setq temp-downcase
517 (expand-file-name (downcase filename) (car dirs)))
518 ;; Try several variants of specified name.
519 (let ((suffix-list Info-suffix-list)
520 (lfn (if (fboundp 'msdos-long-file-names)
521 (msdos-long-file-names)
522 t)))
523 (while (and suffix-list (not found))
524 (cond ((info-file-exists-p
525 (info-insert-file-contents-1
526 temp (car (car suffix-list)) lfn))
527 (setq found temp))
528 ((info-file-exists-p
529 (info-insert-file-contents-1
530 temp-downcase (car (car suffix-list)) lfn))
531 (setq found temp-downcase))
532 ((and (fboundp 'msdos-long-file-names)
534 (info-file-exists-p
535 (info-insert-file-contents-1
536 temp (car (car suffix-list)) nil)))
537 (setq found temp)))
538 (setq suffix-list (cdr suffix-list))))
539 (setq dirs (cdr dirs)))))
540 (if found
541 (setq filename found)
542 (error "Info file %s does not exist" filename))))
543 ;; Record the node we are leaving.
544 (if (and Info-current-file (not no-going-back))
545 (setq Info-history
546 (cons (list Info-current-file Info-current-node (point))
547 Info-history)))
548 ;; Go into info buffer.
549 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
550 (Info-find-node-2 filename nodename no-going-back))
552 (defun Info-on-current-buffer (&optional nodename)
553 "Use the `Info-mode' to browse the current info buffer.
554 If a prefix arg is provided, it queries for the NODENAME which
555 else defaults to \"Top\"."
556 (interactive
557 (list (if current-prefix-arg
558 (completing-read "Node name: " (Info-build-node-completions)
559 nil t "Top"))))
560 (unless nodename (setq nodename "Top"))
561 (info-initialize)
562 (Info-mode)
563 (set (make-local-variable 'Info-current-file) t)
564 (Info-find-node-2 nil nodename))
566 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
567 ;; but at least it keeps this routine (which is only for the benefit of
568 ;; makeinfo-buffer) out of the way of normal operations.
570 (defun Info-revert-find-node (filename nodename)
571 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
572 When *info* is already displaying FILENAME and NODENAME, the window position
573 is preserved, if possible."
574 (pop-to-buffer "*info*")
575 (let ((old-filename Info-current-file)
576 (old-nodename Info-current-node)
577 (pcolumn (current-column))
578 (pline (count-lines (point-min) (line-beginning-position)))
579 (wline (count-lines (point-min) (window-start)))
580 (old-history Info-history)
581 (new-history (and Info-current-file
582 (list Info-current-file Info-current-node (point)))))
583 (kill-buffer (current-buffer))
584 (Info-find-node filename nodename)
585 (setq Info-history old-history)
586 (if (and (equal old-filename Info-current-file)
587 (equal old-nodename Info-current-node))
588 (progn
589 ;; note goto-line is no good, we want to measure from point-min
590 (beginning-of-buffer)
591 (forward-line wline)
592 (set-window-start (selected-window) (point))
593 (beginning-of-buffer)
594 (forward-line pline)
595 (move-to-column pcolumn))
596 ;; only add to the history when coming from a different file+node
597 (if new-history
598 (setq Info-history (cons new-history Info-history))))))
600 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
601 "Find a node in a tag table.
602 MARKER specifies the buffer and position to start searching at.
603 REGEXP is a regular expression matching nodes or references. Its first
604 group should match `Node:' or `Ref:'.
605 CASE-FOLD t means search for a case-insensitive match.
606 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
607 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
608 where the match was found, and MODE is `major-mode' of the buffer in
609 which the match was found."
610 (let ((case-fold-search case-fold))
611 (save-excursion
612 (set-buffer (marker-buffer marker))
613 (goto-char marker)
615 ;; Search tag table
616 (beginning-of-line)
617 (when (re-search-forward regexp nil t)
618 (list (string-equal "Ref:" (match-string 1))
619 (+ (point-min) (read (current-buffer)))
620 major-mode)))))
622 (defun Info-find-in-tag-table (marker regexp)
623 "Find a node in a tag table.
624 MARKER specifies the buffer and position to start searching at.
625 REGEXP is a regular expression matching nodes or references. Its first
626 group should match `Node:' or `Ref:'.
627 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
628 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
629 where the match was found, and MODE is `major-mode' of the buffer in
630 which the match was found.
631 This function tries to find a case-sensitive match first, then a
632 case-insensitive match is tried."
633 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
634 (when (null (car result))
635 (setq result (Info-find-in-tag-table-1 marker regexp t)))
636 result))
638 (defun Info-find-node-in-buffer-1 (regexp case-fold)
639 "Find a node or anchor in the current buffer.
640 REGEXP is a regular expression matching nodes or references. Its first
641 group should match `Node:' or `Ref:'.
642 CASE-FOLD t means search for a case-insensitive match.
643 Value is the position at which a match was found, or nil if not found."
644 (let ((case-fold-search case-fold)
645 found)
646 (save-excursion
647 (when (Info-node-at-bob-matching regexp)
648 (setq found (point)))
649 (while (and (not found)
650 (search-forward "\n\^_" nil t))
651 (forward-line 1)
652 (let ((beg (point)))
653 (forward-line 1)
654 (when (re-search-backward regexp beg t)
655 (beginning-of-line)
656 (setq found (point)))))
657 found)))
659 (defun Info-find-node-in-buffer (regexp)
660 "Find a node or anchor in the current buffer.
661 REGEXP is a regular expression matching nodes or references. Its first
662 group should match `Node:' or `Ref:'.
663 Value is the position at which a match was found, or nil if not found.
664 This function looks for a case-sensitive match first. If none is found,
665 a case-insensitive match is tried."
666 (or (Info-find-node-in-buffer-1 regexp nil)
667 (Info-find-node-in-buffer-1 regexp t)))
669 (defun Info-find-node-2 (filename nodename &optional no-going-back)
670 (buffer-disable-undo (current-buffer))
671 (or (eq major-mode 'Info-mode)
672 (Info-mode))
673 (widen)
674 (setq Info-current-node nil)
675 (unwind-protect
676 (let ((case-fold-search t)
677 anchorpos)
678 ;; Switch files if necessary
679 (or (null filename)
680 (equal Info-current-file filename)
681 (let ((buffer-read-only nil))
682 (setq Info-current-file nil
683 Info-current-subfile nil
684 Info-current-file-completions nil
685 buffer-file-name nil)
686 (erase-buffer)
687 (if (eq filename t)
688 (Info-insert-dir)
689 (info-insert-file-contents filename nil)
690 (setq default-directory (file-name-directory filename)))
691 (set-buffer-modified-p nil)
692 ;; See whether file has a tag table. Record the location if yes.
693 (goto-char (point-max))
694 (forward-line -8)
695 ;; Use string-equal, not equal, to ignore text props.
696 (if (not (or (string-equal nodename "*")
697 (not
698 (search-forward "\^_\nEnd tag table\n" nil t))))
699 (let (pos)
700 ;; We have a tag table. Find its beginning.
701 ;; Is this an indirect file?
702 (search-backward "\nTag table:\n")
703 (setq pos (point))
704 (if (save-excursion
705 (forward-line 2)
706 (looking-at "(Indirect)\n"))
707 ;; It is indirect. Copy it to another buffer
708 ;; and record that the tag table is in that buffer.
709 (let ((buf (current-buffer))
710 (tagbuf
711 (or Info-tag-table-buffer
712 (generate-new-buffer " *info tag table*"))))
713 (setq Info-tag-table-buffer tagbuf)
714 (save-excursion
715 (set-buffer tagbuf)
716 (buffer-disable-undo (current-buffer))
717 (setq case-fold-search t)
718 (erase-buffer)
719 (insert-buffer-substring buf))
720 (set-marker Info-tag-table-marker
721 (match-end 0) tagbuf))
722 (set-marker Info-tag-table-marker pos)))
723 (set-marker Info-tag-table-marker nil))
724 (setq Info-current-file
725 (if (eq filename t) "dir" filename))))
726 ;; Use string-equal, not equal, to ignore text props.
727 (if (string-equal nodename "*")
728 (progn (setq Info-current-node nodename)
729 (Info-set-mode-line))
730 ;; Possibilities:
732 ;; 1. Anchor found in tag table
733 ;; 2. Anchor *not* in tag table
735 ;; 3. Node found in tag table
736 ;; 4. Node *not* found in tag table, but found in file
737 ;; 5. Node *not* in tag table, and *not* in file
739 ;; *Or* the same, but in an indirect subfile.
741 ;; Search file for a suitable node.
742 (let ((guesspos (point-min))
743 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
744 (if (stringp nodename)
745 (regexp-quote nodename)
747 "\\) *[,\t\n\177]")))
749 (catch 'foo
751 ;; First, search a tag table, if any
752 (when (marker-position Info-tag-table-marker)
753 (let* ((m Info-tag-table-marker)
754 (found (Info-find-in-tag-table m regexp)))
756 (when found
757 ;; FOUND is (ANCHOR POS MODE).
758 (setq guesspos (nth 1 found))
760 ;; If this is an indirect file, determine which
761 ;; file really holds this node and read it in.
762 (unless (eq (nth 2 found) 'Info-mode)
763 ;; Note that the current buffer must be the
764 ;; *info* buffer on entry to
765 ;; Info-read-subfile. Thus the hackery above.
766 (setq guesspos (Info-read-subfile guesspos)))
768 ;; Handle anchor
769 (when (nth 0 found)
770 (goto-char (setq anchorpos guesspos))
771 (throw 'foo t)))))
773 ;; Else we may have a node, which we search for:
774 (goto-char (max (point-min)
775 (- (byte-to-position guesspos) 1000)))
777 ;; Now search from our advised position (or from beg of
778 ;; buffer) to find the actual node. First, check
779 ;; whether the node is right where we are, in case the
780 ;; buffer begins with a node.
781 (let ((pos (Info-find-node-in-buffer regexp)))
782 (when pos
783 (goto-char pos)
784 (throw 'foo t))
785 (error "No such anchor in tag table or node in tag table or file: %s"
786 nodename)))
788 (Info-select-node)
789 (goto-char (or anchorpos (point-min))))))
790 ;; If we did not finish finding the specified node,
791 ;; go back to the previous one.
792 (or Info-current-node no-going-back (null Info-history)
793 (let ((hist (car Info-history)))
794 (setq Info-history (cdr Info-history))
795 (Info-find-node (nth 0 hist) (nth 1 hist) t)
796 (goto-char (nth 2 hist))))))
798 ;; Cache the contents of the (virtual) dir file, once we have merged
799 ;; it for the first time, so we can save time subsequently.
800 (defvar Info-dir-contents nil)
802 ;; Cache for the directory we decided to use for the default-directory
803 ;; of the merged dir text.
804 (defvar Info-dir-contents-directory nil)
806 ;; Record the file attributes of all the files from which we
807 ;; constructed Info-dir-contents.
808 (defvar Info-dir-file-attributes nil)
810 (defvar Info-dir-file-name nil)
812 ;; Construct the Info directory node by merging the files named `dir'
813 ;; from various directories. Set the *info* buffer's
814 ;; default-directory to the first directory we actually get any text
815 ;; from.
816 (defun Info-insert-dir ()
817 (if (and Info-dir-contents Info-dir-file-attributes
818 ;; Verify that none of the files we used has changed
819 ;; since we used it.
820 (eval (cons 'and
821 (mapcar (lambda (elt)
822 (let ((curr (file-attributes
823 ;; Handle symlinks
824 (file-truename (car elt)))))
826 ;; Don't compare the access time.
827 (if curr (setcar (nthcdr 4 curr) 0))
828 (setcar (nthcdr 4 (cdr elt)) 0)
829 (equal (cdr elt) curr)))
830 Info-dir-file-attributes))))
831 (progn
832 (insert Info-dir-contents)
833 (goto-char (point-min)))
834 (let ((dirs (if Info-additional-directory-list
835 (append Info-directory-list
836 Info-additional-directory-list)
837 Info-directory-list))
838 (dir-file-attrs nil)
839 ;; Bind this in case the user sets it to nil.
840 (case-fold-search t)
841 ;; This is set non-nil if we find a problem in some input files.
842 problems
843 buffers buffer others nodes dirs-done)
845 ;; Search the directory list for the directory file.
846 (while dirs
847 (let ((truename (file-truename (expand-file-name (car dirs)))))
848 (or (member truename dirs-done)
849 (member (directory-file-name truename) dirs-done)
850 ;; Try several variants of specified name.
851 ;; Try upcasing, appending `.info', or both.
852 (let* (file
853 (attrs
855 (progn (setq file (expand-file-name "dir" truename))
856 (file-attributes file))
857 (progn (setq file (expand-file-name "DIR" truename))
858 (file-attributes file))
859 (progn (setq file (expand-file-name "dir.info" truename))
860 (file-attributes file))
861 (progn (setq file (expand-file-name "DIR.INFO" truename))
862 (file-attributes file)))))
863 (setq dirs-done
864 (cons truename
865 (cons (directory-file-name truename)
866 dirs-done)))
867 (if attrs
868 (save-excursion
869 (or buffers
870 (message "Composing main Info directory..."))
871 (set-buffer (generate-new-buffer " info dir"))
872 (condition-case nil
873 (progn
874 (insert-file-contents file)
875 (set (make-local-variable 'Info-dir-file-name)
876 file)
877 (push (current-buffer) buffers)
878 (push (cons file attrs) dir-file-attrs))
879 (error (kill-buffer (current-buffer))))))))
880 (unless (cdr dirs)
881 (set (make-local-variable 'Info-dir-contents-directory)
882 (file-name-as-directory (car dirs))))
883 (setq dirs (cdr dirs))))
885 (or buffers
886 (error "Can't find the Info directory node"))
888 ;; Distinguish the dir file that comes with Emacs from all the
889 ;; others. Yes, that is really what this is supposed to do.
890 ;; The definition of `Info-directory-list' puts it first on that
891 ;; list and so last in `buffers' at this point.
892 (setq buffer (car (last buffers))
893 others (delq buffer buffers))
895 ;; Insert the entire original dir file as a start; note that we've
896 ;; already saved its default directory to use as the default
897 ;; directory for the whole concatenation.
898 (insert-buffer buffer)
900 ;; Look at each of the other buffers one by one.
901 (dolist (other others)
902 (let (this-buffer-nodes)
903 ;; In each, find all the menus.
904 (with-current-buffer other
905 (goto-char (point-min))
906 ;; Find each menu, and add an elt to NODES for it.
907 (while (re-search-forward "^\\* Menu:" nil t)
908 (while (and (zerop (forward-line 1)) (eolp)))
909 (let ((beg (point))
910 nodename end)
911 (re-search-backward "^\^_")
912 (search-forward "Node: ")
913 (setq nodename
914 (and (looking-at (Info-following-node-name-re))
915 (match-string 1)))
916 (search-forward "\n\^_" nil 'move)
917 (beginning-of-line)
918 (setq end (point))
919 (push (list nodename other beg end) this-buffer-nodes)))
920 (if (assoc-ignore-case "top" this-buffer-nodes)
921 (setq nodes (nconc this-buffer-nodes nodes))
922 (setq problems t)
923 (message "No `top' node in %s" Info-dir-file-name)))))
924 ;; Add to the main menu a menu item for each other node.
925 (re-search-forward "^\\* Menu:")
926 (forward-line 1)
927 (let ((menu-items '("top"))
928 (end (save-excursion (search-forward "\^_" nil t) (point))))
929 (dolist (node nodes)
930 (let ((nodename (car node)))
931 (save-excursion
932 (or (member (downcase nodename) menu-items)
933 (re-search-forward (concat "^\\* +"
934 (regexp-quote nodename)
935 "::")
936 end t)
937 (progn
938 (insert "* " nodename "::" "\n")
939 (push nodename menu-items)))))))
940 ;; Now take each node of each of the other buffers
941 ;; and merge it into the main buffer.
942 (dolist (node nodes)
943 (let ((case-fold-search t)
944 (nodename (car node)))
945 (goto-char (point-min))
946 ;; Find the like-named node in the main buffer.
947 (if (re-search-forward (concat "^\^_.*\n.*Node: "
948 (regexp-quote nodename)
949 "[,\n\t]")
950 nil t)
951 (progn
952 (search-forward "\n\^_" nil 'move)
953 (beginning-of-line)
954 (insert "\n"))
955 ;; If none exists, add one.
956 (goto-char (point-max))
957 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
958 ;; Merge the text from the other buffer's menu
959 ;; into the menu in the like-named node in the main buffer.
960 (apply 'insert-buffer-substring (cdr node))))
961 (Info-dir-remove-duplicates)
962 ;; Kill all the buffers we just made.
963 (mapc 'kill-buffer buffers)
964 (goto-char (point-min))
965 (if problems
966 (message "Composing main Info directory...problems encountered, see `*Messages*'")
967 (message "Composing main Info directory...done"))
968 (set (make-local-variable 'Info-dir-contents) (buffer-string))
969 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
970 (setq default-directory Info-dir-contents-directory))
972 (defvar Info-streamline-headings
973 '(("Emacs" . "Emacs")
974 ("Programming" . "Programming")
975 ("Libraries" . "Libraries")
976 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
977 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
979 (defun Info-dir-remove-duplicates ()
980 (let (limit)
981 (goto-char (point-min))
982 ;; Remove duplicate headings in the same menu.
983 (while (search-forward "\n* Menu:" nil t)
984 (setq limit (save-excursion (search-forward "\n\x1f" nil t)))
985 ;; Look for the next heading to unify.
986 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
987 (let ((name (match-string 1))
988 (start (match-beginning 0))
989 (entries nil) re)
990 ;; Check whether this heading should be streamlined.
991 (save-match-data
992 (dolist (x Info-streamline-headings)
993 (when (string-match (car x) name)
994 (setq name (cdr x))
995 (setq re (car x)))))
996 (if re (replace-match name t t nil 1))
997 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
998 (match-beginning 0)
999 (or limit (point-max))))
1000 ;; Look for other headings of the same category and merge them.
1001 (save-excursion
1002 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1003 (when (if re (save-match-data (string-match re (match-string 1)))
1004 (equal name (match-string 1)))
1005 (forward-line 0)
1006 ;; Delete redundant heading.
1007 (delete-region (match-beginning 0) (point))
1008 ;; Push the entries onto `text'.
1009 (push
1010 (delete-and-extract-region
1011 (point)
1012 (if (re-search-forward "^[^* \n\t]" nil t)
1013 (match-beginning 0)
1014 (or limit (point-max)))) entries))))
1015 ;; Insert the entries just found.
1016 (while (= (line-beginning-position 0) (1- (point)))
1017 (backward-char))
1018 (dolist (entry (nreverse entries))
1019 (insert entry)
1020 (while (= (line-beginning-position 0) (1- (point)))
1021 (delete-region (1- (point)) (point))))
1023 ;; Now remove duplicate entries under the same heading.
1024 (let ((seen nil)
1025 (limit (point)))
1026 (goto-char start)
1027 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1028 limit 'move)
1029 (let ((x (match-string 1)))
1030 (if (member-ignore-case x seen)
1031 (delete-region (match-beginning 0)
1032 (progn (re-search-forward "^[^ \t]" nil t)
1033 (match-beginning 0)))
1034 (push x seen))))))))))
1036 ;; Note that on entry to this function the current-buffer must be the
1037 ;; *info* buffer; not the info tags buffer.
1038 (defun Info-read-subfile (nodepos)
1039 ;; NODEPOS is either a position (in the Info file as a whole,
1040 ;; not relative to a subfile) or the name of a subfile.
1041 (let (lastfilepos
1042 lastfilename)
1043 (if (numberp nodepos)
1044 (save-excursion
1045 (set-buffer (marker-buffer Info-tag-table-marker))
1046 (goto-char (point-min))
1047 (or (looking-at "\^_")
1048 (search-forward "\n\^_"))
1049 (forward-line 2)
1050 (catch 'foo
1051 (while (not (looking-at "\^_"))
1052 (if (not (eolp))
1053 (let ((beg (point))
1054 thisfilepos thisfilename)
1055 (search-forward ": ")
1056 (setq thisfilename (buffer-substring beg (- (point) 2)))
1057 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1058 ;; read in version 19 stops at the end of number.
1059 ;; Advance to the next line.
1060 (forward-line 1)
1061 (if (> thisfilepos nodepos)
1062 (throw 'foo t))
1063 (setq lastfilename thisfilename)
1064 (setq lastfilepos thisfilepos))
1065 (forward-line 1)))))
1066 (setq lastfilename nodepos)
1067 (setq lastfilepos 0))
1068 ;; Assume previous buffer is in Info-mode.
1069 ;; (set-buffer (get-buffer "*info*"))
1070 (or (equal Info-current-subfile lastfilename)
1071 (let ((buffer-read-only nil))
1072 (setq buffer-file-name nil)
1073 (widen)
1074 (erase-buffer)
1075 (info-insert-file-contents lastfilename)
1076 (set-buffer-modified-p nil)
1077 (setq Info-current-subfile lastfilename)))
1078 ;; Widen in case we are in the same subfile as before.
1079 (widen)
1080 (goto-char (point-min))
1081 (if (looking-at "\^_")
1082 (forward-char 1)
1083 (search-forward "\n\^_"))
1084 (if (numberp nodepos)
1085 (+ (- nodepos lastfilepos) (point)))))
1087 (defun Info-unescape-quotes (value)
1088 "Unescape double quotes and backslashes in VALUE"
1089 (let ((start 0)
1090 (unquote value))
1091 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1092 (setq unquote (replace-match "" t t unquote 1))
1093 (setq start (- (match-end 0) 1)))
1094 unquote))
1096 ;; As of Texinfo 4.6, makeinfo writes constructs like
1097 ;; \0\h[image param=value ...\h\0]
1098 ;; into the Info file for handling images.
1099 (defun Info-split-parameter-string (parameter-string)
1100 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1101 whitespace separated list of KEY=VALUE pairs. If VALUE
1102 contains whitespace or double quotes, it must be quoted in
1103 double quotes and any double quotes or backslashes must be
1104 escaped (\\\",\\\\)."
1105 (let ((start 0)
1106 (parameter-alist))
1107 (while (string-match
1108 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1109 parameter-string start)
1110 (setq start (match-end 0))
1111 (push (cons (match-string 1 parameter-string)
1112 (or (match-string 2 parameter-string)
1113 (Info-unescape-quotes
1114 (match-string 3 parameter-string))))
1115 parameter-alist))
1116 parameter-alist))
1118 (defun Info-display-images-node ()
1119 "Display images in current node."
1120 (save-excursion
1121 (let ((inhibit-read-only t)
1122 (case-fold-search t))
1123 (goto-char (point-min))
1124 (while (re-search-forward
1125 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1126 nil t)
1127 (let* ((start (match-beginning 1))
1128 (parameter-alist (Info-split-parameter-string (match-string 2)))
1129 (src (cdr (assoc-string "src" parameter-alist)))
1130 (image-file (if src (if (file-name-absolute-p src) src
1131 (concat default-directory src))
1132 ""))
1133 (image (if (file-exists-p image-file)
1134 (create-image image-file)
1135 "[broken image]")))
1136 (message "Found image: %S" image-file)
1137 (if (not (get-text-property start 'display))
1138 (add-text-properties
1139 start (point) `(display ,image rear-nonsticky (display)))))))
1140 (set-buffer-modified-p nil)))
1142 (defun Info-select-node ()
1143 "Select the info node that point is in."
1144 ;; Bind this in case the user sets it to nil.
1145 (let ((case-fold-search t))
1146 (save-excursion
1147 ;; Find beginning of node.
1148 (if (search-backward "\n\^_" nil 'move)
1149 (forward-line 2)
1150 (if (looking-at "\^_")
1151 (forward-line 1)
1152 (signal 'search-failed (list "\n\^_"))))
1153 ;; Get nodename spelled as it is in the node.
1154 (re-search-forward "Node:[ \t]*")
1155 (setq Info-current-node
1156 (buffer-substring-no-properties (point)
1157 (progn
1158 (skip-chars-forward "^,\t\n")
1159 (point))))
1160 (Info-set-mode-line)
1161 ;; Find the end of it, and narrow.
1162 (beginning-of-line)
1163 (let (active-expression)
1164 ;; Narrow to the node contents
1165 (narrow-to-region (point)
1166 (if (re-search-forward "\n[\^_\f]" nil t)
1167 (prog1
1168 (1- (point))
1169 (if (looking-at "[\n\^_\f]*execute: ")
1170 (progn
1171 (goto-char (match-end 0))
1172 (setq active-expression
1173 (read (current-buffer))))))
1174 (point-max)))
1175 (if Info-enable-active-nodes (eval active-expression))
1176 (Info-fontify-node)
1177 (Info-display-images-node)
1178 (run-hooks 'Info-selection-hook)))))
1180 (defun Info-set-mode-line ()
1181 (setq mode-line-buffer-identification
1182 (nconc (propertized-buffer-identification "%b")
1183 (list
1184 (concat " ("
1185 (file-name-nondirectory
1186 (if (stringp Info-current-file)
1187 Info-current-file
1188 (or buffer-file-name "")))
1189 ") "
1190 (or Info-current-node ""))))))
1192 ;; Go to an info node specified with a filename-and-nodename string
1193 ;; of the sort that is found in pointers in nodes.
1195 (defun Info-goto-node (nodename &optional fork)
1196 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1197 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1198 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1199 its sub-files).
1200 Completion is available, but only for node names in the current Info file.
1201 If FORK is non-nil (interactively with a prefix arg), show the node in
1202 a new info buffer.
1203 If FORK is a string, it is the name to use for the new buffer."
1204 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1205 (info-initialize)
1206 (if fork
1207 (set-buffer
1208 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1209 (let (filename)
1210 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1211 nodename)
1212 (setq filename (if (= (match-beginning 1) (match-end 1))
1214 (match-string 2 nodename))
1215 nodename (match-string 3 nodename))
1216 (let ((trim (string-match "\\s *\\'" filename)))
1217 (if trim (setq filename (substring filename 0 trim))))
1218 (let ((trim (string-match "\\s *\\'" nodename)))
1219 (if trim (setq nodename (substring nodename 0 trim))))
1220 (if transient-mark-mode (deactivate-mark))
1221 (Info-find-node (if (equal filename "") nil filename)
1222 (if (equal nodename "") "Top" nodename))))
1224 (defvar Info-read-node-completion-table)
1226 ;; This function is used as the "completion table" while reading a node name.
1227 ;; It does completion using the alist in Info-read-node-completion-table
1228 ;; unless STRING starts with an open-paren.
1229 (defun Info-read-node-name-1 (string predicate code)
1230 (cond
1231 ;; First complete embedded file names.
1232 ((string-match "\\`([^)]*\\'" string)
1233 (let ((file (substring string 1)))
1234 (cond
1235 ((eq code nil)
1236 (let ((comp (try-completion file 'locate-file-completion
1237 (cons Info-directory-list
1238 (mapcar 'car Info-suffix-list)))))
1239 (cond
1240 ((eq comp t) (concat string ")"))
1241 (comp (concat "(" comp)))))
1242 ((eq code t) (all-completions file 'locate-file-completion
1243 (cons Info-directory-list
1244 (mapcar 'car Info-suffix-list))))
1245 (t nil))))
1246 ;; If a file name was given, then any node is fair game.
1247 ((string-match "\\`(" string)
1248 (cond
1249 ((eq code nil) string)
1250 ((eq code t) nil)
1251 (t t)))
1252 ;; Otherwise use Info-read-node-completion-table.
1253 ((eq code nil)
1254 (try-completion string Info-read-node-completion-table predicate))
1255 ((eq code t)
1256 (all-completions string Info-read-node-completion-table predicate))
1258 (test-completion string Info-read-node-completion-table predicate))))
1260 (defun Info-read-node-name (prompt &optional default)
1261 (let* ((completion-ignore-case t)
1262 (Info-read-node-completion-table (Info-build-node-completions))
1263 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1264 (if (equal nodename "")
1265 (or default
1266 (Info-read-node-name prompt))
1267 nodename)))
1269 (defun Info-build-node-completions ()
1270 (or Info-current-file-completions
1271 (let ((compl nil)
1272 ;; Bind this in case the user sets it to nil.
1273 (case-fold-search t)
1274 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1275 (save-excursion
1276 (save-restriction
1277 (if (marker-buffer Info-tag-table-marker)
1278 (let ((marker Info-tag-table-marker))
1279 (set-buffer (marker-buffer marker))
1280 (widen)
1281 (goto-char marker)
1282 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1283 (setq compl
1284 (cons (list (match-string-no-properties 2))
1285 compl))))
1286 (widen)
1287 (goto-char (point-min))
1288 ;; If the buffer begins with a node header, process that first.
1289 (if (Info-node-at-bob-matching node-regexp)
1290 (setq compl (list (match-string-no-properties 1))))
1291 ;; Now for the rest of the nodes.
1292 (while (search-forward "\n\^_" nil t)
1293 (forward-line 1)
1294 (let ((beg (point)))
1295 (forward-line 1)
1296 (if (re-search-backward node-regexp beg t)
1297 (setq compl
1298 (cons (list (match-string-no-properties 1))
1299 compl))))))))
1300 (setq compl (cons '("*") compl))
1301 (set (make-local-variable 'Info-current-file-completions) compl))))
1303 (defun Info-restore-point (hl)
1304 "If this node has been visited, restore the point value when we left."
1305 (while hl
1306 (if (and (equal (nth 0 (car hl)) Info-current-file)
1307 ;; Use string-equal, not equal, to ignore text props.
1308 (string-equal (nth 1 (car hl)) Info-current-node))
1309 (progn
1310 (goto-char (nth 2 (car hl)))
1311 (setq hl nil)) ;terminate the while at next iter
1312 (setq hl (cdr hl)))))
1314 (defvar Info-search-history nil
1315 "The history list for `Info-search'.")
1317 (defun Info-search (regexp)
1318 "Search for REGEXP, starting from point, and select node it's found in."
1319 (interactive (list (read-string
1320 (if Info-search-history
1321 (format "Regexp search (default `%s'): "
1322 (car Info-search-history))
1323 "Regexp search: ")
1324 nil 'Info-search-history)))
1325 (when transient-mark-mode
1326 (deactivate-mark))
1327 (when (equal regexp "")
1328 (setq regexp (car Info-search-history)))
1329 (when regexp
1330 (let (found beg-found give-up
1331 (onode Info-current-node)
1332 (ofile Info-current-file)
1333 (opoint (point))
1334 (ostart (window-start))
1335 (osubfile Info-current-subfile))
1336 (save-excursion
1337 (save-restriction
1338 (widen)
1339 (while (and (not give-up)
1340 (or (null found)
1341 (isearch-range-invisible beg-found found)))
1342 (if (re-search-forward regexp nil t)
1343 (setq found (point) beg-found (match-beginning 0))
1344 (setq give-up t)))))
1345 ;; If no subfiles, give error now.
1346 (if give-up
1347 (if (null Info-current-subfile)
1348 (re-search-forward regexp)
1349 (setq found nil)))
1351 (unless found
1352 (unwind-protect
1353 ;; Try other subfiles.
1354 (let ((list ()))
1355 (save-excursion
1356 (set-buffer (marker-buffer Info-tag-table-marker))
1357 (goto-char (point-min))
1358 (search-forward "\n\^_\nIndirect:")
1359 (save-restriction
1360 (narrow-to-region (point)
1361 (progn (search-forward "\n\^_")
1362 (1- (point))))
1363 (goto-char (point-min))
1364 ;; Find the subfile we just searched.
1365 (search-forward (concat "\n" osubfile ": "))
1366 ;; Skip that one.
1367 (forward-line 1)
1368 ;; Make a list of all following subfiles.
1369 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1370 (while (not (eobp))
1371 (re-search-forward "\\(^.*\\): [0-9]+$")
1372 (goto-char (+ (match-end 1) 2))
1373 (setq list (cons (cons (+ (point-min)
1374 (read (current-buffer)))
1375 (match-string-no-properties 1))
1376 list))
1377 (goto-char (1+ (match-end 0))))
1378 ;; Put in forward order
1379 (setq list (nreverse list))))
1380 (while list
1381 (message "Searching subfile %s..." (cdr (car list)))
1382 (Info-read-subfile (car (car list)))
1383 (setq list (cdr list))
1384 (setq give-up nil found nil)
1385 (while (and (not give-up)
1386 (or (null found)
1387 (isearch-range-invisible beg-found found)))
1388 (if (re-search-forward regexp nil t)
1389 (setq found (point) beg-found (match-beginning 0))
1390 (setq give-up t)))
1391 (if give-up
1392 (setq found nil))
1393 (if found
1394 (setq list nil)))
1395 (if found
1396 (message "")
1397 (signal 'search-failed (list regexp))))
1398 (if (not found)
1399 (progn (Info-read-subfile osubfile)
1400 (goto-char opoint)
1401 (Info-select-node)
1402 (set-window-start (selected-window) ostart)))))
1403 (widen)
1404 (goto-char found)
1405 (Info-select-node)
1406 ;; Use string-equal, not equal, to ignore text props.
1407 (or (and (string-equal onode Info-current-node)
1408 (equal ofile Info-current-file))
1409 (setq Info-history (cons (list ofile onode opoint)
1410 Info-history))))))
1412 (defun Info-extract-pointer (name &optional errorname)
1413 "Extract the value of the node-pointer named NAME.
1414 If there is none, use ERRORNAME in the error message;
1415 if ERRORNAME is nil, just return nil."
1416 ;; Bind this in case the user sets it to nil.
1417 (let ((case-fold-search t))
1418 (save-excursion
1419 (goto-char (point-min))
1420 (let ((bound (point)))
1421 (forward-line 1)
1422 (cond ((re-search-backward
1423 (concat name ":" (Info-following-node-name-re)) bound t)
1424 (match-string 1))
1425 ((not (eq errorname t))
1426 (error "Node has no %s"
1427 (capitalize (or errorname name)))))))))
1429 (defun Info-following-node-name-re (&optional allowedchars)
1430 "Return a regexp matching a node name.
1431 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1432 saying which chars may appear in the node name.
1433 Submatch 1 is the complete node name.
1434 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1435 Submatch 3 is the local part of the node name.
1436 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1437 (concat "[ \t]*" ;Skip leading space.
1438 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1439 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1440 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1441 "\\|\\)\\)")) ;Allow empty node names.
1443 (defun Info-next ()
1444 "Go to the next node of this node."
1445 (interactive)
1446 (Info-goto-node (Info-extract-pointer "next")))
1448 (defun Info-prev ()
1449 "Go to the previous node of this node."
1450 (interactive)
1451 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1453 (defun Info-up (&optional same-file)
1454 "Go to the superior node of this node.
1455 If SAME-FILE is non-nil, do not move to a different Info file."
1456 (interactive)
1457 (let ((node (Info-extract-pointer "up")))
1458 (and (or same-file (not (stringp Info-current-file)))
1459 (string-match "^(" node)
1460 (error "Up node is in another Info file"))
1461 (Info-goto-node node))
1462 (Info-restore-point Info-history))
1464 (defun Info-last ()
1465 "Go back to the last node visited."
1466 (interactive)
1467 (or Info-history
1468 (error "This is the first Info node you looked at"))
1469 (let (filename nodename opoint)
1470 (setq filename (car (car Info-history)))
1471 (setq nodename (car (cdr (car Info-history))))
1472 (setq opoint (car (cdr (cdr (car Info-history)))))
1473 (setq Info-history (cdr Info-history))
1474 (Info-find-node filename nodename)
1475 (setq Info-history (cdr Info-history))
1476 (goto-char opoint)))
1478 ;;;###autoload
1479 (defun Info-directory ()
1480 "Go to the Info directory node."
1481 (interactive)
1482 (Info-find-node "dir" "top"))
1484 (defun Info-follow-reference (footnotename)
1485 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1486 FOOTNOTENAME may be an abbreviation of the reference name."
1487 (interactive
1488 (let ((completion-ignore-case t)
1489 (case-fold-search t)
1490 completions default alt-default (start-point (point)) str i bol eol)
1491 (save-excursion
1492 ;; Store end and beginning of line.
1493 (end-of-line)
1494 (setq eol (point))
1495 (beginning-of-line)
1496 (setq bol (point))
1498 (goto-char (point-min))
1499 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1500 (setq str (match-string-no-properties 1))
1501 ;; See if this one should be the default.
1502 (and (null default)
1503 (<= (match-beginning 0) start-point)
1504 (<= start-point (point))
1505 (setq default t))
1506 ;; See if this one should be the alternate default.
1507 (and (null alt-default)
1508 (and (<= bol (match-beginning 0))
1509 (<= (point) eol))
1510 (setq alt-default t))
1511 (setq i 0)
1512 (while (setq i (string-match "[ \n\t]+" str i))
1513 (setq str (concat (substring str 0 i) " "
1514 (substring str (match-end 0))))
1515 (setq i (1+ i)))
1516 ;; Record as a completion and perhaps as default.
1517 (if (eq default t) (setq default str))
1518 (if (eq alt-default t) (setq alt-default str))
1519 ;; Don't add this string if it's a duplicate.
1520 (or (assoc-string str completions t)
1521 (push str completions))))
1522 ;; If no good default was found, try an alternate.
1523 (or default
1524 (setq default alt-default))
1525 ;; If only one cross-reference found, then make it default.
1526 (if (eq (length completions) 1)
1527 (setq default (car completions)))
1528 (if completions
1529 (let ((input (completing-read (if default
1530 (concat
1531 "Follow reference named: (default "
1532 default ") ")
1533 "Follow reference named: ")
1534 completions nil t)))
1535 (list (if (equal input "")
1536 default input)))
1537 (error "No cross-references in this node"))))
1539 (unless footnotename
1540 (error "No reference was specified"))
1542 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
1543 (case-fold-search t))
1544 (while (setq i (string-match " " str i))
1545 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1546 (setq i (+ i 6)))
1547 (save-excursion
1548 (goto-char (point-min))
1549 (or (re-search-forward str nil t)
1550 (error "No cross-reference named %s" footnotename))
1551 (goto-char (+ (match-beginning 0) 5))
1552 (setq target
1553 (Info-extract-menu-node-name t)))
1554 (while (setq i (string-match "[ \t\n]+" target i))
1555 (setq target (concat (substring target 0 i) " "
1556 (substring target (match-end 0))))
1557 (setq i (+ i 1)))
1558 (Info-goto-node target)))
1560 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
1561 ;; We allow newline because this is also used in Info-follow-reference,
1562 ;; where the xref name might be wrapped over two lines.
1563 "Regexp that matches a menu entry name upto but not including the colon.
1564 Because of ambiguities, this should be concatenated with something like
1565 `:' and `Info-following-node-name-re'.")
1567 (defun Info-extract-menu-node-name (&optional multi-line)
1568 (skip-chars-forward " \t\n")
1569 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
1570 (Info-following-node-name-re
1571 (if multi-line "^.,\t" "^.,\t\n")) "\\)"))
1572 (replace-regexp-in-string
1573 "[ \n]+" " "
1574 (or (match-string 2)
1575 ;; If the node name is the menu entry name (using `entry::').
1576 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
1578 ;; No one calls this.
1579 ;;(defun Info-menu-item-sequence (list)
1580 ;; (while list
1581 ;; (Info-menu (car list))
1582 ;; (setq list (cdr list))))
1584 (defvar Info-complete-menu-buffer)
1585 (defvar Info-complete-next-re nil)
1586 (defvar Info-complete-cache nil)
1588 (defconst Info-node-spec-re
1589 (concat (Info-following-node-name-re "^.,:") "[,:.]")
1590 "Regexp to match the text after a : until the terminating `.'.")
1592 (defun Info-complete-menu-item (string predicate action)
1593 ;; This uses two dynamically bound variables:
1594 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1595 ;; is the menu of items we're trying to complete.
1596 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1597 ;; also look for menu items in subsequent nodes as long as those
1598 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1599 ;; only used for completion in Info-index.
1601 ;; Note that `Info-complete-menu-buffer' could be current already,
1602 ;; so we want to save point.
1603 (save-excursion
1604 (set-buffer Info-complete-menu-buffer)
1605 (let ((completion-ignore-case t)
1606 (case-fold-search t)
1607 (orignode Info-current-node)
1608 nextnode)
1609 (goto-char (point-min))
1610 (search-forward "\n* Menu:")
1611 (if (not (memq action '(nil t)))
1612 (re-search-forward
1613 (concat "\n\\* +" (regexp-quote string) ":") nil t)
1614 (let ((pattern (concat "\n\\* +\\("
1615 (regexp-quote string)
1616 Info-menu-entry-name-re "\\):" Info-node-spec-re))
1617 completions)
1618 ;; Check the cache.
1619 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
1620 (equal (nth 1 Info-complete-cache) Info-current-node)
1621 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
1622 (let ((prev (nth 3 Info-complete-cache)))
1623 (eq t (compare-strings string 0 (length prev)
1624 prev 0 nil t))))
1625 ;; We can reuse the previous list.
1626 (setq completions (nth 4 Info-complete-cache))
1627 ;; The cache can't be used.
1628 (while
1629 (progn
1630 (while (re-search-forward pattern nil t)
1631 (push (match-string-no-properties 1)
1632 completions))
1633 ;; Check subsequent nodes if applicable.
1634 (and Info-complete-next-re
1635 (setq nextnode (Info-extract-pointer "next" t))
1636 (string-match Info-complete-next-re nextnode)))
1637 (Info-goto-node nextnode))
1638 ;; Go back to the start node (for the next completion).
1639 (unless (equal Info-current-node orignode)
1640 (Info-goto-node orignode))
1641 ;; Update the cache.
1642 (set (make-local-variable 'Info-complete-cache)
1643 (list Info-current-file Info-current-node
1644 Info-complete-next-re string completions)))
1645 (if action
1646 (all-completions string completions predicate)
1647 (try-completion string completions predicate)))))))
1650 (defun Info-menu (menu-item &optional fork)
1651 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1652 The menu item should one of those listed in the current node's menu.
1653 Completion is allowed, and the default menu item is the one point is on.
1654 If FORK is non-nil (interactively with a prefix arg), show the node in
1655 a new info buffer. If FORK is a string, it is the name to use for the
1656 new buffer."
1657 (interactive
1658 (let ((completions '())
1659 ;; If point is within a menu item, use that item as the default
1660 (default nil)
1661 (p (point))
1663 (last nil)
1664 (case-fold-search t))
1665 (save-excursion
1666 (goto-char (point-min))
1667 (if (not (search-forward "\n* menu:" nil t))
1668 (error "No menu in this node"))
1669 (setq beg (point))
1670 (and (< (point) p)
1671 (save-excursion
1672 (goto-char p)
1673 (end-of-line)
1674 (if (re-search-backward (concat "\n\\* +\\("
1675 Info-menu-entry-name-re
1676 "\\):") beg t)
1677 (setq default (match-string-no-properties 1))))))
1678 (let ((item nil))
1679 (while (null item)
1680 (setq item (let ((completion-ignore-case t)
1681 (Info-complete-menu-buffer (current-buffer)))
1682 (completing-read (if default
1683 (format "Menu item (default %s): "
1684 default)
1685 "Menu item: ")
1686 'Info-complete-menu-item nil t)))
1687 ;; we rely on the fact that completing-read accepts an input
1688 ;; of "" even when the require-match argument is true and ""
1689 ;; is not a valid possibility
1690 (if (string= item "")
1691 (if default
1692 (setq item default)
1693 ;; ask again
1694 (setq item nil))))
1695 (list item current-prefix-arg))))
1696 ;; there is a problem here in that if several menu items have the same
1697 ;; name you can only go to the node of the first with this command.
1698 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1700 (defun Info-extract-menu-item (menu-item)
1701 (setq menu-item (regexp-quote menu-item))
1702 (let ((case-fold-search t))
1703 (save-excursion
1704 (let ((case-fold-search t))
1705 (goto-char (point-min))
1706 (or (search-forward "\n* menu:" nil t)
1707 (error "No menu in this node"))
1708 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1709 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1710 (error "No such item in menu"))
1711 (beginning-of-line)
1712 (forward-char 2)
1713 (Info-extract-menu-node-name)))))
1715 ;; If COUNT is nil, use the last item in the menu.
1716 (defun Info-extract-menu-counting (count)
1717 (let ((case-fold-search t))
1718 (save-excursion
1719 (let ((case-fold-search t))
1720 (goto-char (point-min))
1721 (or (search-forward "\n* menu:" nil t)
1722 (error "No menu in this node"))
1723 (if count
1724 (or (search-forward "\n* " nil t count)
1725 (error "Too few items in menu"))
1726 (while (search-forward "\n* " nil t)
1727 nil))
1728 (Info-extract-menu-node-name)))))
1730 (defun Info-nth-menu-item ()
1731 "Go to the node of the Nth menu item.
1732 N is the digit argument used to invoke this command."
1733 (interactive)
1734 (Info-goto-node
1735 (Info-extract-menu-counting
1736 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1738 (defun Info-top-node ()
1739 "Go to the Top node of this file."
1740 (interactive)
1741 (Info-goto-node "Top"))
1743 (defun Info-final-node ()
1744 "Go to the final node in this file."
1745 (interactive)
1746 (Info-goto-node "Top")
1747 (let ((Info-history nil)
1748 (case-fold-search t))
1749 ;; Go to the last node in the menu of Top.
1750 (Info-goto-node (Info-extract-menu-counting nil))
1751 ;; If the last node in the menu is not last in pointer structure,
1752 ;; move forward until we can't go any farther.
1753 (while (Info-forward-node t t) nil)
1754 ;; Then keep moving down to last subnode, unless we reach an index.
1755 (while (and (not (string-match "\\<index\\>" Info-current-node))
1756 (save-excursion (search-forward "\n* Menu:" nil t)))
1757 (Info-goto-node (Info-extract-menu-counting nil)))))
1759 (defun Info-forward-node (&optional not-down no-error)
1760 "Go forward one node, considering all nodes as forming one sequence."
1761 (interactive)
1762 (goto-char (point-min))
1763 (forward-line 1)
1764 (let ((case-fold-search t))
1765 ;; three possibilities, in order of priority:
1766 ;; 1. next node is in a menu in this node (but not in an index)
1767 ;; 2. next node is next at same level
1768 ;; 3. next node is up and next
1769 (cond ((and (not not-down)
1770 (save-excursion (search-forward "\n* menu:" nil t))
1771 (not (string-match "\\<index\\>" Info-current-node)))
1772 (Info-goto-node (Info-extract-menu-counting 1))
1774 ((save-excursion (search-backward "next:" nil t))
1775 (Info-next)
1777 ((and (save-excursion (search-backward "up:" nil t))
1778 ;; Use string-equal, not equal, to ignore text props.
1779 (not (string-equal (downcase (Info-extract-pointer "up"))
1780 "top")))
1781 (let ((old-node Info-current-node))
1782 (Info-up)
1783 (let (Info-history success)
1784 (unwind-protect
1785 (setq success (Info-forward-node t no-error))
1786 (or success (Info-goto-node old-node))))))
1787 (no-error nil)
1788 (t (error "No pointer forward from this node")))))
1790 (defun Info-backward-node ()
1791 "Go backward one node, considering all nodes as forming one sequence."
1792 (interactive)
1793 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1794 (upnode (Info-extract-pointer "up" t))
1795 (case-fold-search t))
1796 (cond ((and upnode (string-match "(" upnode))
1797 (error "First node in file"))
1798 ((and upnode (or (null prevnode)
1799 ;; Use string-equal, not equal,
1800 ;; to ignore text properties.
1801 (string-equal (downcase prevnode)
1802 (downcase upnode))))
1803 (Info-up))
1804 (prevnode
1805 ;; If we move back at the same level,
1806 ;; go down to find the last subnode*.
1807 (Info-prev)
1808 (let (Info-history)
1809 (while (and (not (string-match "\\<index\\>" Info-current-node))
1810 (save-excursion (search-forward "\n* Menu:" nil t)))
1811 (Info-goto-node (Info-extract-menu-counting nil)))))
1813 (error "No pointer backward from this node")))))
1815 (defun Info-exit ()
1816 "Exit Info by selecting some other buffer."
1817 (interactive)
1818 (if Info-standalone
1819 (save-buffers-kill-emacs)
1820 (quit-window)))
1822 (defun Info-next-menu-item ()
1823 "Go to the node of the next menu item."
1824 (interactive)
1825 ;; Bind this in case the user sets it to nil.
1826 (let* ((case-fold-search t)
1827 (node
1828 (save-excursion
1829 (forward-line -1)
1830 (search-forward "\n* menu:" nil t)
1831 (and (search-forward "\n* " nil t)
1832 (Info-extract-menu-node-name)))))
1833 (if node (Info-goto-node node)
1834 (error "No more items in menu"))))
1836 (defun Info-last-menu-item ()
1837 "Go to the node of the previous menu item."
1838 (interactive)
1839 (save-excursion
1840 (forward-line 1)
1841 ;; Bind this in case the user sets it to nil.
1842 (let* ((case-fold-search t)
1843 (beg (save-excursion
1844 (and (search-backward "\n* menu:" nil t)
1845 (point)))))
1846 (or (and beg (search-backward "\n* " beg t))
1847 (error "No previous items in menu")))
1848 (Info-goto-node (save-excursion
1849 (goto-char (match-end 0))
1850 (Info-extract-menu-node-name)))))
1852 (defmacro Info-no-error (&rest body)
1853 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1855 (defun Info-next-preorder ()
1856 "Go to the next subnode or the next node, or go up a level."
1857 (interactive)
1858 (cond ((Info-no-error (Info-next-menu-item)))
1859 ((Info-no-error (Info-next)))
1860 ((Info-no-error (Info-up t))
1861 ;; Since we have already gone thru all the items in this menu,
1862 ;; go up to the end of this node.
1863 (goto-char (point-max))
1864 ;; Since logically we are done with the node with that menu,
1865 ;; move on from it.
1866 (Info-next-preorder))
1868 (error "No more nodes"))))
1870 (defun Info-last-preorder ()
1871 "Go to the last node, popping up a level if there is none."
1872 (interactive)
1873 (cond ((Info-no-error
1874 (Info-last-menu-item)
1875 ;; If we go down a menu item, go to the end of the node
1876 ;; so we can scroll back through it.
1877 (goto-char (point-max)))
1878 ;; Keep going down, as long as there are nested menu nodes.
1879 (while (Info-no-error
1880 (Info-last-menu-item)
1881 ;; If we go down a menu item, go to the end of the node
1882 ;; so we can scroll back through it.
1883 (goto-char (point-max))))
1884 (recenter -1))
1885 ((and (Info-no-error (Info-extract-pointer "prev"))
1886 (not (equal (Info-extract-pointer "up")
1887 (Info-extract-pointer "prev"))))
1888 (Info-no-error (Info-prev))
1889 (goto-char (point-max))
1890 (while (Info-no-error
1891 (Info-last-menu-item)
1892 ;; If we go down a menu item, go to the end of the node
1893 ;; so we can scroll back through it.
1894 (goto-char (point-max))))
1895 (recenter -1))
1896 ((Info-no-error (Info-up t))
1897 (goto-char (point-min))
1898 (let ((case-fold-search t))
1899 (or (search-forward "\n* Menu:" nil t)
1900 (goto-char (point-max)))))
1901 (t (error "No previous nodes"))))
1903 (defun Info-scroll-up ()
1904 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1905 Once you scroll far enough in a node that its menu appears on the screen
1906 but after point, the next scroll moves into its first subnode, unless
1907 `Info-scroll-prefer-subnodes' is nil.
1909 When you scroll past the end of a node, that goes to the next node if
1910 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1911 if this node has no successor, it moves to the parent node's successor,
1912 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1913 the menu of a node, it moves to subnode indicated by the following menu
1914 item. (That case won't normally result from this command, but can happen
1915 in other ways.)"
1917 (interactive)
1918 (if (or (< (window-start) (point-min))
1919 (> (window-start) (point-max)))
1920 (set-window-start (selected-window) (point)))
1921 (let* ((case-fold-search t)
1922 (virtual-end (save-excursion
1923 (goto-char (point-min))
1924 (if (and Info-scroll-prefer-subnodes
1925 (search-forward "\n* Menu:" nil t))
1926 (point)
1927 (point-max)))))
1928 (if (or (< virtual-end (window-start))
1929 (pos-visible-in-window-p virtual-end))
1930 (cond
1931 (Info-scroll-prefer-subnodes (Info-next-preorder))
1932 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1933 (t (Info-next-preorder)))
1934 (scroll-up))))
1936 (defun Info-scroll-down ()
1937 "Scroll one screenful back in Info, considering all nodes as one sequence.
1938 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1939 is non-nil, this goes to its last subnode. When you scroll past the
1940 beginning of a node, that goes to the previous node or back up to the
1941 parent node."
1942 (interactive)
1943 (if (or (< (window-start) (point-min))
1944 (> (window-start) (point-max)))
1945 (set-window-start (selected-window) (point)))
1946 (let* ((case-fold-search t)
1947 (current-point (point))
1948 (virtual-end
1949 (and Info-scroll-prefer-subnodes
1950 (save-excursion
1951 (beginning-of-line)
1952 (setq current-point (point))
1953 (goto-char (point-min))
1954 (search-forward "\n* Menu:"
1955 current-point
1956 t)))))
1957 (if (or virtual-end
1958 (pos-visible-in-window-p (point-min) nil t))
1959 (Info-last-preorder)
1960 (scroll-down))))
1962 (defun Info-next-reference (&optional recur)
1963 "Move cursor to the next cross-reference or menu item in the node."
1964 (interactive)
1965 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1966 (old-pt (point))
1967 (case-fold-search t))
1968 (or (eobp) (forward-char 1))
1969 (or (re-search-forward pat nil t)
1970 (progn
1971 (goto-char (point-min))
1972 (or (re-search-forward pat nil t)
1973 (progn
1974 (goto-char old-pt)
1975 (error "No cross references in this node")))))
1976 (goto-char (match-beginning 0))
1977 (if (looking-at "\\* Menu:")
1978 (if recur
1979 (error "No cross references in this node")
1980 (Info-next-reference t)))))
1982 (defun Info-prev-reference (&optional recur)
1983 "Move cursor to the previous cross-reference or menu item in the node."
1984 (interactive)
1985 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1986 (old-pt (point))
1987 (case-fold-search t))
1988 (or (re-search-backward pat nil t)
1989 (progn
1990 (goto-char (point-max))
1991 (or (re-search-backward pat nil t)
1992 (progn
1993 (goto-char old-pt)
1994 (error "No cross references in this node")))))
1995 (goto-char (match-beginning 0))
1996 (if (looking-at "\\* Menu:")
1997 (if recur
1998 (error "No cross references in this node")
1999 (Info-prev-reference t)))))
2001 (defun Info-goto-index ()
2002 (Info-goto-node "Top")
2003 (or (search-forward "\n* menu:" nil t)
2004 (error "No index"))
2005 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2006 (error "No index"))
2007 (goto-char (match-beginning 1))
2008 ;; Protect Info-history so that the current node (Top) is not added to it.
2009 (let ((Info-history nil))
2010 (Info-goto-node (Info-extract-menu-node-name))))
2012 ;;;###autoload
2013 (defun Info-index (topic)
2014 "Look up a string TOPIC in the index for this file.
2015 The index is defined as the first node in the top level menu whose
2016 name contains the word \"Index\", plus any immediately following
2017 nodes whose names also contain the word \"Index\".
2018 If there are no exact matches to the specified topic, this chooses
2019 the first match which is a case-insensitive substring of a topic.
2020 Use the `,' command to see the other matches.
2021 Give a blank topic name to go to the Index node itself."
2022 (interactive
2023 (list
2024 (let ((Info-complete-menu-buffer (clone-buffer))
2025 (Info-complete-next-re "\\<Index\\>"))
2026 (if (equal Info-current-file "dir")
2027 (error "The Info directory node has no index; use m to select a manual"))
2028 (unwind-protect
2029 (with-current-buffer Info-complete-menu-buffer
2030 (Info-goto-index)
2031 (completing-read "Index topic: " 'Info-complete-menu-item))
2032 (kill-buffer Info-complete-menu-buffer)))))
2033 (if (equal Info-current-file "dir")
2034 (error "The Info directory node has no index; use m to select a manual"))
2035 (let ((orignode Info-current-node)
2036 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
2037 (regexp-quote topic)))
2038 node
2039 (case-fold-search t))
2040 (Info-goto-index)
2041 (or (equal topic "")
2042 (let ((matches nil)
2043 (exact nil)
2044 ;; We bind Info-history to nil for internal node-switches so
2045 ;; that we don't put junk in the history. In the first
2046 ;; Info-goto-index call, above, we do update the history
2047 ;; because that is what the user's previous node choice into it.
2048 (Info-history nil)
2049 found)
2050 (while
2051 (progn
2052 (goto-char (point-min))
2053 (while (re-search-forward pattern nil t)
2054 (push (list (match-string-no-properties 1)
2055 (match-string-no-properties 2)
2056 Info-current-node
2057 (string-to-number (concat "0"
2058 (match-string 3))))
2059 matches))
2060 (and (setq node (Info-extract-pointer "next" t))
2061 (string-match "\\<Index\\>" node)))
2062 (Info-goto-node node))
2063 (or matches
2064 (progn
2065 (Info-goto-node orignode)
2066 (error "No `%s' in index" topic)))
2067 ;; Here it is a feature that assoc is case-sensitive.
2068 (while (setq found (assoc topic matches))
2069 (setq exact (cons found exact)
2070 matches (delq found matches)))
2071 (setq Info-index-alternatives (nconc exact (nreverse matches)))
2072 (Info-index-next 0)))))
2074 (defun Info-index-next (num)
2075 "Go to the next matching index item from the last `i' command."
2076 (interactive "p")
2077 (or Info-index-alternatives
2078 (error "No previous `i' command"))
2079 (while (< num 0)
2080 (setq num (+ num (length Info-index-alternatives))))
2081 (while (> num 0)
2082 (setq Info-index-alternatives
2083 (nconc (cdr Info-index-alternatives)
2084 (list (car Info-index-alternatives)))
2085 num (1- num)))
2086 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2087 (if (> (nth 3 (car Info-index-alternatives)) 0)
2088 (forward-line (nth 3 (car Info-index-alternatives)))
2089 (forward-line 3) ; don't search in headers
2090 (let ((name (car (car Info-index-alternatives))))
2091 (Info-find-index-name name)))
2092 (message "Found `%s' in %s. %s"
2093 (car (car Info-index-alternatives))
2094 (nth 2 (car Info-index-alternatives))
2095 (if (cdr Info-index-alternatives)
2096 "(`,' tries to find next)"
2097 "(Only match)")))
2099 (defun Info-find-index-name (name)
2100 "Move point to the place within the current node where NAME is defined."
2101 (let ((case-fold-search t))
2102 (if (or (re-search-forward (format
2103 "[a-zA-Z]+: %s\\( \\|$\\)"
2104 (regexp-quote name)) nil t)
2105 ;; Find a function definition with a return type.
2106 (re-search-forward (format
2107 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2108 (regexp-quote name)) nil t)
2109 (search-forward (format "`%s'" name) nil t)
2110 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2111 (search-forward
2112 (format "`%s'" (substring name 0 (match-beginning 1)))
2113 nil t))
2114 (search-forward name nil t))
2115 (beginning-of-line)
2116 (goto-char (point-min)))))
2118 (defun Info-undefined ()
2119 "Make command be undefined in Info."
2120 (interactive)
2121 (ding))
2123 (defun Info-help ()
2124 "Enter the Info tutorial."
2125 (interactive)
2126 (delete-other-windows)
2127 (Info-find-node "info"
2128 (if (< (window-height) 23)
2129 "Help-Small-Screen"
2130 "Help")))
2132 (defun Info-summary ()
2133 "Display a brief summary of all Info commands."
2134 (interactive)
2135 (save-window-excursion
2136 (switch-to-buffer "*Help*")
2137 (setq buffer-read-only nil)
2138 (erase-buffer)
2139 (insert (documentation 'Info-mode))
2140 (help-mode)
2141 (goto-char (point-min))
2142 (let (ch flag)
2143 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2144 (message (if flag "Type Space to see more"
2145 "Type Space to return to Info"))
2146 (if (not (eq ?\ (setq ch (read-event))))
2147 (progn (setq unread-command-events (list ch)) nil)
2148 flag))
2149 (scroll-up)))
2150 (bury-buffer "*Help*")))
2152 (defun Info-get-token (pos start all &optional errorstring)
2153 "Return the token around POS.
2154 POS must be somewhere inside the token
2155 START is a regular expression which will match the
2156 beginning of the tokens delimited string
2157 ALL is a regular expression with a single
2158 parenthesized subpattern which is the token to be
2159 returned. E.g. '{\(.*\)}' would return any string
2160 enclosed in braces around POS.
2161 ERRORSTRING optional fourth argument, controls action on no match
2162 nil: return nil
2163 t: beep
2164 a string: signal an error, using that string."
2165 (let ((case-fold-search t))
2166 (save-excursion
2167 (goto-char pos)
2168 ;; First look for a match for START that goes across POS.
2169 (while (and (not (bobp)) (> (point) (- pos (length start)))
2170 (not (looking-at start)))
2171 (forward-char -1))
2172 ;; If we did not find one, search back for START
2173 ;; (this finds only matches that end at or before POS).
2174 (or (looking-at start)
2175 (progn
2176 (goto-char pos)
2177 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2178 (let (found)
2179 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2180 (not (setq found (and (<= (match-beginning 0) pos)
2181 (> (match-end 0) pos))))))
2182 (if (and found (<= (match-beginning 0) pos)
2183 (> (match-end 0) pos))
2184 (match-string-no-properties 1)
2185 (cond ((null errorstring)
2186 nil)
2187 ((eq errorstring t)
2188 (beep)
2189 nil)
2191 (error "No %s around position %d" errorstring pos))))))))
2193 (defun Info-mouse-follow-nearest-node (click)
2194 "\\<Info-mode-map>Follow a node reference near point.
2195 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2196 At end of the node's text, moves to the next node, or up if none."
2197 (interactive "e")
2198 (mouse-set-point click)
2199 (and (not (Info-try-follow-nearest-node))
2200 (save-excursion (forward-line 1) (eobp))
2201 (Info-next-preorder)))
2203 (defun Info-follow-nearest-node ()
2204 "Follow a node reference near point.
2205 If point is on a reference, follow that reference. Otherwise,
2206 if point is in a menu item description, follow that menu item."
2207 (interactive)
2208 (or (Info-try-follow-nearest-node)
2209 (when (save-excursion
2210 (search-backward "\n* menu:" nil t))
2211 (save-excursion
2212 (beginning-of-line)
2213 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2214 (beginning-of-line 0))
2215 (when (looking-at "\\* +\\([^\t\n]*\\):")
2216 (Info-goto-node
2217 (Info-extract-menu-item (match-string-no-properties 1)))
2218 t)))
2219 (error "Point neither on reference nor in menu item description")))
2221 ;; Common subroutine.
2222 (defun Info-try-follow-nearest-node ()
2223 "Follow a node reference near point. Return non-nil if successful."
2224 (let (node)
2225 (cond
2226 ((setq node (Info-get-token (point) "\\*note[ \n]"
2227 "\\*note[ \n]\\([^:]*\\):"))
2228 (Info-follow-reference node))
2229 ;; menu item: node name
2230 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2231 (Info-goto-node node))
2232 ;; menu item: index entry
2233 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2234 (beginning-of-line)
2235 (forward-char 2)
2236 (setq node (Info-extract-menu-node-name))
2237 (Info-goto-node node))
2238 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2239 (Info-goto-node node))
2240 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2241 (Info-goto-node node))
2242 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2243 (Info-goto-node "Top"))
2244 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2245 (Info-goto-node node)))
2246 node))
2248 (defvar Info-mode-map nil
2249 "Keymap containing Info commands.")
2250 (if Info-mode-map
2252 (setq Info-mode-map (make-keymap))
2253 (suppress-keymap Info-mode-map)
2254 (define-key Info-mode-map "." 'beginning-of-buffer)
2255 (define-key Info-mode-map " " 'Info-scroll-up)
2256 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
2257 (define-key Info-mode-map "\t" 'Info-next-reference)
2258 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
2259 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2260 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2261 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2262 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2263 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2264 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2265 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2266 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2267 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2268 (define-key Info-mode-map "0" 'undefined)
2269 (define-key Info-mode-map "?" 'Info-summary)
2270 (define-key Info-mode-map "]" 'Info-forward-node)
2271 (define-key Info-mode-map "[" 'Info-backward-node)
2272 (define-key Info-mode-map "<" 'Info-top-node)
2273 (define-key Info-mode-map ">" 'Info-final-node)
2274 (define-key Info-mode-map "b" 'beginning-of-buffer)
2275 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2276 (define-key Info-mode-map "d" 'Info-directory)
2277 (define-key Info-mode-map "e" 'Info-edit)
2278 (define-key Info-mode-map "f" 'Info-follow-reference)
2279 (define-key Info-mode-map "g" 'Info-goto-node)
2280 (define-key Info-mode-map "h" 'Info-help)
2281 (define-key Info-mode-map "i" 'Info-index)
2282 (define-key Info-mode-map "l" 'Info-last)
2283 (define-key Info-mode-map "m" 'Info-menu)
2284 (define-key Info-mode-map "n" 'Info-next)
2285 (define-key Info-mode-map "p" 'Info-prev)
2286 (define-key Info-mode-map "q" 'Info-exit)
2287 (define-key Info-mode-map "s" 'Info-search)
2288 ;; For consistency with Rmail.
2289 (define-key Info-mode-map "\M-s" 'Info-search)
2290 (define-key Info-mode-map "\M-n" 'clone-buffer)
2291 (define-key Info-mode-map "t" 'Info-top-node)
2292 (define-key Info-mode-map "u" 'Info-up)
2293 (define-key Info-mode-map "," 'Info-index-next)
2294 (define-key Info-mode-map "\177" 'Info-scroll-down)
2295 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2298 (defun Info-check-pointer (item)
2299 "Non-nil if ITEM is present in this node."
2300 (condition-case nil
2301 (Info-extract-pointer item)
2302 (error nil)))
2304 (easy-menu-define
2305 Info-mode-menu Info-mode-map
2306 "Menu for info files."
2307 '("Info"
2308 ["Up" Info-up :active (Info-check-pointer "up")
2309 :help "Go up in the Info tree"]
2310 ["Next" Info-next :active (Info-check-pointer "next")
2311 :help "Go to the next node"]
2312 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2313 :help "Go to the previous node"]
2314 ["Backward" Info-backward-node
2315 :help "Go backward one node, considering all as a sequence"]
2316 ["Forward" Info-forward-node
2317 :help "Go forward one node, considering all as a sequence"]
2318 ["Beginning" beginning-of-buffer
2319 :help "Go to beginning of this node"]
2320 ["Top" Info-top-node
2321 :help "Go to top node of file"]
2322 ["Final Node" Info-final-node
2323 :help "Go to final node in this file"]
2324 ("Menu Item" ["You should never see this" report-emacs-bug t])
2325 ("Reference" ["You should never see this" report-emacs-bug t])
2326 ["Search..." Info-search
2327 :help "Search for regular expression in this Info file"]
2328 ["Go to Node..." Info-goto-node
2329 :help "Go to a named node"]
2330 ["Last" Info-last :active Info-history
2331 :help "Go to the last node you were at"]
2332 ("Index..."
2333 ["Lookup a String" Info-index
2334 :help "Look for a string in the index items"]
2335 ["Next Matching Item" Info-index-next
2336 :help "Look for another occurrence of previous item"])
2337 ["Edit" Info-edit :help "Edit contents of this node"
2338 :active Info-enable-edit]
2339 ["Copy Node Name" Info-copy-current-node-name
2340 :help "Copy the name of the current node into the kill ring"]
2341 ["Exit" Info-exit :help "Stop reading Info"]))
2344 (defvar info-tool-bar-map
2345 (if (display-graphic-p)
2346 (let ((map (make-sparse-keymap)))
2347 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2348 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2349 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2350 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2351 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2352 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2353 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2354 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2355 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2356 map)))
2358 (defvar Info-menu-last-node nil)
2359 ;; Last node the menu was created for.
2360 ;; Value is a list, (FILE-NAME NODE-NAME).
2362 (defun Info-menu-update ()
2363 "Update the Info menu for the current node."
2364 (condition-case nil
2365 (if (or (not (eq major-mode 'Info-mode))
2366 (equal (list Info-current-file Info-current-node)
2367 Info-menu-last-node))
2369 ;; Update menu menu.
2370 (let* ((Info-complete-menu-buffer (current-buffer))
2371 (items (nreverse (condition-case nil
2372 (Info-complete-menu-item "" nil t)
2373 (error nil))))
2374 entries current
2375 (number 0))
2376 (while (and items (< number 9))
2377 (setq current (car items)
2378 items (cdr items)
2379 number (1+ number))
2380 (setq entries (cons `[,current
2381 (Info-menu ,current)
2382 :keys ,(format "%d" number)]
2383 entries)))
2384 (if items
2385 (setq entries (cons ["Other..." Info-menu t] entries)))
2386 (or entries
2387 (setq entries (list ["No menu" nil nil] nil :active)))
2388 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2389 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2390 (let ((items nil)
2391 str i entries current
2392 (number 0)
2393 (case-fold-search t))
2394 (save-excursion
2395 (goto-char (point-min))
2396 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2397 (setq str (match-string 1))
2398 (setq i 0)
2399 (while (setq i (string-match "[ \n\t]+" str i))
2400 (setq str (concat (substring str 0 i) " "
2401 (substring str (match-end 0))))
2402 (setq i (1+ i)))
2403 (setq items
2404 (cons str items))))
2405 (while (and items (< number 9))
2406 (setq current (car items)
2407 items (cdr items)
2408 number (1+ number))
2409 (setq entries (cons `[,current
2410 (Info-follow-reference ,current)
2412 entries)))
2413 (if items
2414 (setq entries (cons ["Other..." Info-follow-reference t]
2415 entries)))
2416 (or entries
2417 (setq entries (list ["No references" nil nil] nil :active)))
2418 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2419 ;; Update last seen node.
2420 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2421 ;; Try to avoid entering infinite beep mode in case of errors.
2422 (error (ding))))
2425 (defun Info-copy-current-node-name ()
2426 "Put the name of the current info node into the kill ring.
2427 The name of the info file is prepended to the node name in parentheses."
2428 (interactive)
2429 (unless Info-current-node
2430 (error "No current info node"))
2431 (kill-new
2432 (concat "("
2433 (file-name-nondirectory
2434 (if (stringp Info-current-file)
2435 Info-current-file
2436 (or buffer-file-name "")))
2438 Info-current-node)))
2441 ;; Info mode is suitable only for specially formatted data.
2442 (put 'Info-mode 'mode-class 'special)
2443 (put 'Info-mode 'no-clone-indirect t)
2445 (defun Info-mode ()
2446 "Info mode provides commands for browsing through the Info documentation tree.
2447 Documentation in Info is divided into \"nodes\", each of which discusses
2448 one topic and contains references to other nodes which discuss related
2449 topics. Info has commands to follow the references and show you other nodes.
2451 \\<Info-mode-map>\
2452 \\[Info-help] Invoke the Info tutorial.
2453 \\[Info-exit] Quit Info: reselect previously selected buffer.
2455 Selecting other nodes:
2456 \\[Info-mouse-follow-nearest-node]
2457 Follow a node reference you click on.
2458 This works with menu items, cross references, and
2459 the \"next\", \"previous\" and \"up\", depending on where you click.
2460 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2461 \\[Info-next] Move to the \"next\" node of this node.
2462 \\[Info-prev] Move to the \"previous\" node of this node.
2463 \\[Info-up] Move \"up\" from this node.
2464 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2465 Picking a menu item causes another node to be selected.
2466 \\[Info-directory] Go to the Info directory node.
2467 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2468 \\[Info-last] Move to the last node you were at.
2469 \\[Info-index] Look up a topic in this file's Index and move to that node.
2470 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2471 \\[Info-top-node] Go to the Top node of this file.
2472 \\[Info-final-node] Go to the final node in this file.
2473 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2474 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2476 Moving within a node:
2477 \\[Info-scroll-up] Normally, scroll forward a full screen.
2478 Once you scroll far enough in a node that its menu appears on the
2479 screen but after point, the next scroll moves into its first
2480 subnode. When after all menu items (or if there is no menu),
2481 move up to the parent node.
2482 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2483 already visible, try to go to the previous menu entry, or up
2484 if there is none.
2485 \\[beginning-of-buffer] Go to beginning of node.
2487 Advanced commands:
2488 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
2489 \\[Info-edit] Edit contents of selected node.
2490 1 Pick first item in node's menu.
2491 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2492 \\[Info-goto-node] Move to node specified by name.
2493 You may include a filename as well, as (FILENAME)NODENAME.
2494 \\[universal-argument] \\[info] Move to new Info file with completion.
2495 \\[Info-search] Search through this Info file for specified regexp,
2496 and select the node in which the next occurrence is found.
2497 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2498 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2499 (kill-all-local-variables)
2500 (setq major-mode 'Info-mode)
2501 (setq mode-name "Info")
2502 (setq tab-width 8)
2503 (use-local-map Info-mode-map)
2504 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2505 (set-syntax-table text-mode-syntax-table)
2506 (setq local-abbrev-table text-mode-abbrev-table)
2507 (setq case-fold-search t)
2508 (setq buffer-read-only t)
2509 (make-local-variable 'Info-current-file)
2510 (make-local-variable 'Info-current-subfile)
2511 (make-local-variable 'Info-current-node)
2512 (make-local-variable 'Info-tag-table-marker)
2513 (setq Info-tag-table-marker (make-marker))
2514 (make-local-variable 'Info-tag-table-buffer)
2515 (setq Info-tag-table-buffer nil)
2516 (make-local-variable 'Info-history)
2517 (make-local-variable 'Info-index-alternatives)
2518 (setq header-line-format
2519 (if Info-use-header-line
2520 '(:eval (get-text-property (point-min) 'header-line))
2521 nil)) ; so the header line isn't displayed
2522 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
2523 ;; This is for the sake of the invisible text we use handling titles.
2524 (make-local-variable 'line-move-ignore-invisible)
2525 (setq line-move-ignore-invisible t)
2526 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
2527 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
2528 (Info-set-mode-line)
2529 (run-hooks 'Info-mode-hook))
2531 (defun Info-clone-buffer-hook ()
2532 (when (bufferp Info-tag-table-buffer)
2533 (setq Info-tag-table-buffer
2534 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2535 (let ((m Info-tag-table-marker))
2536 (when (markerp m)
2537 (setq Info-tag-table-marker
2538 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
2539 (with-current-buffer Info-tag-table-buffer
2540 (copy-marker (marker-position m)))
2541 (make-marker))))))
2543 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
2544 (set-keymap-parent map text-mode-map)
2545 (define-key map "\C-c\C-c" 'Info-cease-edit)
2546 map)
2547 "Local keymap used within `e' command of Info.")
2549 ;; Info-edit mode is suitable only for specially formatted data.
2550 (put 'Info-edit-mode 'mode-class 'special)
2552 (defun Info-edit-mode ()
2553 "Major mode for editing the contents of an Info node.
2554 Like text mode with the addition of `Info-cease-edit'
2555 which returns to Info mode for browsing.
2556 \\{Info-edit-map}"
2557 (use-local-map Info-edit-map)
2558 (setq major-mode 'Info-edit-mode)
2559 (setq mode-name "Info Edit")
2560 (kill-local-variable 'mode-line-buffer-identification)
2561 (setq buffer-read-only nil)
2562 (force-mode-line-update)
2563 (buffer-enable-undo (current-buffer))
2564 (run-hooks 'Info-edit-mode-hook))
2566 (defun Info-edit ()
2567 "Edit the contents of this Info node.
2568 Allowed only if variable `Info-enable-edit' is non-nil."
2569 (interactive)
2570 (or Info-enable-edit
2571 (error "Editing info nodes is not enabled"))
2572 (Info-edit-mode)
2573 (message "%s" (substitute-command-keys
2574 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2576 (defun Info-cease-edit ()
2577 "Finish editing Info node; switch back to Info proper."
2578 (interactive)
2579 ;; Do this first, so nothing has changed if user C-g's at query.
2580 (and (buffer-modified-p)
2581 (y-or-n-p "Save the file? ")
2582 (save-buffer))
2583 (use-local-map Info-mode-map)
2584 (setq major-mode 'Info-mode)
2585 (setq mode-name "Info")
2586 (Info-set-mode-line)
2587 (setq buffer-read-only t)
2588 (force-mode-line-update)
2589 (and (marker-position Info-tag-table-marker)
2590 (buffer-modified-p)
2591 (message "Tags may have changed. Use Info-tagify if necessary")))
2593 (defvar Info-file-list-for-emacs
2594 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
2595 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
2596 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
2597 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
2598 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2599 ("copyright" . "autotype") ("executable" . "autotype")
2600 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2601 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2602 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
2603 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
2604 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2605 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
2606 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
2607 ("rfc2045" . "emacs-mime")
2608 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
2609 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
2610 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
2611 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
2612 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
2613 ("mml" . "emacs-mime"))
2614 "List of Info files that describe Emacs commands.
2615 An element can be a file name, or a list of the form (PREFIX . FILE)
2616 where PREFIX is a name prefix and FILE is the file to look in.
2617 If the element is just a file name, the file name also serves as the prefix.")
2619 (defun Info-find-emacs-command-nodes (command)
2620 "Return a list of locations documenting COMMAND.
2621 The `info-file' property of COMMAND says which Info manual to search.
2622 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2623 defines heuristics for which Info manual to try.
2624 The locations are of the format used in `Info-history', i.e.
2625 \(FILENAME NODENAME BUFFERPOS\)."
2626 (let ((where '())
2627 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2628 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2629 (info-file "emacs")) ;default
2630 ;; Determine which info file this command is documented in.
2631 (if (get command 'info-file)
2632 (setq info-file (get command 'info-file))
2633 ;; If it doesn't say explicitly, test its name against
2634 ;; various prefixes that we know.
2635 (let ((file-list Info-file-list-for-emacs))
2636 (while file-list
2637 (let* ((elt (car file-list))
2638 (name (if (consp elt)
2639 (car elt)
2640 elt))
2641 (file (if (consp elt) (cdr elt) elt))
2642 (regexp (concat "\\`" (regexp-quote name)
2643 "\\(\\'\\|-\\)")))
2644 (if (string-match regexp (symbol-name command))
2645 (setq info-file file file-list nil))
2646 (setq file-list (cdr file-list))))))
2647 (Info-find-node info-file "Top")
2648 (or (and (search-forward "\n* menu:" nil t)
2649 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2650 (error "Info file `%s' appears to lack an index" info-file))
2651 (goto-char (match-beginning 1))
2652 ;; Bind Info-history to nil, to prevent the index nodes from
2653 ;; getting into the node history.
2654 (let ((Info-history nil)
2655 node)
2656 (Info-goto-node (Info-extract-menu-node-name))
2657 (while
2658 (progn
2659 (goto-char (point-min))
2660 (while (re-search-forward cmd-desc nil t)
2661 (setq where
2662 (cons (list Info-current-file
2663 (match-string-no-properties 2)
2665 where)))
2666 (and (setq node (Info-extract-pointer "next" t))
2667 (string-match "\\<Index\\>" node)))
2668 (Info-goto-node node)))
2669 where))
2671 ;;;###autoload
2672 (defun Info-goto-emacs-command-node (command)
2673 "Go to the Info node in the Emacs manual for command COMMAND.
2674 The command is found by looking up in Emacs manual's indices
2675 or in another manual found via COMMAND's `info-file' property or
2676 the variable `Info-file-list-for-emacs'. COMMAND must be a symbol
2677 or string."
2678 (interactive "CFind documentation for command: ")
2679 ;; If command is given as a string, convert it to a symbol.
2680 (if (stringp command)
2681 (setq command (intern command)))
2682 (or (commandp command)
2683 (signal 'wrong-type-argument (list 'commandp command)))
2684 (let ((where (Info-find-emacs-command-nodes command)))
2685 (if where
2686 (let ((num-matches (length where)))
2687 ;; Get Info running, and pop to it in another window.
2688 (save-window-excursion
2689 (info))
2690 ;; FIXME It would be cool if this could use a buffer other
2691 ;; than *info*.
2692 (pop-to-buffer "*info*")
2693 ;; Bind Info-history to nil, to prevent the last Index node
2694 ;; visited by Info-find-emacs-command-nodes from being
2695 ;; pushed onto the history.
2696 (let ((Info-history nil))
2697 (Info-find-node (car (car where))
2698 (car (cdr (car where)))))
2699 (if (> num-matches 1)
2700 (progn
2701 ;; (car where) will be pushed onto Info-history
2702 ;; when/if they go to another node. Put the other
2703 ;; nodes that were found on the history.
2704 (setq Info-history (nconc (cdr where) Info-history))
2705 (message "Found %d other entr%s. Use %s to see %s."
2706 (1- num-matches)
2707 (if (> num-matches 2) "ies" "y")
2708 (substitute-command-keys "\\[Info-last]")
2709 (if (> num-matches 2) "them" "it")))))
2710 (error "Couldn't find documentation for %s" command))))
2712 ;;;###autoload
2713 (defun Info-goto-emacs-key-command-node (key)
2714 "Go to the node in the Emacs manual which describes the command bound to KEY.
2715 KEY is a string.
2716 Interactively, if the binding is `execute-extended-command', a command is read.
2717 The command is found by looking up in Emacs manual's indices
2718 or in another manual found via COMMAND's `info-file' property or
2719 the variable `Info-file-list-for-emacs'."
2720 (interactive "kFind documentation for key: ")
2721 (let ((command (key-binding key)))
2722 (cond ((null command)
2723 (message "%s is undefined" (key-description key)))
2724 ((and (interactive-p)
2725 (eq command 'execute-extended-command))
2726 (Info-goto-emacs-command-node
2727 (read-command "Find documentation for command: ")))
2729 (Info-goto-emacs-command-node command)))))
2731 (defface Info-title-1-face
2732 '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
2733 (t (:height 1.2 :inherit Info-title-2-face)))
2734 "Face for Info titles at level 1."
2735 :group 'info)
2737 (defface Info-title-2-face
2738 '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
2739 (t (:height 1.2 :inherit Info-title-3-face)))
2740 "Face for Info titles at level 2."
2741 :group 'info)
2743 (defface Info-title-3-face
2744 '((((type tty pc) (class color)) (:weight bold))
2745 (t (:height 1.2 :inherit Info-title-4-face)))
2746 "Face for Info titles at level 3."
2747 :group 'info)
2749 (defface Info-title-4-face
2750 '((((type tty pc) (class color)) (:weight bold))
2751 (t (:weight bold :inherit variable-pitch)))
2752 "Face for Info titles at level 4."
2753 :group 'info)
2755 (defface info-menu-header
2756 '((((type tty pc))
2757 :underline t
2758 :weight bold)
2760 :inherit variable-pitch
2761 :weight bold))
2762 "Face for headers in Info menus."
2763 :group 'info)
2765 (defun Info-fontify-menu-headers ()
2766 "Add the face `info-menu-header' to any header before a menu entry."
2767 (save-excursion
2768 (goto-char (point-min))
2769 (when (re-search-forward "^\\* Menu:" nil t)
2770 (put-text-property (match-beginning 0) (match-end 0)
2771 'font-lock-face 'info-menu-header)
2772 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
2773 (put-text-property (match-beginning 1) (match-end 1)
2774 'font-lock-face 'info-menu-header)))))
2776 (defvar Info-next-link-keymap
2777 (let ((keymap (make-sparse-keymap)))
2778 (define-key keymap [header-line mouse-1] 'Info-next)
2779 (define-key keymap [header-line mouse-2] 'Info-next)
2780 (define-key keymap [header-line down-mouse-1] 'ignore)
2781 (define-key keymap [mouse-2] 'Info-next)
2782 keymap)
2783 "Keymap to put on the Next link in the text or the header line.")
2785 (defvar Info-prev-link-keymap
2786 (let ((keymap (make-sparse-keymap)))
2787 (define-key keymap [header-line mouse-1] 'Info-prev)
2788 (define-key keymap [header-line mouse-2] 'Info-prev)
2789 (define-key keymap [header-line down-mouse-1] 'ignore)
2790 (define-key keymap [mouse-2] 'Info-prev)
2791 keymap)
2792 "Keymap to put on the Prev link in the text or the header line.")
2795 (defvar Info-up-link-keymap
2796 (let ((keymap (make-sparse-keymap)))
2797 (define-key keymap [header-line mouse-1] 'Info-up)
2798 (define-key keymap [header-line mouse-2] 'Info-up)
2799 (define-key keymap [header-line down-mouse-1] 'ignore)
2800 (define-key keymap [mouse-2] 'Info-up)
2801 keymap)
2802 "Keymap to put on the Up link in the text or the header line.")
2804 (defun Info-fontify-node ()
2805 ;; Only fontify the node if it hasn't already been done.
2806 (unless (let ((where (next-property-change (point-min))))
2807 (and where (not (= where (point-max)))))
2808 (save-excursion
2809 (let ((inhibit-read-only t)
2810 (case-fold-search t)
2811 paragraph-markers)
2812 (goto-char (point-min))
2813 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
2814 (goto-char (match-end 0))
2815 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2816 (goto-char (match-end 0))
2817 (let* ((nbeg (match-beginning 2))
2818 (nend (match-end 2))
2819 (tbeg (match-beginning 1))
2820 (tag (match-string 1)))
2821 (if (string-equal tag "Node")
2822 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
2823 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
2824 (put-text-property tbeg nend 'mouse-face 'highlight)
2825 (put-text-property tbeg nend
2826 'help-echo
2827 (concat "Go to node "
2828 (buffer-substring nbeg nend)))
2829 ;; Always set up the text property keymap.
2830 ;; It will either be used in the buffer
2831 ;; or copied in the header line.
2832 (put-text-property tbeg nend 'keymap
2833 (cond
2834 ((equal tag "Prev") Info-prev-link-keymap)
2835 ((equal tag "Next") Info-next-link-keymap)
2836 ((equal tag "Up") Info-up-link-keymap))))))
2837 (when Info-use-header-line
2838 (goto-char (point-min))
2839 (let ((header-end (line-end-position))
2840 header)
2841 ;; If we find neither Next: nor Prev: link, show the entire
2842 ;; node header. Otherwise, don't show the File: and Node:
2843 ;; parts, to avoid wasting precious space on information that
2844 ;; is available in the mode line.
2845 (if (re-search-forward
2846 "\\(next\\|up\\|prev[ious]*\\): "
2847 header-end t)
2848 (progn
2849 (goto-char (match-beginning 1))
2850 (setq header (buffer-substring (point) header-end)))
2851 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
2852 (setq header
2853 (concat "No next, prev or up links -- "
2854 (buffer-substring (point) header-end)))
2855 (setq header (buffer-substring (point) header-end))))
2857 (put-text-property (point-min) (1+ (point-min))
2858 'header-line header)
2859 ;; Hide the part of the first line
2860 ;; that is in the header, if it is just part.
2861 (unless (bobp)
2862 ;; Hide the punctuation at the end, too.
2863 (skip-chars-backward " \t,")
2864 (put-text-property (point) header-end 'invisible t)))))
2865 (goto-char (point-min))
2866 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2867 nil t)
2868 (let* ((c (preceding-char))
2869 (face
2870 (cond ((= c ?*) 'Info-title-1-face)
2871 ((= c ?=) 'Info-title-2-face)
2872 ((= c ?-) 'Info-title-3-face)
2873 (t 'Info-title-4-face))))
2874 (put-text-property (match-beginning 1) (match-end 1)
2875 'font-lock-face face))
2876 ;; This is a serious problem for trying to handle multiple
2877 ;; frame types at once. We want this text to be invisible
2878 ;; on frames that can display the font above.
2879 (when (memq (framep (selected-frame)) '(x pc w32 mac))
2880 (add-text-properties (1- (match-beginning 2)) (match-end 2)
2881 '(invisible t front-sticky nil rear-nonsticky t))))
2882 (goto-char (point-min))
2883 (while (re-search-forward "\\(\\*Note[ \t]*\\)\n?[ \t]*\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t)
2884 (unless (= (char-after (1- (match-beginning 0))) ?\") ; hack
2885 (let ((start (match-beginning 0))
2886 (next (point))
2887 (hide-tag Info-hide-note-references)
2888 other-tag)
2889 (when hide-tag
2890 ;; *Note is often used where *note should have been
2891 (goto-char start)
2892 (skip-syntax-backward " ")
2893 (setq other-tag
2894 (cond ((memq (char-before) '(nil ?\. ?! ??))
2895 "See ")
2896 ((memq (char-before) '(?\, ?\; ?\: ?-))
2897 "see ")
2898 ((memq (char-before) '(?\( ?\[ ?\{))
2899 ;; Check whether the paren is preceded by
2900 ;; an end of sentence
2901 (skip-syntax-backward " (")
2902 (if (memq (char-before) '(nil ?\. ?! ??))
2903 "See "
2904 "see "))
2905 ((save-match-data (looking-at "\n\n"))
2906 "See ")))
2907 (goto-char next))
2908 (if hide-tag
2909 (add-text-properties (match-beginning 1) (match-end 1)
2910 '(invisible t front-sticky nil rear-nonsticky t)))
2911 (add-text-properties
2912 (match-beginning 2) (match-end 2)
2913 (cons 'help-echo
2914 (cons (if (match-end 4)
2915 (concat "mouse-2: go to " (match-string 4))
2916 "mouse-2: go to this node")
2917 '(font-lock-face info-xref
2918 mouse-face highlight))))
2919 (when (eq Info-hide-note-references t)
2920 (add-text-properties (match-beginning 3) (match-end 3)
2921 '(invisible t front-sticky nil rear-nonsticky t)))
2922 (when other-tag
2923 (save-excursion
2924 (goto-char (match-beginning 1))
2925 (insert other-tag)))
2926 (when (and Info-refill-paragraphs
2927 (or hide-tag (eq Info-hide-note-references t)))
2928 (push (set-marker (make-marker) start)
2929 paragraph-markers)))))
2931 (when (and Info-refill-paragraphs
2932 paragraph-markers)
2933 (let ((fill-nobreak-invisible t)
2934 (fill-individual-varying-indent nil)
2935 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
2936 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
2937 (adaptive-fill-mode nil))
2938 (goto-char (point-max))
2939 (while paragraph-markers
2940 (let ((m (car paragraph-markers)))
2941 (setq paragraph-markers (cdr paragraph-markers))
2942 (when (< m (point))
2943 (goto-char m)
2944 (beginning-of-line)
2945 (let ((beg (point)))
2946 (when (zerop (forward-paragraph))
2947 (fill-individual-paragraphs beg (point) nil nil)
2948 (goto-char beg))))
2949 (set-marker m nil)))))
2951 (goto-char (point-min))
2952 (when (and (search-forward "\n* Menu:" nil t)
2953 (not (string-match "\\<Index\\>" Info-current-node))
2954 ;; Don't take time to annotate huge menus
2955 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2956 (let ((n 0)
2957 cont)
2958 (while (re-search-forward
2959 (concat "^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
2960 Info-node-spec-re "\\([ \t]*\\)\\)")
2961 nil t)
2962 (setq n (1+ n))
2963 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
2964 (put-text-property (match-beginning 0)
2965 (1+ (match-beginning 0))
2966 'font-lock-face 'info-menu-5))
2967 (add-text-properties
2968 (match-beginning 1) (match-end 1)
2969 (cons 'help-echo
2970 (cons
2971 (if (match-end 3)
2972 (concat "mouse-2: go to " (match-string 3))
2973 "mouse-2: go to this node")
2974 '(font-lock-face info-xref
2975 mouse-face highlight))))
2976 (when (eq Info-hide-note-references t)
2977 (put-text-property (match-beginning 2) (1- (match-end 6))
2978 'invisible t)
2979 ;; We need a stretchable space like :align-to but with
2980 ;; a minimum value.
2981 (put-text-property (1- (match-end 6)) (match-end 6) 'display
2982 (if (>= 22 (- (match-end 1)
2983 (match-beginning 0)))
2984 '(space :align-to 24)
2985 '(space :width 2)))
2986 (setq cont (looking-at "."))
2987 (while (and (= (forward-line 1) 0)
2988 (looking-at "\\([ \t]+\\)[^*\n]"))
2989 (put-text-property (match-beginning 1) (1- (match-end 1))
2990 'invisible t)
2991 (put-text-property (1- (match-end 1)) (match-end 1)
2992 'display
2993 (if cont
2994 '(space :align-to 26)
2995 '(space :align-to 24)))
2996 (setq cont t))))))
2998 (Info-fontify-menu-headers)
2999 (set-buffer-modified-p nil)))))
3002 ;; When an Info buffer is killed, make sure the associated tags buffer
3003 ;; is killed too.
3004 (defun Info-kill-buffer ()
3005 (and (eq major-mode 'Info-mode)
3006 Info-tag-table-buffer
3007 (kill-buffer Info-tag-table-buffer)))
3009 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
3011 ;;; Speedbar support:
3012 ;; These functions permit speedbar to display the "tags" in the
3013 ;; current info node.
3014 (eval-when-compile (require 'speedbar))
3016 (defvar Info-speedbar-key-map nil
3017 "Keymap used when in the info display mode.")
3019 (defun Info-install-speedbar-variables ()
3020 "Install those variables used by speedbar to enhance Info."
3021 (if Info-speedbar-key-map
3023 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3025 ;; Basic tree features
3026 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3027 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3028 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3029 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3032 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3033 Info-speedbar-key-map
3034 Info-speedbar-hierarchy-buttons)))
3036 (defvar Info-speedbar-menu-items
3037 '(["Browse Node" speedbar-edit-line t]
3038 ["Expand Node" speedbar-expand-line
3039 (save-excursion (beginning-of-line)
3040 (looking-at "[0-9]+: *.\\+. "))]
3041 ["Contract Node" speedbar-contract-line
3042 (save-excursion (beginning-of-line)
3043 (looking-at "[0-9]+: *.-. "))]
3045 "Additional menu-items to add to speedbar frame.")
3047 ;; Make sure our special speedbar major mode is loaded
3048 (if (featurep 'speedbar)
3049 (Info-install-speedbar-variables)
3050 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
3052 ;;; Info hierarchy display method
3053 ;;;###autoload
3054 (defun Info-speedbar-browser ()
3055 "Initialize speedbar to display an info node browser.
3056 This will add a speedbar major display mode."
3057 (interactive)
3058 (require 'speedbar)
3059 ;; Make sure that speedbar is active
3060 (speedbar-frame-mode 1)
3061 ;; Now, throw us into Info mode on speedbar.
3062 (speedbar-change-initial-expansion-list "Info")
3065 (eval-when-compile (defvar speedbar-attached-frame))
3067 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
3068 "Display an Info directory hierarchy in speedbar.
3069 DIRECTORY is the current directory in the attached frame.
3070 DEPTH is the current indentation depth.
3071 NODE is an optional argument that is used to represent the
3072 specific node to expand."
3073 (if (and (not node)
3074 (save-excursion (goto-char (point-min))
3075 (let ((case-fold-search t))
3076 (looking-at "Info Nodes:"))))
3077 ;; Update our "current node" maybe?
3079 ;; We cannot use the generic list code, that depends on all leaves
3080 ;; being known at creation time.
3081 (if (not node)
3082 (speedbar-with-writable (insert "Info Nodes:\n")))
3083 (let ((completions nil)
3084 (cf (selected-frame)))
3085 (select-frame speedbar-attached-frame)
3086 (save-window-excursion
3087 (setq completions
3088 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
3089 (select-frame cf)
3090 (if completions
3091 (speedbar-with-writable
3092 (dolist (completion completions)
3093 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
3094 (cdr completion)
3095 (car completion)
3096 'Info-speedbar-goto-node
3097 (cdr completion)
3098 'info-xref depth))
3100 nil))))
3102 (defun Info-speedbar-goto-node (text node indent)
3103 "When user clicks on TEXT, go to an info NODE.
3104 The INDENT level is ignored."
3105 (select-frame speedbar-attached-frame)
3106 (let* ((buff (or (get-buffer "*info*")
3107 (progn (info) (get-buffer "*info*"))))
3108 (bwin (get-buffer-window buff 0)))
3109 (if bwin
3110 (progn
3111 (select-window bwin)
3112 (raise-frame (window-frame bwin)))
3113 (if speedbar-power-click
3114 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3115 (select-frame speedbar-attached-frame)
3116 (switch-to-buffer buff)))
3117 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3118 (error "Invalid node %s" node)
3119 (Info-find-node (match-string 1 node) (match-string 2 node))
3120 ;; If we do a find-node, and we were in info mode, restore
3121 ;; the old default method. Once we are in info mode, it makes
3122 ;; sense to return to whatever method the user was using before.
3123 (if (string= speedbar-initial-expansion-list-name "Info")
3124 (speedbar-change-initial-expansion-list
3125 speedbar-previously-used-expansion-list-name)))))
3127 (defun Info-speedbar-expand-node (text token indent)
3128 "Expand the node the user clicked on.
3129 TEXT is the text of the button we clicked on, a + or - item.
3130 TOKEN is data related to this node (NAME . FILE).
3131 INDENT is the current indentation depth."
3132 (cond ((string-match "+" text) ;we have to expand this file
3133 (speedbar-change-expand-button-char ?-)
3134 (if (speedbar-with-writable
3135 (save-excursion
3136 (end-of-line) (forward-char 1)
3137 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
3138 (speedbar-change-expand-button-char ?-)
3139 (speedbar-change-expand-button-char ??)))
3140 ((string-match "-" text) ;we have to contract this node
3141 (speedbar-change-expand-button-char ?+)
3142 (speedbar-delete-subblock indent))
3143 (t (error "Ooops... not sure what to do")))
3144 (speedbar-center-buffer-smartly))
3146 (defun Info-speedbar-fetch-file-nodes (nodespec)
3147 "Fetch the subnodes from the info NODESPEC.
3148 NODESPEC is a string of the form: (file)node.
3149 Optional THISFILE represends the filename of"
3150 (save-excursion
3151 ;; Set up a buffer we can use to fake-out Info.
3152 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3153 (if (not (equal major-mode 'Info-mode))
3154 (Info-mode))
3155 ;; Get the node into this buffer
3156 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3157 (error "Invalid node specification %s" nodespec)
3158 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
3159 ;; Scan the created buffer
3160 (goto-char (point-min))
3161 (let ((completions nil)
3162 (case-fold-search t)
3163 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3164 (match-string 1 nodespec))))
3165 ;; Always skip the first one...
3166 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3167 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3168 (let ((name (match-string 1)))
3169 (push (cons name
3170 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3171 (match-string 1)
3172 (if (looking-at " *\\(([^)]+)\\)\\.")
3173 (concat (match-string 1) "Top")
3174 (concat "(" thisfile ")"
3175 (if (looking-at " \\([^.]+\\).")
3176 (match-string 1)
3177 name)))))
3178 completions)))
3179 (nreverse completions))))
3181 ;;; Info mode node listing
3182 ;; FIXME: Seems not to be used. -stef
3183 (defun Info-speedbar-buttons (buffer)
3184 "Create a speedbar display to help navigation in an Info file.
3185 BUFFER is the buffer speedbar is requesting buttons for."
3186 (if (save-excursion (goto-char (point-min))
3187 (let ((case-fold-search t))
3188 (not (looking-at "Info Nodes:"))))
3189 (erase-buffer))
3190 (Info-speedbar-hierarchy-buttons nil 0)
3193 (dolist (mess '("^Node has no Previous$"
3194 "^No menu in this node$"
3195 "^Node has no Next$"
3196 "^No cross-references in this node^"
3197 search-failed
3198 "^No \".*\" in index$"))
3199 (add-to-list 'debug-ignored-errors mess))
3201 (provide 'info)
3203 ;;; info.el ends here