(set-visited-file-name, file-expand-wildcards): Fix docstring.
[emacs.git] / lisp / info.el
blob085be1ae897e4be2dec732f09b7600e8ec115119
1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985,86,92,93,94,95,96,97,98,99,2000,01,02,03,2004
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: help
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29 ;; In particular we make these assumptions:
30 ;; - a menu item MAY contain colons but not colon-space ": "
31 ;; - a menu item ending with ": " (but not ":: ") is an index entry
32 ;; - a node name MAY NOT contain a colon
33 ;; This distinction is to support indexing of computer programming
34 ;; language terms that may contain ":" but not ": ".
36 ;;; Code:
38 (eval-when-compile (require 'jka-compr))
40 (defgroup info nil
41 "Info subsystem"
42 :group 'help
43 :group 'docs)
46 (defvar Info-history nil
47 "Stack of info nodes user has visited.
48 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50 (defvar Info-history-list nil
51 "List of all info nodes user has visited.
52 Each element of list is a list (FILENAME NODENAME).")
54 (defcustom Info-enable-edit nil
55 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
56 This is convenient if you want to write info files by hand.
57 However, we recommend that you not do this.
58 It is better to write a Texinfo file and generate the Info file from that,
59 because that gives you a printed manual as well."
60 :type 'boolean
61 :group 'info)
63 (defvar Info-enable-active-nodes nil
64 "Non-nil allows Info to execute Lisp code associated with nodes.
65 The Lisp code is executed when the node is selected.")
66 (put 'Info-enable-active-nodes 'risky-local-variable t)
68 (defface info-node
69 '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
70 (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
71 (t :weight bold :slant italic))
72 "Face for Info node names."
73 :group 'info)
75 (defface info-menu-5
76 '((((class color)) :foreground "red1")
77 (t :underline t))
78 "Face for every third `*' in an Info menu."
79 :group 'info)
81 (defface info-xref
82 '((((class color) (background light)) :foreground "blue")
83 (((class color) (background dark)) :foreground "cyan")
84 (t :underline t))
85 "Face for Info cross-references."
86 :group 'info)
88 (defface info-xref-visited
89 '((t :inherit info-xref)
90 (((class color) (background light)) :foreground "magenta4")
91 (((class color) (background dark)) :foreground "magenta3")) ;"violet"?
92 "Face for visited Info cross-references."
93 :group 'info)
95 (defcustom Info-fontify-visited-nodes t
96 "*Non-nil means to fontify visited nodes in a different face."
97 :version "21.4"
98 :type 'boolean
99 :group 'info)
101 (defcustom Info-fontify-maximum-menu-size 100000
102 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
103 :type 'integer
104 :group 'info)
106 (defcustom Info-use-header-line t
107 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
108 A header-line does not scroll with the rest of the buffer."
109 :type 'boolean
110 :group 'info)
112 (defface info-header-xref
113 '((t :inherit info-xref))
114 "Face for Info cross-references in a node header."
115 :group 'info)
117 (defface info-header-node
118 '((t :inherit info-node))
119 "Face for Info nodes in a node header."
120 :group 'info)
122 (defvar Info-directory-list nil
123 "List of directories to search for Info documentation files.
124 If nil, meaning not yet initialized, Info uses the environment
125 variable INFOPATH to initialize it, or `Info-default-directory-list'
126 if there is no INFOPATH variable in the environment, or the
127 concatenation of the two if INFOPATH ends with a colon.
129 When `Info-directory-list' is initialized from the value of
130 `Info-default-directory-list', and Emacs is installed in one of the
131 standard directories, the directory of Info files that come with Emacs
132 is put last (so that local Info files override standard ones).
134 When `Info-directory-list' is initialized from the value of
135 `Info-default-directory-list', and Emacs is not installed in one
136 of the standard directories, the first element of the resulting
137 list is the directory where Emacs installs the Info files that
138 come with it. This is so that Emacs's own manual, which suits the
139 version of Emacs you are using, will always be found first. This
140 is useful when you install an experimental version of Emacs without
141 removing the standard installation.
143 If you want to override the order of directories in
144 `Info-default-directory-list', set INFOPATH in the environment.
146 If you run the Emacs executable from the `src' directory in the Emacs
147 source tree, and INFOPATH is not defined, the `info' directory in the
148 source tree is used as the first element of `Info-directory-list', in
149 place of the installation Info directory. This is useful when you run
150 a version of Emacs without installing it.")
152 (defcustom Info-additional-directory-list nil
153 "List of additional directories to search for Info documentation files.
154 These directories are searched after those in `Info-directory-list'."
155 :type '(repeat directory)
156 :group 'info)
158 (defcustom Info-scroll-prefer-subnodes nil
159 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
160 If this is non-nil, and you scroll far enough in a node that its menu
161 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
162 moves to a subnode indicated by the following menu item. This means
163 that you visit a subnode before getting to the end of the menu.
165 Setting this option to nil results in behavior similar to the stand-alone
166 Info reader program, which visits the first subnode from the menu only
167 when you hit the end of the current node."
168 :version "21.4"
169 :type 'boolean
170 :group 'info)
172 (defcustom Info-hide-note-references t
173 "*If non-nil, hide the tag and section reference in *note and * menu items.
174 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
175 If value is non-nil but not t or `hide', the reference section is still shown."
176 :version "21.4"
177 :type '(choice (const :tag "No hiding" nil)
178 (const :tag "Replace tag and hide reference" t)
179 (const :tag "Hide tag and reference" hide)
180 (other :tag "Only replace tag" tag))
181 :group 'info)
183 (defcustom Info-refill-paragraphs nil
184 "*If non-nil, attempt to refill paragraphs with hidden references.
185 This refilling may accidentally remove explicit line breaks in the info
186 file, so be prepared for a few surprises if you enable this feature."
187 :version "21.4"
188 :type 'boolean
189 :group 'info)
191 (defcustom Info-search-whitespace-regexp "\\\\(?:\\\\s-+\\\\)"
192 "*If non-nil, regular expression to match a sequence of whitespace chars.
193 This applies to Info search for regular expressions.
194 You might want to use something like \"[ \\t\\r\\n]+\" instead.
195 In the Customization buffer, that is `[' followed by a space,
196 a tab, a carriage return (control-M), a newline, and `]+'."
197 :type 'regexp
198 :group 'info)
200 (defcustom Info-mode-hook
201 ;; Try to obey obsolete Info-fontify settings.
202 (unless (and (boundp 'Info-fontify) (null Info-fontify))
203 '(turn-on-font-lock))
204 "Hooks run when `Info-mode' is called."
205 :type 'hook
206 :group 'info)
208 (defcustom Info-selection-hook nil
209 "Hooks run when `Info-select-node' is called."
210 :type 'hook
211 :group 'info)
213 (defvar Info-edit-mode-hook nil
214 "Hooks run when `Info-edit-mode' is called.")
216 (defvar Info-current-file nil
217 "Info file that Info is now looking at, or nil.
218 This is the name that was specified in Info, not the actual file name.
219 It doesn't contain directory names or file name extensions added by Info.
220 Can also be t when using `Info-on-current-buffer'.")
222 (defvar Info-current-subfile nil
223 "Info subfile that is actually in the *info* buffer now.
224 nil if current info file is not split into subfiles.")
226 (defvar Info-current-node nil
227 "Name of node that Info is now looking at, or nil.")
229 (defvar Info-tag-table-marker nil
230 "Marker pointing at beginning of current Info file's tag table.
231 Marker points nowhere if file has no tag table.")
233 (defvar Info-tag-table-buffer nil
234 "Buffer used for indirect tag tables.")
236 (defvar Info-current-file-completions nil
237 "Cached completion list for current Info file.")
239 (defvar Info-index-alternatives nil
240 "List of possible matches for last `Info-index' command.")
242 (defvar Info-point-loc nil
243 "Point location within a selected node.
244 If string, the point is moved to the proper occurrence of the
245 name of the followed cross reference within a selected node.
246 If number, the point is moved to the corresponding line.")
248 (defvar Info-standalone nil
249 "Non-nil if Emacs was started solely as an Info browser.")
251 (defvar Info-suffix-list
252 ;; The MS-DOS list should work both when long file names are
253 ;; supported (Windows 9X), and when only 8+3 file names are available.
254 (if (eq system-type 'ms-dos)
255 '( (".gz" . "gunzip")
256 (".z" . "gunzip")
257 (".bz2" . ("bzip2" "-dc"))
258 (".inz" . "gunzip")
259 (".igz" . "gunzip")
260 (".info.Z" . "gunzip")
261 (".info.gz" . "gunzip")
262 ("-info.Z" . "gunzip")
263 ("-info.gz" . "gunzip")
264 ("/index.gz". "gunzip")
265 ("/index.z" . "gunzip")
266 (".inf" . nil)
267 (".info" . nil)
268 ("-info" . nil)
269 ("/index" . nil)
270 ("" . nil))
271 '( (".info.Z". "uncompress")
272 (".info.Y". "unyabba")
273 (".info.gz". "gunzip")
274 (".info.z". "gunzip")
275 (".info.bz2" . ("bzip2" "-dc"))
276 (".info". nil)
277 ("-info.Z". "uncompress")
278 ("-info.Y". "unyabba")
279 ("-info.gz". "gunzip")
280 ("-info.bz2" . ("bzip2" "-dc"))
281 ("-info.z". "gunzip")
282 ("-info". nil)
283 ("/index.Z". "uncompress")
284 ("/index.Y". "unyabba")
285 ("/index.gz". "gunzip")
286 ("/index.z". "gunzip")
287 ("/index.bz2". ("bzip2" "-dc"))
288 ("/index". nil)
289 (".Z". "uncompress")
290 (".Y". "unyabba")
291 (".gz". "gunzip")
292 (".z". "gunzip")
293 (".bz2" . ("bzip2" "-dc"))
294 ("". nil)))
295 "List of file name suffixes and associated decoding commands.
296 Each entry should be (SUFFIX . STRING); the file is given to
297 the command as standard input.
299 STRING may be a list of strings. In that case, the first element is
300 the command name, and the rest are arguments to that command.
302 If STRING is nil, no decoding is done.
303 Because the SUFFIXes are tried in order, the empty string should
304 be last in the list.")
306 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
307 ;; First, on MS-DOS with no long file names support, delete some of
308 ;; the extension in FILENAME to make room.
309 (defun info-insert-file-contents-1 (filename suffix lfn)
310 (if lfn ; long file names are supported
311 (concat filename suffix)
312 (let* ((sans-exts (file-name-sans-extension filename))
313 ;; How long is the extension in FILENAME (not counting the dot).
314 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
315 ext-left)
316 ;; SUFFIX starts with a dot. If FILENAME already has one,
317 ;; get rid of the one in SUFFIX (unless suffix is empty).
318 (or (and (<= ext-len 0)
319 (not (eq (aref filename (1- (length filename))) ?.)))
320 (= (length suffix) 0)
321 (setq suffix (substring suffix 1)))
322 ;; How many chars of that extension should we keep?
323 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
324 ;; Get rid of the rest of the extension, and add SUFFIX.
325 (concat (substring filename 0 (- (length filename)
326 (- ext-len ext-left)))
327 suffix))))
329 (defun info-file-exists-p (filename)
330 (and (file-exists-p filename)
331 (not (file-directory-p filename))))
333 (defun info-insert-file-contents (filename &optional visit)
334 "Insert the contents of an info file in the current buffer.
335 Do the right thing if the file has been compressed or zipped."
336 (let* ((tail Info-suffix-list)
337 (lfn (if (fboundp 'msdos-long-file-names)
338 (msdos-long-file-names)
340 (check-short (and (fboundp 'msdos-long-file-names)
341 lfn))
342 fullname decoder done)
343 (if (info-file-exists-p filename)
344 ;; FILENAME exists--see if that name contains a suffix.
345 ;; If so, set DECODE accordingly.
346 (progn
347 (while (and tail
348 (not (string-match
349 (concat (regexp-quote (car (car tail))) "$")
350 filename)))
351 (setq tail (cdr tail)))
352 (setq fullname filename
353 decoder (cdr (car tail))))
354 ;; Try adding suffixes to FILENAME and see if we can find something.
355 (while (and tail (not done))
356 (setq fullname (info-insert-file-contents-1 filename
357 (car (car tail)) lfn))
358 (if (info-file-exists-p fullname)
359 (setq done t
360 ;; If we found a file with a suffix, set DECODER
361 ;; according to the suffix.
362 decoder (cdr (car tail)))
363 ;; When the MS-DOS port runs on Windows, we need to check
364 ;; the short variant of a long file name as well.
365 (when check-short
366 (setq fullname (info-insert-file-contents-1 filename
367 (car (car tail)) nil))
368 (if (info-file-exists-p fullname)
369 (setq done t
370 decoder (cdr (car tail))))))
371 (setq tail (cdr tail)))
372 (or tail
373 (error "Can't find %s or any compressed version of it" filename)))
374 ;; check for conflict with jka-compr
375 (if (and (featurep 'jka-compr)
376 (jka-compr-installed-p)
377 (jka-compr-get-compression-info fullname))
378 (setq decoder nil))
379 (if decoder
380 (progn
381 (insert-file-contents-literally fullname visit)
382 (let ((buffer-read-only nil)
383 (coding-system-for-write 'no-conversion)
384 (default-directory (or (file-name-directory fullname)
385 default-directory)))
386 (or (consp decoder)
387 (setq decoder (list decoder)))
388 (apply 'call-process-region (point-min) (point-max)
389 (car decoder) t t nil (cdr decoder))))
390 (insert-file-contents fullname visit))))
392 (defun Info-default-dirs ()
393 (let ((source (expand-file-name "info/" source-directory))
394 (sibling (if installation-directory
395 (expand-file-name "info/" installation-directory)
396 (if invocation-directory
397 (let ((infodir (expand-file-name
398 "../info/"
399 invocation-directory)))
400 (if (file-exists-p infodir)
401 infodir
402 (setq infodir (expand-file-name
403 "../../../info/"
404 invocation-directory))
405 (and (file-exists-p infodir)
406 infodir))))))
407 alternative)
408 (setq alternative
409 (if (and sibling (file-exists-p sibling))
410 ;; Uninstalled, Emacs builddir != srcdir.
411 sibling
412 ;; Uninstalled, builddir == srcdir
413 source))
414 (if (or (member alternative Info-default-directory-list)
415 ;; On DOS/NT, we use movable executables always,
416 ;; and we must always find the Info dir at run time.
417 (if (memq system-type '(ms-dos windows-nt))
419 ;; Use invocation-directory for Info
420 ;; only if we used it for exec-directory also.
421 (not (string= exec-directory
422 (expand-file-name "lib-src/"
423 installation-directory))))
424 (not (file-exists-p alternative)))
425 Info-default-directory-list
426 ;; `alternative' contains the Info files that came with this
427 ;; version, so we should look there first. `Info-insert-dir'
428 ;; currently expects to find `alternative' first on the list.
429 (cons alternative
430 ;; Don't drop the last part, it might contain non-Emacs stuff.
431 ;; (reverse (cdr (reverse
432 Info-default-directory-list)))) ;; )))
434 (defun info-initialize ()
435 "Initialize `Info-directory-list', if that hasn't been done yet."
436 (unless Info-directory-list
437 (let ((path (getenv "INFOPATH")))
438 (setq Info-directory-list
439 (prune-directory-list
440 (if path
441 (if (string-match ":\\'" path)
442 (append (split-string (substring path 0 -1)
443 (regexp-quote path-separator))
444 (Info-default-dirs))
445 (split-string path (regexp-quote path-separator)))
446 (Info-default-dirs)))))))
448 ;;;###autoload
449 (defun info-other-window (&optional file)
450 "Like `info' but show the Info buffer in another window."
451 (interactive (if current-prefix-arg
452 (list (read-file-name "Info file name: " nil nil t))))
453 (let (same-window-buffer-names same-window-regexps)
454 (info file)))
456 ;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
458 ;;;###autoload
459 (defun info (&optional file buffer)
460 "Enter Info, the documentation browser.
461 Optional argument FILE specifies the file to examine;
462 the default is the top-level directory of Info.
463 Called from a program, FILE may specify an Info node of the form
464 `(FILENAME)NODENAME'.
465 Optional argument BUFFER specifies the Info buffer name;
466 the default buffer name is *info*. If BUFFER exists,
467 just switch to BUFFER. Otherwise, create a new buffer
468 with the top-level Info directory.
470 In interactive use, a non-numeric prefix argument directs
471 this command to read a file name from the minibuffer.
472 A numeric prefix argument appends the number to the buffer name.
474 The search path for Info files is in the variable `Info-directory-list'.
475 The top-level Info directory is made by combining all the files named `dir'
476 in all the directories in that path."
477 (interactive (list
478 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
479 (read-file-name "Info file name: " nil nil t))
480 (if (numberp current-prefix-arg)
481 (format "*info*<%s>" current-prefix-arg))))
482 (pop-to-buffer (or buffer "*info*"))
483 (if (and buffer (not (eq major-mode 'Info-mode)))
484 (Info-mode))
485 (if file
486 ;; If argument already contains parentheses, don't add another set
487 ;; since the argument will then be parsed improperly. This also
488 ;; has the added benefit of allowing node names to be included
489 ;; following the parenthesized filename.
490 (if (and (stringp file) (string-match "(.*)" file))
491 (Info-goto-node file)
492 (Info-goto-node (concat "(" file ")")))
493 (if (zerop (buffer-size))
494 (Info-directory))))
496 ;;;###autoload
497 (defun info-emacs-manual ()
498 "Display the Emacs manual in Info mode."
499 (interactive)
500 (info "emacs"))
502 ;;;###autoload
503 (defun info-standalone ()
504 "Run Emacs as a standalone Info reader.
505 Usage: emacs -f info-standalone [filename]
506 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
507 (setq Info-standalone t)
508 (if (and command-line-args-left
509 (not (string-match "^-" (car command-line-args-left))))
510 (condition-case err
511 (progn
512 (info (car command-line-args-left))
513 (setq command-line-args-left (cdr command-line-args-left)))
514 (error (send-string-to-terminal
515 (format "%s\n" (if (eq (car-safe err) 'error)
516 (nth 1 err) err)))
517 (save-buffers-kill-emacs)))
518 (info)))
520 ;; See if the accessible portion of the buffer begins with a node
521 ;; delimiter, and the node header line which follows matches REGEXP.
522 ;; Typically, this test will be followed by a loop that examines the
523 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
524 ;; to have the overhead of this special test inside the loop.
526 ;; This function changes match-data, but supposedly the caller might
527 ;; want to use the results of re-search-backward.
529 ;; The return value is the value of point at the beginning of matching
530 ;; REGEXP, if the function succeeds, nil otherwise.
531 (defun Info-node-at-bob-matching (regexp)
532 (and (bobp) ; are we at beginning of buffer?
533 (looking-at "\^_") ; does it begin with node delimiter?
534 (let (beg)
535 (forward-line 1)
536 (setq beg (point))
537 (forward-line 1) ; does the line after delimiter match REGEXP?
538 (re-search-backward regexp beg t))))
540 (defun Info-find-file (filename &optional noerror)
541 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
542 Optional second argument NOERROR, if t, means if file is not found
543 just return nil (no error)."
544 ;; Convert filename to lower case if not found as specified.
545 ;; Expand it.
546 (if (stringp filename)
547 (let (temp temp-downcase found)
548 (setq filename (substitute-in-file-name filename))
549 (cond
550 ((string= (downcase filename) "dir")
551 (setq found t))
552 ((string= filename "apropos")
553 (setq found 'apropos))
554 ((string= filename "history")
555 (setq found 'history))
556 ((string= filename "toc")
557 (setq found 'toc))
559 (let ((dirs (if (string-match "^\\./" filename)
560 ;; If specified name starts with `./'
561 ;; then just try current directory.
562 '("./")
563 (if (file-name-absolute-p filename)
564 ;; No point in searching for an
565 ;; absolute file name
566 '(nil)
567 (if Info-additional-directory-list
568 (append Info-directory-list
569 Info-additional-directory-list)
570 Info-directory-list)))))
571 ;; Search the directory list for file FILENAME.
572 (while (and dirs (not found))
573 (setq temp (expand-file-name filename (car dirs)))
574 (setq temp-downcase
575 (expand-file-name (downcase filename) (car dirs)))
576 ;; Try several variants of specified name.
577 (let ((suffix-list Info-suffix-list)
578 (lfn (if (fboundp 'msdos-long-file-names)
579 (msdos-long-file-names)
580 t)))
581 (while (and suffix-list (not found))
582 (cond ((info-file-exists-p
583 (info-insert-file-contents-1
584 temp (car (car suffix-list)) lfn))
585 (setq found temp))
586 ((info-file-exists-p
587 (info-insert-file-contents-1
588 temp-downcase (car (car suffix-list)) lfn))
589 (setq found temp-downcase))
590 ((and (fboundp 'msdos-long-file-names)
592 (info-file-exists-p
593 (info-insert-file-contents-1
594 temp (car (car suffix-list)) nil)))
595 (setq found temp)))
596 (setq suffix-list (cdr suffix-list))))
597 (setq dirs (cdr dirs))))))
598 (if found
599 (setq filename found)
600 (if noerror
601 (setq filename nil)
602 (error "Info file %s does not exist" filename)))
603 filename)))
605 (defun Info-find-node (filename nodename &optional no-going-back)
606 "Go to an info node specified as separate FILENAME and NODENAME.
607 NO-GOING-BACK is non-nil if recovering from an error in this function;
608 it says do not attempt further (recursive) error recovery."
609 (info-initialize)
610 (setq filename (Info-find-file filename))
611 ;; Record the node we are leaving.
612 (if (and Info-current-file (not no-going-back))
613 (setq Info-history
614 (cons (list Info-current-file Info-current-node (point))
615 Info-history)))
616 ;; Go into info buffer.
617 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
618 (Info-find-node-2 filename nodename no-going-back))
620 (defun Info-on-current-buffer (&optional nodename)
621 "Use the `Info-mode' to browse the current info buffer.
622 If a prefix arg is provided, it queries for the NODENAME which
623 else defaults to \"Top\"."
624 (interactive
625 (list (if current-prefix-arg
626 (completing-read "Node name: " (Info-build-node-completions)
627 nil t "Top"))))
628 (unless nodename (setq nodename "Top"))
629 (info-initialize)
630 (Info-mode)
631 (set (make-local-variable 'Info-current-file) t)
632 (Info-find-node-2 nil nodename))
634 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
635 ;; but at least it keeps this routine (which is only for the benefit of
636 ;; makeinfo-buffer) out of the way of normal operations.
638 (defun Info-revert-find-node (filename nodename)
639 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
640 When *info* is already displaying FILENAME and NODENAME, the window position
641 is preserved, if possible."
642 (pop-to-buffer "*info*")
643 (let ((old-filename Info-current-file)
644 (old-nodename Info-current-node)
645 (pcolumn (current-column))
646 (pline (count-lines (point-min) (line-beginning-position)))
647 (wline (count-lines (point-min) (window-start)))
648 (old-history Info-history)
649 (new-history (and Info-current-file
650 (list Info-current-file Info-current-node (point)))))
651 (kill-buffer (current-buffer))
652 (Info-find-node filename nodename)
653 (setq Info-history old-history)
654 (if (and (equal old-filename Info-current-file)
655 (equal old-nodename Info-current-node))
656 (progn
657 ;; note goto-line is no good, we want to measure from point-min
658 (beginning-of-buffer)
659 (forward-line wline)
660 (set-window-start (selected-window) (point))
661 (beginning-of-buffer)
662 (forward-line pline)
663 (move-to-column pcolumn))
664 ;; only add to the history when coming from a different file+node
665 (if new-history
666 (setq Info-history (cons new-history Info-history))))))
668 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
669 "Find a node in a tag table.
670 MARKER specifies the buffer and position to start searching at.
671 REGEXP is a regular expression matching nodes or references. Its first
672 group should match `Node:' or `Ref:'.
673 CASE-FOLD t means search for a case-insensitive match.
674 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
675 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
676 where the match was found, and MODE is `major-mode' of the buffer in
677 which the match was found."
678 (let ((case-fold-search case-fold))
679 (save-excursion
680 (set-buffer (marker-buffer marker))
681 (goto-char marker)
683 ;; Search tag table
684 (beginning-of-line)
685 (when (re-search-forward regexp nil t)
686 (list (string-equal "Ref:" (match-string 1))
687 (+ (point-min) (read (current-buffer)))
688 major-mode)))))
690 (defun Info-find-in-tag-table (marker regexp)
691 "Find a node in a tag table.
692 MARKER specifies the buffer and position to start searching at.
693 REGEXP is a regular expression matching nodes or references. Its first
694 group should match `Node:' or `Ref:'.
695 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
696 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
697 where the match was found, and MODE is `major-mode' of the buffer in
698 which the match was found.
699 This function tries to find a case-sensitive match first, then a
700 case-insensitive match is tried."
701 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
702 (when (null (car result))
703 (setq result (Info-find-in-tag-table-1 marker regexp t)))
704 result))
706 (defun Info-find-node-in-buffer-1 (regexp case-fold)
707 "Find a node or anchor in the current buffer.
708 REGEXP is a regular expression matching nodes or references. Its first
709 group should match `Node:' or `Ref:'.
710 CASE-FOLD t means search for a case-insensitive match.
711 Value is the position at which a match was found, or nil if not found."
712 (let ((case-fold-search case-fold)
713 found)
714 (save-excursion
715 (when (Info-node-at-bob-matching regexp)
716 (setq found (point)))
717 (while (and (not found)
718 (search-forward "\n\^_" nil t))
719 (forward-line 1)
720 (let ((beg (point)))
721 (forward-line 1)
722 (when (re-search-backward regexp beg t)
723 (beginning-of-line)
724 (setq found (point)))))
725 found)))
727 (defun Info-find-node-in-buffer (regexp)
728 "Find a node or anchor in the current buffer.
729 REGEXP is a regular expression matching nodes or references. Its first
730 group should match `Node:' or `Ref:'.
731 Value is the position at which a match was found, or nil if not found.
732 This function looks for a case-sensitive match first. If none is found,
733 a case-insensitive match is tried."
734 (or (Info-find-node-in-buffer-1 regexp nil)
735 (Info-find-node-in-buffer-1 regexp t)))
737 (defun Info-find-node-2 (filename nodename &optional no-going-back)
738 (buffer-disable-undo (current-buffer))
739 (or (eq major-mode 'Info-mode)
740 (Info-mode))
741 (widen)
742 (setq Info-current-node nil)
743 (unwind-protect
744 (let ((case-fold-search t)
745 anchorpos)
746 ;; Switch files if necessary
747 (or (null filename)
748 (equal Info-current-file filename)
749 (let ((buffer-read-only nil))
750 (setq Info-current-file nil
751 Info-current-subfile nil
752 Info-current-file-completions nil
753 buffer-file-name nil)
754 (erase-buffer)
755 (cond
756 ((eq filename t)
757 (Info-insert-dir))
758 ((eq filename 'apropos)
759 (insert-buffer-substring " *info-apropos*"))
760 ((eq filename 'history)
761 (insert-buffer-substring " *info-history*"))
762 ((eq filename 'toc)
763 (insert-buffer-substring " *info-toc*"))
765 (info-insert-file-contents filename nil)
766 (setq default-directory (file-name-directory filename))))
767 (set-buffer-modified-p nil)
768 ;; See whether file has a tag table. Record the location if yes.
769 (goto-char (point-max))
770 (forward-line -8)
771 ;; Use string-equal, not equal, to ignore text props.
772 (if (not (or (string-equal nodename "*")
773 (not
774 (search-forward "\^_\nEnd tag table\n" nil t))))
775 (let (pos)
776 ;; We have a tag table. Find its beginning.
777 ;; Is this an indirect file?
778 (search-backward "\nTag table:\n")
779 (setq pos (point))
780 (if (save-excursion
781 (forward-line 2)
782 (looking-at "(Indirect)\n"))
783 ;; It is indirect. Copy it to another buffer
784 ;; and record that the tag table is in that buffer.
785 (let ((buf (current-buffer))
786 (tagbuf
787 (or Info-tag-table-buffer
788 (generate-new-buffer " *info tag table*"))))
789 (setq Info-tag-table-buffer tagbuf)
790 (save-excursion
791 (set-buffer tagbuf)
792 (buffer-disable-undo (current-buffer))
793 (setq case-fold-search t)
794 (erase-buffer)
795 (insert-buffer-substring buf))
796 (set-marker Info-tag-table-marker
797 (match-end 0) tagbuf))
798 (set-marker Info-tag-table-marker pos)))
799 (set-marker Info-tag-table-marker nil))
800 (setq Info-current-file
801 (cond
802 ((eq filename t) "dir")
803 ((eq filename 'apropos) "apropos")
804 ((eq filename 'history) "history")
805 ((eq filename 'toc) "toc")
806 (t filename)))
808 ;; Use string-equal, not equal, to ignore text props.
809 (if (string-equal nodename "*")
810 (progn (setq Info-current-node nodename)
811 (Info-set-mode-line))
812 ;; Possibilities:
814 ;; 1. Anchor found in tag table
815 ;; 2. Anchor *not* in tag table
817 ;; 3. Node found in tag table
818 ;; 4. Node *not* found in tag table, but found in file
819 ;; 5. Node *not* in tag table, and *not* in file
821 ;; *Or* the same, but in an indirect subfile.
823 ;; Search file for a suitable node.
824 (let ((guesspos (point-min))
825 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
826 (if (stringp nodename)
827 (regexp-quote nodename)
829 "\\) *[,\t\n\177]")))
831 (catch 'foo
833 ;; First, search a tag table, if any
834 (when (marker-position Info-tag-table-marker)
835 (let* ((m Info-tag-table-marker)
836 (found (Info-find-in-tag-table m regexp)))
838 (when found
839 ;; FOUND is (ANCHOR POS MODE).
840 (setq guesspos (nth 1 found))
842 ;; If this is an indirect file, determine which
843 ;; file really holds this node and read it in.
844 (unless (eq (nth 2 found) 'Info-mode)
845 ;; Note that the current buffer must be the
846 ;; *info* buffer on entry to
847 ;; Info-read-subfile. Thus the hackery above.
848 (setq guesspos (Info-read-subfile guesspos)))
850 ;; Handle anchor
851 (when (nth 0 found)
852 (goto-char (setq anchorpos guesspos))
853 (throw 'foo t)))))
855 ;; Else we may have a node, which we search for:
856 (goto-char (max (point-min)
857 (- (byte-to-position guesspos) 1000)))
859 ;; Now search from our advised position (or from beg of
860 ;; buffer) to find the actual node. First, check
861 ;; whether the node is right where we are, in case the
862 ;; buffer begins with a node.
863 (let ((pos (Info-find-node-in-buffer regexp)))
864 (when pos
865 (goto-char pos)
866 (throw 'foo t))
867 ;; No such anchor in tag table or node in tag table or file
868 (error "No such node or anchor: %s" nodename)))
870 (Info-select-node)
871 (goto-char (point-min))
872 (cond (anchorpos
873 (let ((new-history (list Info-current-file
874 (substring-no-properties nodename))))
875 ;; Add anchors to the history too
876 (setq Info-history-list
877 (cons new-history
878 (delete new-history Info-history-list))))
879 (goto-char anchorpos))
880 ((numberp Info-point-loc)
881 (forward-line (1- Info-point-loc))
882 (setq Info-point-loc nil))
883 ((stringp Info-point-loc)
884 (Info-find-index-name Info-point-loc)
885 (setq Info-point-loc nil))))))
886 ;; If we did not finish finding the specified node,
887 ;; go back to the previous one.
888 (or Info-current-node no-going-back (null Info-history)
889 (let ((hist (car Info-history)))
890 (setq Info-history (cdr Info-history))
891 (Info-find-node (nth 0 hist) (nth 1 hist) t)
892 (goto-char (nth 2 hist))))))
894 ;; Cache the contents of the (virtual) dir file, once we have merged
895 ;; it for the first time, so we can save time subsequently.
896 (defvar Info-dir-contents nil)
898 ;; Cache for the directory we decided to use for the default-directory
899 ;; of the merged dir text.
900 (defvar Info-dir-contents-directory nil)
902 ;; Record the file attributes of all the files from which we
903 ;; constructed Info-dir-contents.
904 (defvar Info-dir-file-attributes nil)
906 (defvar Info-dir-file-name nil)
908 ;; Construct the Info directory node by merging the files named `dir'
909 ;; from various directories. Set the *info* buffer's
910 ;; default-directory to the first directory we actually get any text
911 ;; from.
912 (defun Info-insert-dir ()
913 (if (and Info-dir-contents Info-dir-file-attributes
914 ;; Verify that none of the files we used has changed
915 ;; since we used it.
916 (eval (cons 'and
917 (mapcar (lambda (elt)
918 (let ((curr (file-attributes
919 ;; Handle symlinks
920 (file-truename (car elt)))))
922 ;; Don't compare the access time.
923 (if curr (setcar (nthcdr 4 curr) 0))
924 (setcar (nthcdr 4 (cdr elt)) 0)
925 (equal (cdr elt) curr)))
926 Info-dir-file-attributes))))
927 (progn
928 (insert Info-dir-contents)
929 (goto-char (point-min)))
930 (let ((dirs (if Info-additional-directory-list
931 (append Info-directory-list
932 Info-additional-directory-list)
933 Info-directory-list))
934 (dir-file-attrs nil)
935 ;; Bind this in case the user sets it to nil.
936 (case-fold-search t)
937 ;; This is set non-nil if we find a problem in some input files.
938 problems
939 buffers buffer others nodes dirs-done)
941 ;; Search the directory list for the directory file.
942 (while dirs
943 (let ((truename (file-truename (expand-file-name (car dirs)))))
944 (or (member truename dirs-done)
945 (member (directory-file-name truename) dirs-done)
946 ;; Try several variants of specified name.
947 ;; Try upcasing, appending `.info', or both.
948 (let* (file
949 (attrs
951 (progn (setq file (expand-file-name "dir" truename))
952 (file-attributes file))
953 (progn (setq file (expand-file-name "DIR" truename))
954 (file-attributes file))
955 (progn (setq file (expand-file-name "dir.info" truename))
956 (file-attributes file))
957 (progn (setq file (expand-file-name "DIR.INFO" truename))
958 (file-attributes file)))))
959 (setq dirs-done
960 (cons truename
961 (cons (directory-file-name truename)
962 dirs-done)))
963 (if attrs
964 (save-excursion
965 (or buffers
966 (message "Composing main Info directory..."))
967 (set-buffer (generate-new-buffer " info dir"))
968 (condition-case nil
969 (progn
970 (insert-file-contents file)
971 (set (make-local-variable 'Info-dir-file-name)
972 file)
973 (push (current-buffer) buffers)
974 (push (cons file attrs) dir-file-attrs))
975 (error (kill-buffer (current-buffer))))))))
976 (unless (cdr dirs)
977 (set (make-local-variable 'Info-dir-contents-directory)
978 (file-name-as-directory (car dirs))))
979 (setq dirs (cdr dirs))))
981 (or buffers
982 (error "Can't find the Info directory node"))
984 ;; Distinguish the dir file that comes with Emacs from all the
985 ;; others. Yes, that is really what this is supposed to do.
986 ;; The definition of `Info-directory-list' puts it first on that
987 ;; list and so last in `buffers' at this point.
988 (setq buffer (car (last buffers))
989 others (delq buffer buffers))
991 ;; Insert the entire original dir file as a start; note that we've
992 ;; already saved its default directory to use as the default
993 ;; directory for the whole concatenation.
994 (insert-buffer buffer)
996 ;; Look at each of the other buffers one by one.
997 (dolist (other others)
998 (let (this-buffer-nodes)
999 ;; In each, find all the menus.
1000 (with-current-buffer other
1001 (goto-char (point-min))
1002 ;; Find each menu, and add an elt to NODES for it.
1003 (while (re-search-forward "^\\* Menu:" nil t)
1004 (while (and (zerop (forward-line 1)) (eolp)))
1005 (let ((beg (point))
1006 nodename end)
1007 (re-search-backward "^\^_")
1008 (search-forward "Node: ")
1009 (setq nodename (Info-following-node-name))
1010 (search-forward "\n\^_" nil 'move)
1011 (beginning-of-line)
1012 (setq end (point))
1013 (push (list nodename other beg end) this-buffer-nodes)))
1014 (if (assoc-string "top" this-buffer-nodes t)
1015 (setq nodes (nconc this-buffer-nodes nodes))
1016 (setq problems t)
1017 (message "No `top' node in %s" Info-dir-file-name)))))
1018 ;; Add to the main menu a menu item for each other node.
1019 (re-search-forward "^\\* Menu:")
1020 (forward-line 1)
1021 (let ((menu-items '("top"))
1022 (end (save-excursion (search-forward "\^_" nil t) (point))))
1023 (dolist (node nodes)
1024 (let ((nodename (car node)))
1025 (save-excursion
1026 (or (member (downcase nodename) menu-items)
1027 (re-search-forward (concat "^\\* +"
1028 (regexp-quote nodename)
1029 "::")
1030 end t)
1031 (progn
1032 (insert "* " nodename "::" "\n")
1033 (push nodename menu-items)))))))
1034 ;; Now take each node of each of the other buffers
1035 ;; and merge it into the main buffer.
1036 (dolist (node nodes)
1037 (let ((case-fold-search t)
1038 (nodename (car node)))
1039 (goto-char (point-min))
1040 ;; Find the like-named node in the main buffer.
1041 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1042 (regexp-quote nodename)
1043 "[,\n\t]")
1044 nil t)
1045 (progn
1046 (search-forward "\n\^_" nil 'move)
1047 (beginning-of-line)
1048 (insert "\n"))
1049 ;; If none exists, add one.
1050 (goto-char (point-max))
1051 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1052 ;; Merge the text from the other buffer's menu
1053 ;; into the menu in the like-named node in the main buffer.
1054 (apply 'insert-buffer-substring (cdr node))))
1055 (Info-dir-remove-duplicates)
1056 ;; Kill all the buffers we just made.
1057 (mapc 'kill-buffer buffers)
1058 (goto-char (point-min))
1059 (if problems
1060 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1061 (message "Composing main Info directory...done"))
1062 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1063 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1064 (setq default-directory Info-dir-contents-directory))
1066 (defvar Info-streamline-headings
1067 '(("Emacs" . "Emacs")
1068 ("Programming" . "Programming")
1069 ("Libraries" . "Libraries")
1070 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1071 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1073 (defun Info-dir-remove-duplicates ()
1074 (let (limit)
1075 (goto-char (point-min))
1076 ;; Remove duplicate headings in the same menu.
1077 (while (search-forward "\n* Menu:" nil t)
1078 (setq limit (save-excursion (search-forward "\n\x1f" nil t)))
1079 ;; Look for the next heading to unify.
1080 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1081 (let ((name (match-string 1))
1082 (start (match-beginning 0))
1083 (entries nil) re)
1084 ;; Check whether this heading should be streamlined.
1085 (save-match-data
1086 (dolist (x Info-streamline-headings)
1087 (when (string-match (car x) name)
1088 (setq name (cdr x))
1089 (setq re (car x)))))
1090 (if re (replace-match name t t nil 1))
1091 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1092 (match-beginning 0)
1093 (or limit (point-max))))
1094 ;; Look for other headings of the same category and merge them.
1095 (save-excursion
1096 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1097 (when (if re (save-match-data (string-match re (match-string 1)))
1098 (equal name (match-string 1)))
1099 (forward-line 0)
1100 ;; Delete redundant heading.
1101 (delete-region (match-beginning 0) (point))
1102 ;; Push the entries onto `text'.
1103 (push
1104 (delete-and-extract-region
1105 (point)
1106 (if (re-search-forward "^[^* \n\t]" nil t)
1107 (match-beginning 0)
1108 (or limit (point-max)))) entries))))
1109 ;; Insert the entries just found.
1110 (while (= (line-beginning-position 0) (1- (point)))
1111 (backward-char))
1112 (dolist (entry (nreverse entries))
1113 (insert entry)
1114 (while (= (line-beginning-position 0) (1- (point)))
1115 (delete-region (1- (point)) (point))))
1117 ;; Now remove duplicate entries under the same heading.
1118 (let ((seen nil)
1119 (limit (point)))
1120 (goto-char start)
1121 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1122 limit 'move)
1123 (let ((x (match-string 1)))
1124 (if (member-ignore-case x seen)
1125 (delete-region (match-beginning 0)
1126 (progn (re-search-forward "^[^ \t]" nil t)
1127 (match-beginning 0)))
1128 (push x seen))))))))))
1130 ;; Note that on entry to this function the current-buffer must be the
1131 ;; *info* buffer; not the info tags buffer.
1132 (defun Info-read-subfile (nodepos)
1133 ;; NODEPOS is either a position (in the Info file as a whole,
1134 ;; not relative to a subfile) or the name of a subfile.
1135 (let (lastfilepos
1136 lastfilename)
1137 (if (numberp nodepos)
1138 (save-excursion
1139 (set-buffer (marker-buffer Info-tag-table-marker))
1140 (goto-char (point-min))
1141 (or (looking-at "\^_")
1142 (search-forward "\n\^_"))
1143 (forward-line 2)
1144 (catch 'foo
1145 (while (not (looking-at "\^_"))
1146 (if (not (eolp))
1147 (let ((beg (point))
1148 thisfilepos thisfilename)
1149 (search-forward ": ")
1150 (setq thisfilename (buffer-substring beg (- (point) 2)))
1151 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1152 ;; read in version 19 stops at the end of number.
1153 ;; Advance to the next line.
1154 (forward-line 1)
1155 (if (> thisfilepos nodepos)
1156 (throw 'foo t))
1157 (setq lastfilename thisfilename)
1158 (setq lastfilepos thisfilepos))
1159 (forward-line 1)))))
1160 (setq lastfilename nodepos)
1161 (setq lastfilepos 0))
1162 ;; Assume previous buffer is in Info-mode.
1163 ;; (set-buffer (get-buffer "*info*"))
1164 (or (equal Info-current-subfile lastfilename)
1165 (let ((buffer-read-only nil))
1166 (setq buffer-file-name nil)
1167 (widen)
1168 (erase-buffer)
1169 (info-insert-file-contents lastfilename)
1170 (set-buffer-modified-p nil)
1171 (setq Info-current-subfile lastfilename)))
1172 ;; Widen in case we are in the same subfile as before.
1173 (widen)
1174 (goto-char (point-min))
1175 (if (looking-at "\^_")
1176 (forward-char 1)
1177 (search-forward "\n\^_"))
1178 (if (numberp nodepos)
1179 (+ (- nodepos lastfilepos) (point)))))
1181 (defun Info-unescape-quotes (value)
1182 "Unescape double quotes and backslashes in VALUE."
1183 (let ((start 0)
1184 (unquote value))
1185 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1186 (setq unquote (replace-match "" t t unquote 1))
1187 (setq start (- (match-end 0) 1)))
1188 unquote))
1190 ;; As of Texinfo 4.6, makeinfo writes constructs like
1191 ;; \0\h[image param=value ...\h\0]
1192 ;; into the Info file for handling images.
1193 (defun Info-split-parameter-string (parameter-string)
1194 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1195 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1196 whitespace or double quotes, it must be quoted in double quotes and
1197 any double quotes or backslashes must be escaped (\\\",\\\\)."
1198 (let ((start 0)
1199 (parameter-alist))
1200 (while (string-match
1201 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1202 parameter-string start)
1203 (setq start (match-end 0))
1204 (push (cons (match-string 1 parameter-string)
1205 (or (match-string 2 parameter-string)
1206 (Info-unescape-quotes
1207 (match-string 3 parameter-string))))
1208 parameter-alist))
1209 parameter-alist))
1211 (defun Info-display-images-node ()
1212 "Display images in current node."
1213 (save-excursion
1214 (let ((inhibit-read-only t)
1215 (case-fold-search t))
1216 (goto-char (point-min))
1217 (while (re-search-forward
1218 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1219 nil t)
1220 (let* ((start (match-beginning 1))
1221 (parameter-alist (Info-split-parameter-string (match-string 2)))
1222 (src (cdr (assoc-string "src" parameter-alist)))
1223 (image-file (if src (if (file-name-absolute-p src) src
1224 (concat default-directory src))
1225 ""))
1226 (image (if (file-exists-p image-file)
1227 (create-image image-file)
1228 "[broken image]")))
1229 (if (not (get-text-property start 'display))
1230 (add-text-properties
1231 start (point) `(display ,image rear-nonsticky (display)))))))
1232 (set-buffer-modified-p nil)))
1234 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1235 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1236 ;; including one optional trailing newline.
1237 (defun Info-hide-cookies-node ()
1238 "Hide unrecognised cookies in current node."
1239 (save-excursion
1240 (let ((inhibit-read-only t)
1241 (case-fold-search t))
1242 (goto-char (point-min))
1243 (while (re-search-forward
1244 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1245 nil t)
1246 (let* ((start (match-beginning 1)))
1247 (if (not (get-text-property start 'invisible))
1248 (put-text-property start (point) 'invisible t)))))
1249 (set-buffer-modified-p nil)))
1251 (defun Info-select-node ()
1252 "Select the info node that point is in."
1253 ;; Bind this in case the user sets it to nil.
1254 (let ((case-fold-search t))
1255 (save-excursion
1256 ;; Find beginning of node.
1257 (if (search-backward "\n\^_" nil 'move)
1258 (forward-line 2)
1259 (if (looking-at "\^_")
1260 (forward-line 1)
1261 (signal 'search-failed (list "\n\^_"))))
1262 ;; Get nodename spelled as it is in the node.
1263 (re-search-forward "Node:[ \t]*")
1264 (setq Info-current-node
1265 (buffer-substring-no-properties (point)
1266 (progn
1267 (skip-chars-forward "^,\t\n")
1268 (point))))
1269 (Info-set-mode-line)
1270 ;; Find the end of it, and narrow.
1271 (beginning-of-line)
1272 (let (active-expression)
1273 ;; Narrow to the node contents
1274 (narrow-to-region (point)
1275 (if (re-search-forward "\n[\^_\f]" nil t)
1276 (prog1
1277 (1- (point))
1278 (if (looking-at "[\n\^_\f]*execute: ")
1279 (progn
1280 (goto-char (match-end 0))
1281 (setq active-expression
1282 (read (current-buffer))))))
1283 (point-max)))
1284 (if Info-enable-active-nodes (eval active-expression))
1285 ;; Add a new unique history item to full history list
1286 (let ((new-history (list Info-current-file Info-current-node)))
1287 (setq Info-history-list
1288 (cons new-history (delete new-history Info-history-list))))
1289 (Info-fontify-node)
1290 (Info-display-images-node)
1291 (Info-hide-cookies-node)
1292 (run-hooks 'Info-selection-hook)))))
1294 (defun Info-set-mode-line ()
1295 (setq mode-line-buffer-identification
1296 (nconc (propertized-buffer-identification "%b")
1297 (list
1298 (concat " ("
1299 (file-name-nondirectory
1300 (if (stringp Info-current-file)
1301 Info-current-file
1302 (or buffer-file-name "")))
1303 ") "
1304 (or Info-current-node ""))))))
1306 ;; Go to an info node specified with a filename-and-nodename string
1307 ;; of the sort that is found in pointers in nodes.
1309 (defun Info-goto-node (nodename &optional fork)
1310 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1311 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1312 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1313 its sub-files).
1314 Completion is available, but only for node names in the current Info file.
1315 If FORK is non-nil (interactively with a prefix arg), show the node in
1316 a new info buffer.
1317 If FORK is a string, it is the name to use for the new buffer."
1318 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1319 (info-initialize)
1320 (if fork
1321 (set-buffer
1322 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1323 (let (filename)
1324 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1325 nodename)
1326 (setq filename (if (= (match-beginning 1) (match-end 1))
1328 (match-string 2 nodename))
1329 nodename (match-string 3 nodename))
1330 (let ((trim (string-match "\\s +\\'" filename)))
1331 (if trim (setq filename (substring filename 0 trim))))
1332 (let ((trim (string-match "\\s +\\'" nodename)))
1333 (if trim (setq nodename (substring nodename 0 trim))))
1334 (if transient-mark-mode (deactivate-mark))
1335 (Info-find-node (if (equal filename "") nil filename)
1336 (if (equal nodename "") "Top" nodename))))
1338 (defvar Info-read-node-completion-table)
1340 ;; This function is used as the "completion table" while reading a node name.
1341 ;; It does completion using the alist in Info-read-node-completion-table
1342 ;; unless STRING starts with an open-paren.
1343 (defun Info-read-node-name-1 (string predicate code)
1344 (cond
1345 ;; First complete embedded file names.
1346 ((string-match "\\`([^)]*\\'" string)
1347 (let ((file (substring string 1)))
1348 (cond
1349 ((eq code nil)
1350 (let ((comp (try-completion file 'locate-file-completion
1351 (cons Info-directory-list
1352 (mapcar 'car Info-suffix-list)))))
1353 (cond
1354 ((eq comp t) (concat string ")"))
1355 (comp (concat "(" comp)))))
1356 ((eq code t) (all-completions file 'locate-file-completion
1357 (cons Info-directory-list
1358 (mapcar 'car Info-suffix-list))))
1359 (t nil))))
1360 ;; If a file name was given, then any node is fair game.
1361 ((string-match "\\`(" string)
1362 (cond
1363 ((eq code nil) string)
1364 ((eq code t) nil)
1365 (t t)))
1366 ;; Otherwise use Info-read-node-completion-table.
1367 ((eq code nil)
1368 (try-completion string Info-read-node-completion-table predicate))
1369 ((eq code t)
1370 (all-completions string Info-read-node-completion-table predicate))
1372 (test-completion string Info-read-node-completion-table predicate))))
1374 (defun Info-read-node-name (prompt &optional default)
1375 (let* ((completion-ignore-case t)
1376 (Info-read-node-completion-table (Info-build-node-completions))
1377 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1378 (if (equal nodename "")
1379 (or default
1380 (Info-read-node-name prompt))
1381 nodename)))
1383 (defun Info-build-node-completions ()
1384 (or Info-current-file-completions
1385 (let ((compl nil)
1386 ;; Bind this in case the user sets it to nil.
1387 (case-fold-search t)
1388 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1389 (save-excursion
1390 (save-restriction
1391 (if (marker-buffer Info-tag-table-marker)
1392 (let ((marker Info-tag-table-marker))
1393 (set-buffer (marker-buffer marker))
1394 (widen)
1395 (goto-char marker)
1396 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1397 (setq compl
1398 (cons (list (match-string-no-properties 2))
1399 compl))))
1400 (widen)
1401 (goto-char (point-min))
1402 ;; If the buffer begins with a node header, process that first.
1403 (if (Info-node-at-bob-matching node-regexp)
1404 (setq compl (list (match-string-no-properties 1))))
1405 ;; Now for the rest of the nodes.
1406 (while (search-forward "\n\^_" nil t)
1407 (forward-line 1)
1408 (let ((beg (point)))
1409 (forward-line 1)
1410 (if (re-search-backward node-regexp beg t)
1411 (setq compl
1412 (cons (list (match-string-no-properties 1))
1413 compl))))))))
1414 (setq compl (cons '("*") compl))
1415 (set (make-local-variable 'Info-current-file-completions) compl))))
1417 (defun Info-restore-point (hl)
1418 "If this node has been visited, restore the point value when we left."
1419 (while hl
1420 (if (and (equal (nth 0 (car hl)) Info-current-file)
1421 ;; Use string-equal, not equal, to ignore text props.
1422 (string-equal (nth 1 (car hl)) Info-current-node))
1423 (progn
1424 (goto-char (nth 2 (car hl)))
1425 (setq hl nil)) ;terminate the while at next iter
1426 (setq hl (cdr hl)))))
1428 (defvar Info-search-history nil
1429 "The history list for `Info-search'.")
1431 (defvar Info-search-case-fold nil
1432 "The value of `case-fold-search' from previous `Info-search' command.")
1434 (defun Info-search (regexp)
1435 "Search for REGEXP, starting from point, and select node it's found in."
1436 (interactive (list (read-string
1437 (if Info-search-history
1438 (format "Regexp search%s (default `%s'): "
1439 (if case-fold-search "" " case-sensitively")
1440 (car Info-search-history))
1441 (format "Regexp search%s: "
1442 (if case-fold-search "" " case-sensitively")))
1443 nil 'Info-search-history)))
1444 (when transient-mark-mode
1445 (deactivate-mark))
1446 (when (equal regexp "")
1447 (setq regexp (car Info-search-history)))
1448 (when regexp
1449 (let (found beg-found give-up
1450 (onode Info-current-node)
1451 (ofile Info-current-file)
1452 (opoint (point))
1453 (ostart (window-start))
1454 (osubfile Info-current-subfile))
1455 (when Info-search-whitespace-regexp
1456 (setq regexp (replace-regexp-in-string
1457 "[ \t\n]+" Info-search-whitespace-regexp regexp)))
1458 (setq Info-search-case-fold case-fold-search)
1459 (save-excursion
1460 (save-restriction
1461 (widen)
1462 (while (and (not give-up)
1463 (or (null found)
1464 (isearch-range-invisible beg-found found)))
1465 (if (re-search-forward regexp nil t)
1466 (setq found (point) beg-found (match-beginning 0))
1467 (setq give-up t)))))
1468 ;; If no subfiles, give error now.
1469 (if give-up
1470 (if (null Info-current-subfile)
1471 (re-search-forward regexp)
1472 (setq found nil)))
1474 (unless found
1475 (unwind-protect
1476 ;; Try other subfiles.
1477 (let ((list ()))
1478 (save-excursion
1479 (set-buffer (marker-buffer Info-tag-table-marker))
1480 (goto-char (point-min))
1481 (search-forward "\n\^_\nIndirect:")
1482 (save-restriction
1483 (narrow-to-region (point)
1484 (progn (search-forward "\n\^_")
1485 (1- (point))))
1486 (goto-char (point-min))
1487 ;; Find the subfile we just searched.
1488 (search-forward (concat "\n" osubfile ": "))
1489 ;; Skip that one.
1490 (forward-line 1)
1491 ;; Make a list of all following subfiles.
1492 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1493 (while (not (eobp))
1494 (re-search-forward "\\(^.*\\): [0-9]+$")
1495 (goto-char (+ (match-end 1) 2))
1496 (setq list (cons (cons (+ (point-min)
1497 (read (current-buffer)))
1498 (match-string-no-properties 1))
1499 list))
1500 (goto-char (1+ (match-end 0))))
1501 ;; Put in forward order
1502 (setq list (nreverse list))))
1503 (while list
1504 (message "Searching subfile %s..." (cdr (car list)))
1505 (Info-read-subfile (car (car list)))
1506 (setq list (cdr list))
1507 (setq give-up nil found nil)
1508 (while (and (not give-up)
1509 (or (null found)
1510 (isearch-range-invisible beg-found found)))
1511 (if (re-search-forward regexp nil t)
1512 (setq found (point) beg-found (match-beginning 0))
1513 (setq give-up t)))
1514 (if give-up
1515 (setq found nil))
1516 (if found
1517 (setq list nil)))
1518 (if found
1519 (message "")
1520 (signal 'search-failed (list regexp))))
1521 (if (not found)
1522 (progn (Info-read-subfile osubfile)
1523 (goto-char opoint)
1524 (Info-select-node)
1525 (set-window-start (selected-window) ostart)))))
1526 (widen)
1527 (goto-char found)
1528 (Info-select-node)
1529 ;; Use string-equal, not equal, to ignore text props.
1530 (or (and (string-equal onode Info-current-node)
1531 (equal ofile Info-current-file))
1532 (setq Info-history (cons (list ofile onode opoint)
1533 Info-history))))))
1535 (defun Info-search-case-sensitively ()
1536 "Search for a regexp case-sensitively."
1537 (interactive)
1538 (let ((case-fold-search nil))
1539 (call-interactively 'Info-search)))
1541 (defun Info-search-next ()
1542 "Search for next regexp from a previous `Info-search' command."
1543 (interactive)
1544 (let ((case-fold-search Info-search-case-fold))
1545 (if Info-search-history
1546 (Info-search (car Info-search-history))
1547 (call-interactively 'Info-search))))
1549 (defun Info-extract-pointer (name &optional errorname)
1550 "Extract the value of the node-pointer named NAME.
1551 If there is none, use ERRORNAME in the error message;
1552 if ERRORNAME is nil, just return nil."
1553 ;; Bind this in case the user sets it to nil.
1554 (let ((case-fold-search t))
1555 (save-excursion
1556 (goto-char (point-min))
1557 (let ((bound (point)))
1558 (forward-line 1)
1559 (cond ((re-search-backward
1560 (concat name ":" (Info-following-node-name-re)) bound t)
1561 (match-string 1))
1562 ((not (eq errorname t))
1563 (error "Node has no %s"
1564 (capitalize (or errorname name)))))))))
1566 (defun Info-following-node-name-re (&optional allowedchars)
1567 "Return a regexp matching a node name.
1568 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1569 saying which chars may appear in the node name.
1570 Submatch 1 is the complete node name.
1571 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1572 Submatch 3 is the local part of the node name.
1573 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1574 (concat "[ \t]*" ;Skip leading space.
1575 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1576 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1577 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1578 "\\|\\)\\)")) ;Allow empty node names.
1580 ;;; For compatibility; other files have used this name.
1581 (defun Info-following-node-name ()
1582 (and (looking-at (Info-following-node-name-re))
1583 (match-string 1)))
1585 (defun Info-next ()
1586 "Go to the next node of this node."
1587 (interactive)
1588 (Info-goto-node (Info-extract-pointer "next")))
1590 (defun Info-prev ()
1591 "Go to the previous node of this node."
1592 (interactive)
1593 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1595 (defun Info-up (&optional same-file)
1596 "Go to the superior node of this node.
1597 If SAME-FILE is non-nil, do not move to a different Info file."
1598 (interactive)
1599 (let ((old-node Info-current-node)
1600 (old-file Info-current-file)
1601 (node (Info-extract-pointer "up")) p)
1602 (and (or same-file (not (stringp Info-current-file)))
1603 (string-match "^(" node)
1604 (error "Up node is in another Info file"))
1605 (Info-goto-node node)
1606 (setq p (point))
1607 (goto-char (point-min))
1608 (if (and (search-forward "\n* Menu:" nil t)
1609 (re-search-forward
1610 (if (string-equal old-node "Top")
1611 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
1612 (concat "\n\\* +\\(" (regexp-quote old-node)
1613 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
1614 nil t))
1615 (beginning-of-line)
1616 (goto-char p)
1617 (Info-restore-point Info-history))))
1619 (defun Info-last ()
1620 "Go back to the last node visited."
1621 (interactive)
1622 (or Info-history
1623 (error "This is the first Info node you looked at"))
1624 (let (filename nodename opoint)
1625 (setq filename (car (car Info-history)))
1626 (setq nodename (car (cdr (car Info-history))))
1627 (setq opoint (car (cdr (cdr (car Info-history)))))
1628 (setq Info-history (cdr Info-history))
1629 (Info-find-node filename nodename)
1630 (setq Info-history (cdr Info-history))
1631 (goto-char opoint)))
1633 ;;;###autoload
1634 (defun Info-directory ()
1635 "Go to the Info directory node."
1636 (interactive)
1637 (Info-find-node "dir" "top"))
1639 (defun Info-history ()
1640 "Go to a node with a menu of visited nodes."
1641 (interactive)
1642 (let ((curr-file Info-current-file)
1643 (curr-node Info-current-node)
1645 (with-current-buffer (get-buffer-create " *info-history*")
1646 (let ((inhibit-read-only t))
1647 (erase-buffer)
1648 (goto-char (point-min))
1649 (insert "\n\x1f\nFile: history Node: Top, Up: (dir)\n\n")
1650 (insert "Recently Visited Nodes\n**********************\n\n")
1651 (insert "* Menu:\n\n")
1652 (let ((hl (delete '("history" "Top") Info-history-list)))
1653 (while hl
1654 (let ((file (nth 0 (car hl)))
1655 (node (nth 1 (car hl))))
1656 (if (and (string-equal file curr-file)
1657 (string-equal node curr-node))
1658 (setq p (point)))
1659 (insert "* " node ": (" (file-name-nondirectory file)
1660 ")" node ".\n"))
1661 (setq hl (cdr hl))))))
1662 (Info-find-node "history" "Top")
1663 (goto-char (or p (point-min)))))
1665 (defun Info-toc ()
1666 "Go to a node with table of contents of the current Info file."
1667 (interactive)
1668 (let ((curr-file Info-current-file)
1669 (curr-node Info-current-node)
1671 (with-current-buffer (get-buffer-create " *info-toc*")
1672 (let ((inhibit-read-only t)
1673 (node-list (Info-build-toc curr-file)))
1674 (erase-buffer)
1675 (goto-char (point-min))
1676 (insert "\n\x1f\nFile: toc Node: Top, Up: (dir)\n\n")
1677 (insert "Table of Contents\n*****************\n\n")
1678 (insert "*Note Top::\n")
1679 (Info-insert-toc
1680 (nth 2 (assoc "Top" node-list)) ; get Top nodes
1681 node-list 0 curr-file))
1682 (if (not (bobp))
1683 (let ((Info-hide-note-references 'hide)
1684 (Info-fontify-visited-nodes nil))
1685 (setq Info-current-node "Top")
1686 (Info-fontify-node)))
1687 (goto-char (point-min))
1688 (if (setq p (search-forward (concat "*Note " curr-node ":") nil t))
1689 (setq p (- p (length curr-node) 2))))
1690 (Info-find-node "toc" "Top")
1691 (goto-char (or p (point-min)))))
1693 (defun Info-insert-toc (nodes node-list level curr-file)
1694 "Insert table of contents with references to nodes."
1695 (let ((section "Top"))
1696 (while nodes
1697 (let ((node (assoc (car nodes) node-list)))
1698 (unless (member (nth 1 node) (list nil section))
1699 (insert (setq section (nth 1 node)) "\n"))
1700 (insert (make-string level ?\t))
1701 (insert "*Note " (car nodes) ": (" curr-file ")" (car nodes) ".\n")
1702 (Info-insert-toc (nth 2 node) node-list (1+ level) curr-file)
1703 (setq nodes (cdr nodes))))))
1705 (defun Info-build-toc (file)
1706 "Build table of contents from menus of Info FILE and its subfiles."
1707 (if (equal file "dir")
1708 (error "Table of contents for Info directory is not supported yet"))
1709 (with-temp-buffer
1710 (let ((default-directory (or (and (stringp file)
1711 (file-name-directory
1712 (setq file (Info-find-file file))))
1713 default-directory))
1714 (sections '(("Top" "Top")))
1715 nodes subfiles)
1716 (while (or file subfiles)
1717 (or file (message "Searching subfile %s..." (car subfiles)))
1718 (erase-buffer)
1719 (info-insert-file-contents (or file (car subfiles)))
1720 (while (and (search-forward "\n\^_\nFile:" nil 'move)
1721 (search-forward "Node: " nil 'move))
1722 (let ((nodename (substring-no-properties (Info-following-node-name)))
1723 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
1724 (point-max)) 2))
1725 (section "Top")
1726 menu-items)
1727 (when (and (not (string-match "\\<index\\>" nodename))
1728 (re-search-forward "^\\* Menu:" bound t))
1729 (forward-line 1)
1730 (beginning-of-line)
1731 (setq bound (or (and (equal nodename "Top")
1732 (save-excursion
1733 (re-search-forward
1734 "^[ \t-]*The Detailed Node Listing" nil t)))
1735 bound))
1736 (while (< (point) bound)
1737 (cond
1738 ;; Menu item line
1739 ((looking-at "^\\* +[^:]+:")
1740 (beginning-of-line)
1741 (forward-char 2)
1742 (let ((menu-node-name (substring-no-properties
1743 (Info-extract-menu-node-name))))
1744 (setq menu-items (cons menu-node-name menu-items))
1745 (if (equal nodename "Top")
1746 (setq sections
1747 (cons (list menu-node-name section) sections)))))
1748 ;; Other non-empty strings in the Top node are section names
1749 ((and (equal nodename "Top")
1750 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
1751 (setq section (match-string-no-properties 1))))
1752 (forward-line 1)
1753 (beginning-of-line)))
1754 (setq nodes (cons (list nodename
1755 (cadr (assoc nodename sections))
1756 (nreverse menu-items))
1757 nodes))
1758 (goto-char bound)))
1759 (if file
1760 (save-excursion
1761 (goto-char (point-min))
1762 (if (search-forward "\n\^_\nIndirect:" nil t)
1763 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
1764 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
1765 (setq subfiles (cons (match-string-no-properties 1)
1766 subfiles)))))
1767 (setq subfiles (nreverse subfiles)
1768 file nil))
1769 (setq subfiles (cdr subfiles))))
1770 (message "")
1771 (nreverse nodes))))
1773 (defun Info-follow-reference (footnotename &optional fork)
1774 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1775 FOOTNOTENAME may be an abbreviation of the reference name.
1776 If FORK is non-nil (interactively with a prefix arg), show the node in
1777 a new info buffer. If FORK is a string, it is the name to use for the
1778 new buffer."
1779 (interactive
1780 (let ((completion-ignore-case t)
1781 (case-fold-search t)
1782 completions default alt-default (start-point (point)) str i bol eol)
1783 (save-excursion
1784 ;; Store end and beginning of line.
1785 (end-of-line)
1786 (setq eol (point))
1787 (beginning-of-line)
1788 (setq bol (point))
1790 (goto-char (point-min))
1791 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
1792 (setq str (match-string-no-properties 1))
1793 ;; See if this one should be the default.
1794 (and (null default)
1795 (<= (match-beginning 0) start-point)
1796 (<= start-point (point))
1797 (setq default t))
1798 ;; See if this one should be the alternate default.
1799 (and (null alt-default)
1800 (and (<= bol (match-beginning 0))
1801 (<= (point) eol))
1802 (setq alt-default t))
1803 (setq i 0)
1804 (while (setq i (string-match "[ \n\t]+" str i))
1805 (setq str (concat (substring str 0 i) " "
1806 (substring str (match-end 0))))
1807 (setq i (1+ i)))
1808 ;; Record as a completion and perhaps as default.
1809 (if (eq default t) (setq default str))
1810 (if (eq alt-default t) (setq alt-default str))
1811 ;; Don't add this string if it's a duplicate.
1812 (or (assoc-string str completions t)
1813 (push str completions))))
1814 ;; If no good default was found, try an alternate.
1815 (or default
1816 (setq default alt-default))
1817 ;; If only one cross-reference found, then make it default.
1818 (if (eq (length completions) 1)
1819 (setq default (car completions)))
1820 (if completions
1821 (let ((input (completing-read (if default
1822 (concat
1823 "Follow reference named: (default "
1824 default ") ")
1825 "Follow reference named: ")
1826 completions nil t)))
1827 (list (if (equal input "")
1828 default input) current-prefix-arg))
1829 (error "No cross-references in this node"))))
1831 (unless footnotename
1832 (error "No reference was specified"))
1834 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
1835 (case-fold-search t))
1836 (while (setq i (string-match " " str i))
1837 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1838 (setq i (+ i 6)))
1839 (save-excursion
1840 ;; Move point to the beginning of reference if point is on reference
1841 (or (looking-at "\\*note[ \n\t]+")
1842 (and (looking-back "\\*note[ \n\t]+")
1843 (goto-char (match-beginning 0)))
1844 (if (and (save-excursion
1845 (goto-char (+ (point) 5)) ; skip a possible *note
1846 (re-search-backward "\\*note[ \n\t]+" nil t)
1847 (looking-at str))
1848 (<= (point) (match-end 0)))
1849 (goto-char (match-beginning 0))))
1850 ;; Go to the reference closest to point
1851 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
1852 (+ (match-beginning 0) 5))))
1853 (prev-ref (save-excursion (and (re-search-backward str nil t)
1854 (+ (match-beginning 0) 5)))))
1855 (goto-char (cond ((and next-ref prev-ref)
1856 (if (< (abs (- next-ref (point)))
1857 (abs (- prev-ref (point))))
1858 next-ref prev-ref))
1859 ((or next-ref prev-ref))
1860 ((error "No cross-reference named %s" footnotename))))
1861 (setq target (Info-extract-menu-node-name t))))
1862 (while (setq i (string-match "[ \t\n]+" target i))
1863 (setq target (concat (substring target 0 i) " "
1864 (substring target (match-end 0))))
1865 (setq i (+ i 1)))
1866 (Info-goto-node target fork)))
1868 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
1869 ;; We allow newline because this is also used in Info-follow-reference,
1870 ;; where the xref name might be wrapped over two lines.
1871 "Regexp that matches a menu entry name upto but not including the colon.
1872 Because of ambiguities, this should be concatenated with something like
1873 `:' and `Info-following-node-name-re'.")
1875 (defun Info-extract-menu-node-name (&optional multi-line index-node)
1876 (skip-chars-forward " \t\n")
1877 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
1878 (Info-following-node-name-re
1879 (cond
1880 (index-node "^,\t\n")
1881 (multi-line "^.,\t")
1882 (t "^.,\t\n")))
1883 "\\)"
1884 (if index-node
1885 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
1886 "")))
1887 (if index-node
1888 (setq Info-point-loc
1889 (if (match-beginning 5)
1890 (string-to-number (match-string 5))
1891 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
1892 ;;; Comment out the next line to use names of cross-references:
1893 ;;; (setq Info-point-loc
1894 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
1896 (replace-regexp-in-string
1897 "[ \n]+" " "
1898 (or (match-string 2)
1899 ;; If the node name is the menu entry name (using `entry::').
1900 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
1902 ;; No one calls this.
1903 ;;(defun Info-menu-item-sequence (list)
1904 ;; (while list
1905 ;; (Info-menu (car list))
1906 ;; (setq list (cdr list))))
1908 (defvar Info-complete-menu-buffer)
1909 (defvar Info-complete-next-re nil)
1910 (defvar Info-complete-cache nil)
1912 (defconst Info-node-spec-re
1913 (concat (Info-following-node-name-re "^.,:") "[,:.]")
1914 "Regexp to match the text after a : until the terminating `.'.")
1916 (defun Info-complete-menu-item (string predicate action)
1917 ;; This uses two dynamically bound variables:
1918 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1919 ;; is the menu of items we're trying to complete.
1920 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1921 ;; also look for menu items in subsequent nodes as long as those
1922 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1923 ;; only used for completion in Info-index.
1925 ;; Note that `Info-complete-menu-buffer' could be current already,
1926 ;; so we want to save point.
1927 (save-excursion
1928 (set-buffer Info-complete-menu-buffer)
1929 (let ((completion-ignore-case t)
1930 (case-fold-search t)
1931 (orignode Info-current-node)
1932 nextnode)
1933 (goto-char (point-min))
1934 (search-forward "\n* Menu:")
1935 (if (not (memq action '(nil t)))
1936 (re-search-forward
1937 (concat "\n\\* +" (regexp-quote string) ":") nil t)
1938 (let ((pattern (concat "\n\\* +\\("
1939 (regexp-quote string)
1940 Info-menu-entry-name-re "\\):" Info-node-spec-re))
1941 completions)
1942 ;; Check the cache.
1943 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
1944 (equal (nth 1 Info-complete-cache) Info-current-node)
1945 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
1946 (let ((prev (nth 3 Info-complete-cache)))
1947 (eq t (compare-strings string 0 (length prev)
1948 prev 0 nil t))))
1949 ;; We can reuse the previous list.
1950 (setq completions (nth 4 Info-complete-cache))
1951 ;; The cache can't be used.
1952 (while
1953 (progn
1954 (while (re-search-forward pattern nil t)
1955 (push (match-string-no-properties 1)
1956 completions))
1957 ;; Check subsequent nodes if applicable.
1958 (and Info-complete-next-re
1959 (setq nextnode (Info-extract-pointer "next" t))
1960 (string-match Info-complete-next-re nextnode)))
1961 (Info-goto-node nextnode))
1962 ;; Go back to the start node (for the next completion).
1963 (unless (equal Info-current-node orignode)
1964 (Info-goto-node orignode))
1965 ;; Update the cache.
1966 (set (make-local-variable 'Info-complete-cache)
1967 (list Info-current-file Info-current-node
1968 Info-complete-next-re string completions)))
1969 (if action
1970 (all-completions string completions predicate)
1971 (try-completion string completions predicate)))))))
1974 (defun Info-menu (menu-item &optional fork)
1975 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1976 The menu item should one of those listed in the current node's menu.
1977 Completion is allowed, and the default menu item is the one point is on.
1978 If FORK is non-nil (interactively with a prefix arg), show the node in
1979 a new info buffer. If FORK is a string, it is the name to use for the
1980 new buffer."
1981 (interactive
1982 (let ((completions '())
1983 ;; If point is within a menu item, use that item as the default
1984 (default nil)
1985 (p (point))
1987 (last nil)
1988 (case-fold-search t))
1989 (save-excursion
1990 (goto-char (point-min))
1991 (if (not (search-forward "\n* menu:" nil t))
1992 (error "No menu in this node"))
1993 (setq beg (point))
1994 (and (< (point) p)
1995 (save-excursion
1996 (goto-char p)
1997 (end-of-line)
1998 (if (re-search-backward (concat "\n\\* +\\("
1999 Info-menu-entry-name-re
2000 "\\):") beg t)
2001 (setq default (match-string-no-properties 1))))))
2002 (let ((item nil))
2003 (while (null item)
2004 (setq item (let ((completion-ignore-case t)
2005 (Info-complete-menu-buffer (current-buffer)))
2006 (completing-read (if default
2007 (format "Menu item (default %s): "
2008 default)
2009 "Menu item: ")
2010 'Info-complete-menu-item nil t)))
2011 ;; we rely on the fact that completing-read accepts an input
2012 ;; of "" even when the require-match argument is true and ""
2013 ;; is not a valid possibility
2014 (if (string= item "")
2015 (if default
2016 (setq item default)
2017 ;; ask again
2018 (setq item nil))))
2019 (list item current-prefix-arg))))
2020 ;; there is a problem here in that if several menu items have the same
2021 ;; name you can only go to the node of the first with this command.
2022 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2024 (defun Info-extract-menu-item (menu-item)
2025 (setq menu-item (regexp-quote menu-item))
2026 (let ((case-fold-search t))
2027 (save-excursion
2028 (let ((case-fold-search t))
2029 (goto-char (point-min))
2030 (or (search-forward "\n* menu:" nil t)
2031 (error "No menu in this node"))
2032 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2033 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2034 (error "No such item in menu"))
2035 (beginning-of-line)
2036 (forward-char 2)
2037 (Info-extract-menu-node-name)))))
2039 ;; If COUNT is nil, use the last item in the menu.
2040 (defun Info-extract-menu-counting (count)
2041 (let ((case-fold-search t))
2042 (save-excursion
2043 (let ((case-fold-search t))
2044 (goto-char (point-min))
2045 (or (search-forward "\n* menu:" nil t)
2046 (error "No menu in this node"))
2047 (if count
2048 (or (search-forward "\n* " nil t count)
2049 (error "Too few items in menu"))
2050 (while (search-forward "\n* " nil t)
2051 nil))
2052 (Info-extract-menu-node-name)))))
2054 (defun Info-nth-menu-item ()
2055 "Go to the node of the Nth menu item.
2056 N is the digit argument used to invoke this command."
2057 (interactive)
2058 (Info-goto-node
2059 (Info-extract-menu-counting
2060 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2062 (defun Info-top-node ()
2063 "Go to the Top node of this file."
2064 (interactive)
2065 (Info-goto-node "Top"))
2067 (defun Info-final-node ()
2068 "Go to the final node in this file."
2069 (interactive)
2070 (Info-goto-node "Top")
2071 (let ((Info-history nil)
2072 (case-fold-search t))
2073 ;; Go to the last node in the menu of Top.
2074 (Info-goto-node (Info-extract-menu-counting nil))
2075 ;; If the last node in the menu is not last in pointer structure,
2076 ;; move forward until we can't go any farther.
2077 (while (Info-forward-node t t) nil)
2078 ;; Then keep moving down to last subnode, unless we reach an index.
2079 (while (and (not (string-match "\\<index\\>" Info-current-node))
2080 (save-excursion (search-forward "\n* Menu:" nil t)))
2081 (Info-goto-node (Info-extract-menu-counting nil)))))
2083 (defun Info-forward-node (&optional not-down no-error)
2084 "Go forward one node, considering all nodes as forming one sequence."
2085 (interactive)
2086 (goto-char (point-min))
2087 (forward-line 1)
2088 (let ((case-fold-search t))
2089 ;; three possibilities, in order of priority:
2090 ;; 1. next node is in a menu in this node (but not in an index)
2091 ;; 2. next node is next at same level
2092 ;; 3. next node is up and next
2093 (cond ((and (not not-down)
2094 (save-excursion (search-forward "\n* menu:" nil t))
2095 (not (string-match "\\<index\\>" Info-current-node)))
2096 (Info-goto-node (Info-extract-menu-counting 1))
2098 ((save-excursion (search-backward "next:" nil t))
2099 (Info-next)
2101 ((and (save-excursion (search-backward "up:" nil t))
2102 ;; Use string-equal, not equal, to ignore text props.
2103 (not (string-equal (downcase (Info-extract-pointer "up"))
2104 "top")))
2105 (let ((old-node Info-current-node))
2106 (Info-up)
2107 (let (Info-history success)
2108 (unwind-protect
2109 (setq success (Info-forward-node t no-error))
2110 (or success (Info-goto-node old-node))))))
2111 (no-error nil)
2112 (t (error "No pointer forward from this node")))))
2114 (defun Info-backward-node ()
2115 "Go backward one node, considering all nodes as forming one sequence."
2116 (interactive)
2117 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2118 (upnode (Info-extract-pointer "up" t))
2119 (case-fold-search t))
2120 (cond ((and upnode (string-match "(" upnode))
2121 (error "First node in file"))
2122 ((and upnode (or (null prevnode)
2123 ;; Use string-equal, not equal,
2124 ;; to ignore text properties.
2125 (string-equal (downcase prevnode)
2126 (downcase upnode))))
2127 (Info-up))
2128 (prevnode
2129 ;; If we move back at the same level,
2130 ;; go down to find the last subnode*.
2131 (Info-prev)
2132 (let (Info-history)
2133 (while (and (not (string-match "\\<index\\>" Info-current-node))
2134 (save-excursion (search-forward "\n* Menu:" nil t)))
2135 (Info-goto-node (Info-extract-menu-counting nil)))))
2137 (error "No pointer backward from this node")))))
2139 (defun Info-exit ()
2140 "Exit Info by selecting some other buffer."
2141 (interactive)
2142 (if Info-standalone
2143 (save-buffers-kill-emacs)
2144 (quit-window)))
2146 (defun Info-next-menu-item ()
2147 "Go to the node of the next menu item."
2148 (interactive)
2149 ;; Bind this in case the user sets it to nil.
2150 (let* ((case-fold-search t)
2151 (node
2152 (save-excursion
2153 (forward-line -1)
2154 (search-forward "\n* menu:" nil t)
2155 (and (search-forward "\n* " nil t)
2156 (Info-extract-menu-node-name)))))
2157 (if node (Info-goto-node node)
2158 (error "No more items in menu"))))
2160 (defun Info-last-menu-item ()
2161 "Go to the node of the previous menu item."
2162 (interactive)
2163 (save-excursion
2164 (forward-line 1)
2165 ;; Bind this in case the user sets it to nil.
2166 (let* ((case-fold-search t)
2167 (beg (save-excursion
2168 (and (search-backward "\n* menu:" nil t)
2169 (point)))))
2170 (or (and beg (search-backward "\n* " beg t))
2171 (error "No previous items in menu")))
2172 (Info-goto-node (save-excursion
2173 (goto-char (match-end 0))
2174 (Info-extract-menu-node-name)))))
2176 (defmacro Info-no-error (&rest body)
2177 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2179 (defun Info-next-preorder ()
2180 "Go to the next subnode or the next node, or go up a level."
2181 (interactive)
2182 (cond ((Info-no-error (Info-next-menu-item)))
2183 ((Info-no-error (Info-next)))
2184 ((Info-no-error (Info-up t))
2185 ;; Since we have already gone thru all the items in this menu,
2186 ;; go up to the end of this node.
2187 (goto-char (point-max))
2188 ;; Since logically we are done with the node with that menu,
2189 ;; move on from it.
2190 (Info-next-preorder))
2192 (error "No more nodes"))))
2194 (defun Info-last-preorder ()
2195 "Go to the last node, popping up a level if there is none."
2196 (interactive)
2197 (cond ((Info-no-error
2198 (Info-last-menu-item)
2199 ;; If we go down a menu item, go to the end of the node
2200 ;; so we can scroll back through it.
2201 (goto-char (point-max)))
2202 ;; Keep going down, as long as there are nested menu nodes.
2203 (while (Info-no-error
2204 (Info-last-menu-item)
2205 ;; If we go down a menu item, go to the end of the node
2206 ;; so we can scroll back through it.
2207 (goto-char (point-max))))
2208 (recenter -1))
2209 ((and (Info-no-error (Info-extract-pointer "prev"))
2210 (not (equal (Info-extract-pointer "up")
2211 (Info-extract-pointer "prev"))))
2212 (Info-no-error (Info-prev))
2213 (goto-char (point-max))
2214 (while (Info-no-error
2215 (Info-last-menu-item)
2216 ;; If we go down a menu item, go to the end of the node
2217 ;; so we can scroll back through it.
2218 (goto-char (point-max))))
2219 (recenter -1))
2220 ((Info-no-error (Info-up t))
2221 (goto-char (point-min))
2222 (let ((case-fold-search t))
2223 (or (search-forward "\n* Menu:" nil t)
2224 (goto-char (point-max)))))
2225 (t (error "No previous nodes"))))
2227 (defun Info-scroll-up ()
2228 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2229 Once you scroll far enough in a node that its menu appears on the screen
2230 but after point, the next scroll moves into its first subnode, unless
2231 `Info-scroll-prefer-subnodes' is nil.
2233 When you scroll past the end of a node, that goes to the next node if
2234 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2235 if this node has no successor, it moves to the parent node's successor,
2236 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2237 the menu of a node, it moves to subnode indicated by the following menu
2238 item. (That case won't normally result from this command, but can happen
2239 in other ways.)"
2241 (interactive)
2242 (if (or (< (window-start) (point-min))
2243 (> (window-start) (point-max)))
2244 (set-window-start (selected-window) (point)))
2245 (let* ((case-fold-search t)
2246 (virtual-end (save-excursion
2247 (goto-char (point-min))
2248 (if (and Info-scroll-prefer-subnodes
2249 (search-forward "\n* Menu:" nil t))
2250 (point)
2251 (point-max)))))
2252 (if (or (< virtual-end (window-start))
2253 (pos-visible-in-window-p virtual-end))
2254 (cond
2255 (Info-scroll-prefer-subnodes (Info-next-preorder))
2256 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2257 (t (Info-next-preorder)))
2258 (scroll-up))))
2260 (defun Info-scroll-down ()
2261 "Scroll one screenful back in Info, considering all nodes as one sequence.
2262 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2263 is non-nil, this goes to its last subnode. When you scroll past the
2264 beginning of a node, that goes to the previous node or back up to the
2265 parent node."
2266 (interactive)
2267 (if (or (< (window-start) (point-min))
2268 (> (window-start) (point-max)))
2269 (set-window-start (selected-window) (point)))
2270 (let* ((case-fold-search t)
2271 (current-point (point))
2272 (virtual-end
2273 (and Info-scroll-prefer-subnodes
2274 (save-excursion
2275 (beginning-of-line)
2276 (setq current-point (point))
2277 (goto-char (point-min))
2278 (search-forward "\n* Menu:"
2279 current-point
2280 t)))))
2281 (if (or virtual-end
2282 (pos-visible-in-window-p (point-min) nil t))
2283 (Info-last-preorder)
2284 (scroll-down))))
2286 (defun Info-next-reference (&optional recur)
2287 "Move cursor to the next cross-reference or menu item in the node."
2288 (interactive)
2289 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2290 (old-pt (point))
2291 (case-fold-search t))
2292 (or (eobp) (forward-char 1))
2293 (or (re-search-forward pat nil t)
2294 (progn
2295 (goto-char (point-min))
2296 (or (re-search-forward pat nil t)
2297 (progn
2298 (goto-char old-pt)
2299 (error "No cross references in this node")))))
2300 (goto-char (or (match-beginning 1) (match-beginning 0)))
2301 (if (looking-at "\\* Menu:")
2302 (if recur
2303 (error "No cross references in this node")
2304 (Info-next-reference t)))))
2306 (defun Info-prev-reference (&optional recur)
2307 "Move cursor to the previous cross-reference or menu item in the node."
2308 (interactive)
2309 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2310 (old-pt (point))
2311 (case-fold-search t))
2312 (or (re-search-backward pat nil t)
2313 (progn
2314 (goto-char (point-max))
2315 (or (re-search-backward pat nil t)
2316 (progn
2317 (goto-char old-pt)
2318 (error "No cross references in this node")))))
2319 (goto-char (or (match-beginning 1) (match-beginning 0)))
2320 (if (looking-at "\\* Menu:")
2321 (if recur
2322 (error "No cross references in this node")
2323 (Info-prev-reference t)))))
2325 (defun Info-goto-index ()
2326 (Info-goto-node "Top")
2327 (or (search-forward "\n* menu:" nil t)
2328 (error "No index"))
2329 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2330 (error "No index"))
2331 (goto-char (match-beginning 1))
2332 ;; Protect Info-history so that the current node (Top) is not added to it.
2333 (let ((Info-history nil))
2334 (Info-goto-node (Info-extract-menu-node-name))))
2336 ;;;###autoload
2337 (defun Info-index (topic)
2338 "Look up a string TOPIC in the index for this file.
2339 The index is defined as the first node in the top level menu whose
2340 name contains the word \"Index\", plus any immediately following
2341 nodes whose names also contain the word \"Index\".
2342 If there are no exact matches to the specified topic, this chooses
2343 the first match which is a case-insensitive substring of a topic.
2344 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2345 Give a blank topic name to go to the Index node itself."
2346 (interactive
2347 (list
2348 (let ((Info-complete-menu-buffer (clone-buffer))
2349 (Info-complete-next-re "\\<Index\\>"))
2350 (if (equal Info-current-file "dir")
2351 (error "The Info directory node has no index; use m to select a manual"))
2352 (unwind-protect
2353 (with-current-buffer Info-complete-menu-buffer
2354 (Info-goto-index)
2355 (completing-read "Index topic: " 'Info-complete-menu-item))
2356 (kill-buffer Info-complete-menu-buffer)))))
2357 (if (equal Info-current-file "dir")
2358 (error "The Info directory node has no index; use m to select a manual"))
2359 (let ((orignode Info-current-node)
2360 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2361 (regexp-quote topic)))
2362 node
2363 (case-fold-search t))
2364 (Info-goto-index)
2365 (or (equal topic "")
2366 (let ((matches nil)
2367 (exact nil)
2368 ;; We bind Info-history to nil for internal node-switches so
2369 ;; that we don't put junk in the history. In the first
2370 ;; Info-goto-index call, above, we do update the history
2371 ;; because that is what the user's previous node choice into it.
2372 (Info-history nil)
2373 found)
2374 (while
2375 (progn
2376 (goto-char (point-min))
2377 (while (re-search-forward pattern nil t)
2378 (push (list (match-string-no-properties 1)
2379 (match-string-no-properties 2)
2380 Info-current-node
2381 (string-to-number (concat "0"
2382 (match-string 3))))
2383 matches))
2384 (and (setq node (Info-extract-pointer "next" t))
2385 (string-match "\\<Index\\>" node)))
2386 (Info-goto-node node))
2387 (or matches
2388 (progn
2389 (Info-goto-node orignode)
2390 (error "No `%s' in index" topic)))
2391 ;; Here it is a feature that assoc is case-sensitive.
2392 (while (setq found (assoc topic matches))
2393 (setq exact (cons found exact)
2394 matches (delq found matches)))
2395 (setq Info-index-alternatives (nconc exact (nreverse matches)))
2396 (Info-index-next 0)))))
2398 (defun Info-index-next (num)
2399 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
2400 (interactive "p")
2401 (or Info-index-alternatives
2402 (error "No previous `i' command"))
2403 (while (< num 0)
2404 (setq num (+ num (length Info-index-alternatives))))
2405 (while (> num 0)
2406 (setq Info-index-alternatives
2407 (nconc (cdr Info-index-alternatives)
2408 (list (car Info-index-alternatives)))
2409 num (1- num)))
2410 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2411 (if (> (nth 3 (car Info-index-alternatives)) 0)
2412 (forward-line (1- (nth 3 (car Info-index-alternatives))))
2413 (forward-line 3) ; don't search in headers
2414 (let ((name (car (car Info-index-alternatives))))
2415 (Info-find-index-name name)))
2416 (message "Found `%s' in %s. %s"
2417 (car (car Info-index-alternatives))
2418 (nth 2 (car Info-index-alternatives))
2419 (if (cdr Info-index-alternatives)
2420 "(`,' tries to find next)"
2421 "(Only match)")))
2423 (defun Info-find-index-name (name)
2424 "Move point to the place within the current node where NAME is defined."
2425 (let ((case-fold-search t))
2426 (if (or (re-search-forward (format
2427 "[a-zA-Z]+: %s\\( \\|$\\)"
2428 (regexp-quote name)) nil t)
2429 ;; Find a function definition with a return type.
2430 (re-search-forward (format
2431 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2432 (regexp-quote name)) nil t)
2433 (search-forward (format "`%s'" name) nil t)
2434 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2435 (search-forward
2436 (format "`%s'" (substring name 0 (match-beginning 1)))
2437 nil t))
2438 (search-forward name nil t)
2439 ;; Try again without the " <1>" makeinfo can append
2440 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
2441 (Info-find-index-name (match-string 1 name))))
2442 (progn (beginning-of-line) t) ;; non-nil for recursive call
2443 (goto-char (point-min)))))
2445 ;;;###autoload
2446 (defun info-apropos (string)
2447 "Grovel indices of all known Info files on your system for STRING.
2448 Build a menu of the possible matches."
2449 (interactive "sIndex apropos: ")
2450 (unless (string= string "")
2451 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2452 (regexp-quote string)))
2453 (ohist Info-history)
2454 (ohist-list Info-history-list)
2455 (current-node Info-current-node)
2456 (current-file Info-current-file)
2457 manuals matches node)
2458 (let ((Info-fontify-maximum-menu-size 0)
2459 Info-use-header-lines
2460 Info-hide-note-references)
2461 (Info-directory)
2462 (message "Searching indices...")
2463 (goto-char (point-min))
2464 (re-search-forward "\\* Menu: *\n" nil t)
2465 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
2466 (add-to-list 'manuals (match-string 1)))
2467 (dolist (manual manuals)
2468 (message "Searching %s" manual)
2469 (condition-case nil
2470 (save-excursion
2471 (Info-find-node manual "Top")
2472 (when (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2473 (goto-char (match-beginning 1))
2474 (Info-goto-node (Info-extract-menu-node-name))
2475 (while
2476 (progn
2477 (goto-char (point-min))
2478 (while (re-search-forward pattern nil t)
2479 (add-to-list 'matches
2480 (list manual
2481 (match-string-no-properties 1)
2482 (match-string-no-properties 2)
2483 (match-string-no-properties 3))))
2484 (and (setq node (Info-extract-pointer "next" t))
2485 (string-match "\\<Index\\>" node)))
2486 (Info-goto-node node))))
2487 (error nil))))
2488 (Info-goto-node (concat "(" current-file ")" current-node))
2489 (setq Info-history ohist
2490 Info-history-list ohist-list)
2491 (message "Searching indices...done")
2492 (if (null matches)
2493 (message "No matches found")
2494 (with-current-buffer (get-buffer-create " *info-apropos*")
2495 (erase-buffer)
2496 (insert "\n\x1f\nFile: apropos, Node: Index, Up: (dir)\n")
2497 (insert "* Menu: \nNodes whose indices contain \"" string "\"\n\n")
2498 (dolist (entry matches)
2499 (insert
2500 (format "* %-38s (%s)%s.%s\n"
2501 (concat (nth 1 entry) " [" (nth 0 entry) "]:")
2502 (nth 0 entry)
2503 (nth 2 entry)
2504 (if (nth 3 entry)
2505 (concat " (line " (nth 3 entry) ")")
2506 "")))))
2507 (Info-find-node "apropos" "Index")
2508 (setq Info-complete-cache nil)))))
2510 (defun Info-undefined ()
2511 "Make command be undefined in Info."
2512 (interactive)
2513 (ding))
2515 (defun Info-help ()
2516 "Enter the Info tutorial."
2517 (interactive)
2518 (delete-other-windows)
2519 (Info-find-node "info"
2520 (if (< (window-height) 23)
2521 "Help-Small-Screen"
2522 "Help")))
2524 (defun Info-summary ()
2525 "Display a brief summary of all Info commands."
2526 (interactive)
2527 (save-window-excursion
2528 (switch-to-buffer "*Help*")
2529 (setq buffer-read-only nil)
2530 (erase-buffer)
2531 (insert (documentation 'Info-mode))
2532 (help-mode)
2533 (goto-char (point-min))
2534 (let (ch flag)
2535 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2536 (message (if flag "Type Space to see more"
2537 "Type Space to return to Info"))
2538 (if (not (eq ?\ (setq ch (read-event))))
2539 (progn (setq unread-command-events (list ch)) nil)
2540 flag))
2541 (scroll-up)))
2542 (bury-buffer "*Help*")))
2544 (defun Info-get-token (pos start all &optional errorstring)
2545 "Return the token around POS.
2546 POS must be somewhere inside the token
2547 START is a regular expression which will match the
2548 beginning of the tokens delimited string
2549 ALL is a regular expression with a single
2550 parenthesized subpattern which is the token to be
2551 returned. E.g. '{\(.*\)}' would return any string
2552 enclosed in braces around POS.
2553 ERRORSTRING optional fourth argument, controls action on no match
2554 nil: return nil
2555 t: beep
2556 a string: signal an error, using that string."
2557 (let ((case-fold-search t))
2558 (save-excursion
2559 (goto-char pos)
2560 ;; First look for a match for START that goes across POS.
2561 (while (and (not (bobp)) (> (point) (- pos (length start)))
2562 (not (looking-at start)))
2563 (forward-char -1))
2564 ;; If we did not find one, search back for START
2565 ;; (this finds only matches that end at or before POS).
2566 (or (looking-at start)
2567 (progn
2568 (goto-char pos)
2569 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2570 (let (found)
2571 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2572 (not (setq found (and (<= (match-beginning 0) pos)
2573 (> (match-end 0) pos))))))
2574 (if (and found (<= (match-beginning 0) pos)
2575 (> (match-end 0) pos))
2576 (match-string-no-properties 1)
2577 (cond ((null errorstring)
2578 nil)
2579 ((eq errorstring t)
2580 (beep)
2581 nil)
2583 (error "No %s around position %d" errorstring pos))))))))
2585 (defun Info-mouse-follow-nearest-node (click)
2586 "\\<Info-mode-map>Follow a node reference near point.
2587 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2588 At end of the node's text, moves to the next node, or up if none."
2589 (interactive "e")
2590 (mouse-set-point click)
2591 (and (not (Info-try-follow-nearest-node))
2592 (save-excursion (forward-line 1) (eobp))
2593 (Info-next-preorder)))
2595 (defun Info-follow-nearest-node (&optional fork)
2596 "Follow a node reference near point.
2597 If point is on a reference, follow that reference. Otherwise,
2598 if point is in a menu item description, follow that menu item."
2599 (interactive "P")
2600 (or (Info-try-follow-nearest-node fork)
2601 (when (save-excursion
2602 (search-backward "\n* menu:" nil t))
2603 (save-excursion
2604 (beginning-of-line)
2605 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2606 (beginning-of-line 0))
2607 (when (looking-at "\\* +\\([^\t\n]*\\):")
2608 (Info-goto-node
2609 (Info-extract-menu-item (match-string-no-properties 1)) fork)
2610 t)))
2611 (error "Point neither on reference nor in menu item description")))
2613 ;; Common subroutine.
2614 (defun Info-try-follow-nearest-node (&optional fork)
2615 "Follow a node reference near point. Return non-nil if successful."
2616 (let (node)
2617 (cond
2618 ((and (Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
2619 (or (featurep 'browse-url) (require 'browse-url nil t)))
2620 (setq node t)
2621 (browse-url (browse-url-url-at-point)))
2622 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
2623 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
2624 (Info-follow-reference node fork))
2625 ;; menu item: node name
2626 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2627 (Info-goto-node node fork))
2628 ;; menu item: node name or index entry
2629 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2630 (beginning-of-line)
2631 (forward-char 2)
2632 (setq node (Info-extract-menu-node-name
2633 nil (string-match "\\<index\\>" Info-current-node)))
2634 (Info-goto-node node fork))
2635 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2636 (Info-goto-node node fork))
2637 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2638 (Info-goto-node node fork))
2639 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2640 (Info-goto-node "Top" fork))
2641 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2642 (Info-goto-node node fork)))
2643 node))
2645 (defvar Info-mode-map nil
2646 "Keymap containing Info commands.")
2647 (if Info-mode-map
2649 (setq Info-mode-map (make-keymap))
2650 (suppress-keymap Info-mode-map)
2651 (define-key Info-mode-map "." 'beginning-of-buffer)
2652 (define-key Info-mode-map " " 'Info-scroll-up)
2653 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
2654 (define-key Info-mode-map "\t" 'Info-next-reference)
2655 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2656 (define-key Info-mode-map [backtab] 'Info-prev-reference)
2657 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2658 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2659 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2660 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2661 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2662 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2663 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2664 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2665 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2666 (define-key Info-mode-map "0" 'undefined)
2667 (define-key Info-mode-map "?" 'Info-summary)
2668 (define-key Info-mode-map "]" 'Info-forward-node)
2669 (define-key Info-mode-map "[" 'Info-backward-node)
2670 (define-key Info-mode-map "<" 'Info-top-node)
2671 (define-key Info-mode-map ">" 'Info-final-node)
2672 (define-key Info-mode-map "b" 'beginning-of-buffer)
2673 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2674 (define-key Info-mode-map "d" 'Info-directory)
2675 (define-key Info-mode-map "e" 'Info-edit)
2676 (define-key Info-mode-map "f" 'Info-follow-reference)
2677 (define-key Info-mode-map "g" 'Info-goto-node)
2678 (define-key Info-mode-map "h" 'Info-help)
2679 (define-key Info-mode-map "i" 'Info-index)
2680 (define-key Info-mode-map "l" 'Info-last)
2681 (define-key Info-mode-map "m" 'Info-menu)
2682 (define-key Info-mode-map "n" 'Info-next)
2683 (define-key Info-mode-map "p" 'Info-prev)
2684 (define-key Info-mode-map "q" 'Info-exit)
2685 (define-key Info-mode-map "s" 'Info-search)
2686 ;; For consistency with Rmail.
2687 (define-key Info-mode-map "\M-s" 'Info-search)
2688 (define-key Info-mode-map "\M-n" 'clone-buffer)
2689 (define-key Info-mode-map "t" 'Info-top-node)
2690 (define-key Info-mode-map "u" 'Info-up)
2691 (define-key Info-mode-map "," 'Info-index-next)
2692 (define-key Info-mode-map "\177" 'Info-scroll-down)
2693 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2696 (defun Info-check-pointer (item)
2697 "Non-nil if ITEM is present in this node."
2698 (condition-case nil
2699 (Info-extract-pointer item)
2700 (error nil)))
2702 (easy-menu-define
2703 Info-mode-menu Info-mode-map
2704 "Menu for info files."
2705 '("Info"
2706 ["Up" Info-up :active (Info-check-pointer "up")
2707 :help "Go up in the Info tree"]
2708 ["Next" Info-next :active (Info-check-pointer "next")
2709 :help "Go to the next node"]
2710 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2711 :help "Go to the previous node"]
2712 ["Backward" Info-backward-node
2713 :help "Go backward one node, considering all as a sequence"]
2714 ["Forward" Info-forward-node
2715 :help "Go forward one node, considering all as a sequence"]
2716 ["Beginning" beginning-of-buffer
2717 :help "Go to beginning of this node"]
2718 ["Top" Info-top-node
2719 :help "Go to top node of file"]
2720 ["Final Node" Info-final-node
2721 :help "Go to final node in this file"]
2722 ("Menu Item" ["You should never see this" report-emacs-bug t])
2723 ("Reference" ["You should never see this" report-emacs-bug t])
2724 ["Search..." Info-search
2725 :help "Search for regular expression in this Info file"]
2726 ["Search Case-Sensitively..." Info-search-case-sensitively
2727 :help "Search for regular expression case sensitively"]
2728 ["Search Next" Info-search-next
2729 :help "Search for another occurrence of regular expression"]
2730 ["Go to Node..." Info-goto-node
2731 :help "Go to a named node"]
2732 ["Last" Info-last :active Info-history
2733 :help "Go to the last node you were at"]
2734 ["History" Info-history :active Info-history-list
2735 :help "Go to the history buffer"]
2736 ["Table of Contents" Info-toc
2737 :help "Go to the buffer with a table of contents"]
2738 ("Index..."
2739 ["Lookup a String" Info-index
2740 :help "Look for a string in the index items"]
2741 ["Next Matching Item" Info-index-next
2742 :help "Look for another occurrence of previous item"]
2743 ["Lookup a string in all indices" info-apropos
2744 :help "Look for a string in the indices of all manuals"])
2745 ["Edit" Info-edit :help "Edit contents of this node"
2746 :active Info-enable-edit]
2747 ["Copy Node Name" Info-copy-current-node-name
2748 :help "Copy the name of the current node into the kill ring"]
2749 ["Clone Info buffer" clone-buffer
2750 :help "Create a twin copy of the current Info buffer."]
2751 ["Exit" Info-exit :help "Stop reading Info"]))
2754 (defvar info-tool-bar-map
2755 (if (display-graphic-p)
2756 (let ((map (make-sparse-keymap)))
2757 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2758 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2759 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2760 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2761 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2762 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2763 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2764 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2765 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2766 map)))
2768 (defvar Info-menu-last-node nil)
2769 ;; Last node the menu was created for.
2770 ;; Value is a list, (FILE-NAME NODE-NAME).
2772 (defun Info-menu-update ()
2773 "Update the Info menu for the current node."
2774 (condition-case nil
2775 (if (or (not (eq major-mode 'Info-mode))
2776 (equal (list Info-current-file Info-current-node)
2777 Info-menu-last-node))
2779 ;; Update menu menu.
2780 (let* ((Info-complete-menu-buffer (current-buffer))
2781 (items (nreverse (condition-case nil
2782 (Info-complete-menu-item "" nil t)
2783 (error nil))))
2784 entries current
2785 (number 0))
2786 (while (and items (< number 9))
2787 (setq current (car items)
2788 items (cdr items)
2789 number (1+ number))
2790 (setq entries (cons `[,current
2791 (Info-menu ,current)
2792 :keys ,(format "%d" number)]
2793 entries)))
2794 (if items
2795 (setq entries (cons ["Other..." Info-menu t] entries)))
2796 (or entries
2797 (setq entries (list ["No menu" nil nil] nil :active)))
2798 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2799 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2800 (let ((items nil)
2801 str i entries current
2802 (number 0)
2803 (case-fold-search t))
2804 (save-excursion
2805 (goto-char (point-min))
2806 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2807 (setq str (match-string 1))
2808 (setq i 0)
2809 (while (setq i (string-match "[ \n\t]+" str i))
2810 (setq str (concat (substring str 0 i) " "
2811 (substring str (match-end 0))))
2812 (setq i (1+ i)))
2813 (setq items
2814 (cons str items))))
2815 (while (and items (< number 9))
2816 (setq current (car items)
2817 items (cdr items)
2818 number (1+ number))
2819 (setq entries (cons `[,current
2820 (Info-follow-reference ,current)
2822 entries)))
2823 (if items
2824 (setq entries (cons ["Other..." Info-follow-reference t]
2825 entries)))
2826 (or entries
2827 (setq entries (list ["No references" nil nil] nil :active)))
2828 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2829 ;; Update last seen node.
2830 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2831 ;; Try to avoid entering infinite beep mode in case of errors.
2832 (error (ding))))
2835 (defun Info-copy-current-node-name ()
2836 "Put the name of the current info node into the kill ring.
2837 The name of the info file is prepended to the node name in parentheses."
2838 (interactive)
2839 (unless Info-current-node
2840 (error "No current info node"))
2841 (kill-new
2842 (concat "("
2843 (file-name-nondirectory
2844 (if (stringp Info-current-file)
2845 Info-current-file
2846 (or buffer-file-name "")))
2848 Info-current-node)))
2851 ;; Info mode is suitable only for specially formatted data.
2852 (put 'Info-mode 'mode-class 'special)
2853 (put 'Info-mode 'no-clone-indirect t)
2855 (defun Info-mode ()
2856 "Info mode provides commands for browsing through the Info documentation tree.
2857 Documentation in Info is divided into \"nodes\", each of which discusses
2858 one topic and contains references to other nodes which discuss related
2859 topics. Info has commands to follow the references and show you other nodes.
2861 \\<Info-mode-map>\
2862 \\[Info-help] Invoke the Info tutorial.
2863 \\[Info-exit] Quit Info: reselect previously selected buffer.
2865 Selecting other nodes:
2866 \\[Info-mouse-follow-nearest-node]
2867 Follow a node reference you click on.
2868 This works with menu items, cross references, and
2869 the \"next\", \"previous\" and \"up\", depending on where you click.
2870 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2871 \\[Info-next] Move to the \"next\" node of this node.
2872 \\[Info-prev] Move to the \"previous\" node of this node.
2873 \\[Info-up] Move \"up\" from this node.
2874 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2875 Picking a menu item causes another node to be selected.
2876 \\[Info-directory] Go to the Info directory node.
2877 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2878 \\[Info-last] Move to the last node you were at.
2879 \\[Info-history] Go to the history buffer.
2880 \\[Info-toc] Go to the buffer with a table of contents.
2881 \\[Info-index] Look up a topic in this file's Index and move to that node.
2882 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
2883 \\[info-apropos] Look for a string in the indices of all manuals.
2884 \\[Info-top-node] Go to the Top node of this file.
2885 \\[Info-final-node] Go to the final node in this file.
2886 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2887 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2889 Moving within a node:
2890 \\[Info-scroll-up] Normally, scroll forward a full screen.
2891 Once you scroll far enough in a node that its menu appears on the
2892 screen but after point, the next scroll moves into its first
2893 subnode. When after all menu items (or if there is no menu),
2894 move up to the parent node.
2895 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2896 already visible, try to go to the previous menu entry, or up
2897 if there is none.
2898 \\[beginning-of-buffer] Go to beginning of node.
2900 Advanced commands:
2901 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
2902 \\[clone-buffer] Select a new cloned Info buffer in another window.
2903 \\[Info-edit] Edit contents of selected node.
2904 1 Pick first item in node's menu.
2905 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2906 \\[Info-goto-node] Move to node specified by name.
2907 You may include a filename as well, as (FILENAME)NODENAME.
2908 \\[universal-argument] \\[info] Move to new Info file with completion.
2909 \\[Info-search] Search through this Info file for specified regexp,
2910 and select the node in which the next occurrence is found.
2911 \\[Info-search-case-sensitively] Search through this Info file
2912 for specified regexp case-sensitively.
2913 \\[Info-search-next] Search for another occurrence of regexp
2914 from a previous \\<Info-mode-map>\\[Info-search] command.
2915 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2916 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2917 (kill-all-local-variables)
2918 (setq major-mode 'Info-mode)
2919 (setq mode-name "Info")
2920 (setq tab-width 8)
2921 (use-local-map Info-mode-map)
2922 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2923 (set-syntax-table text-mode-syntax-table)
2924 (setq local-abbrev-table text-mode-abbrev-table)
2925 (setq case-fold-search t)
2926 (setq buffer-read-only t)
2927 (make-local-variable 'Info-current-file)
2928 (make-local-variable 'Info-current-subfile)
2929 (make-local-variable 'Info-current-node)
2930 (make-local-variable 'Info-tag-table-marker)
2931 (setq Info-tag-table-marker (make-marker))
2932 (make-local-variable 'Info-tag-table-buffer)
2933 (setq Info-tag-table-buffer nil)
2934 (make-local-variable 'Info-history)
2935 (make-local-variable 'Info-index-alternatives)
2936 (setq header-line-format
2937 (if Info-use-header-line
2938 '(:eval (get-text-property (point-min) 'header-line))
2939 nil)) ; so the header line isn't displayed
2940 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
2941 ;; This is for the sake of the invisible text we use handling titles.
2942 (make-local-variable 'line-move-ignore-invisible)
2943 (setq line-move-ignore-invisible t)
2944 (make-local-variable 'desktop-save-buffer)
2945 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
2946 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
2947 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
2948 (Info-set-mode-line)
2949 (run-hooks 'Info-mode-hook))
2951 (defun Info-clone-buffer-hook ()
2952 (when (bufferp Info-tag-table-buffer)
2953 (setq Info-tag-table-buffer
2954 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2955 (let ((m Info-tag-table-marker))
2956 (when (markerp m)
2957 (setq Info-tag-table-marker
2958 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
2959 (with-current-buffer Info-tag-table-buffer
2960 (copy-marker (marker-position m)))
2961 (make-marker))))))
2963 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
2964 (set-keymap-parent map text-mode-map)
2965 (define-key map "\C-c\C-c" 'Info-cease-edit)
2966 map)
2967 "Local keymap used within `e' command of Info.")
2969 ;; Info-edit mode is suitable only for specially formatted data.
2970 (put 'Info-edit-mode 'mode-class 'special)
2972 (defun Info-edit-mode ()
2973 "Major mode for editing the contents of an Info node.
2974 Like text mode with the addition of `Info-cease-edit'
2975 which returns to Info mode for browsing.
2976 \\{Info-edit-map}"
2977 (use-local-map Info-edit-map)
2978 (setq major-mode 'Info-edit-mode)
2979 (setq mode-name "Info Edit")
2980 (kill-local-variable 'mode-line-buffer-identification)
2981 (setq buffer-read-only nil)
2982 (force-mode-line-update)
2983 (buffer-enable-undo (current-buffer))
2984 (run-hooks 'Info-edit-mode-hook))
2986 (defun Info-edit ()
2987 "Edit the contents of this Info node.
2988 Allowed only if variable `Info-enable-edit' is non-nil."
2989 (interactive)
2990 (or Info-enable-edit
2991 (error "Editing info nodes is not enabled"))
2992 (Info-edit-mode)
2993 (message "%s" (substitute-command-keys
2994 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2996 (defun Info-cease-edit ()
2997 "Finish editing Info node; switch back to Info proper."
2998 (interactive)
2999 ;; Do this first, so nothing has changed if user C-g's at query.
3000 (and (buffer-modified-p)
3001 (y-or-n-p "Save the file? ")
3002 (save-buffer))
3003 (use-local-map Info-mode-map)
3004 (setq major-mode 'Info-mode)
3005 (setq mode-name "Info")
3006 (Info-set-mode-line)
3007 (setq buffer-read-only t)
3008 (force-mode-line-update)
3009 (and (marker-position Info-tag-table-marker)
3010 (buffer-modified-p)
3011 (message "Tags may have changed. Use Info-tagify if necessary")))
3013 (defvar Info-file-list-for-emacs
3014 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
3015 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3016 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3017 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3018 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3019 ("copyright" . "autotype") ("executable" . "autotype")
3020 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3021 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3022 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3023 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3024 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3025 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3026 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3027 ("rfc2045" . "emacs-mime")
3028 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3029 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3030 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3031 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3032 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3033 ("mml" . "emacs-mime"))
3034 "List of Info files that describe Emacs commands.
3035 An element can be a file name, or a list of the form (PREFIX . FILE)
3036 where PREFIX is a name prefix and FILE is the file to look in.
3037 If the element is just a file name, the file name also serves as the prefix.")
3039 (defun Info-find-emacs-command-nodes (command)
3040 "Return a list of locations documenting COMMAND.
3041 The `info-file' property of COMMAND says which Info manual to search.
3042 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3043 defines heuristics for which Info manual to try.
3044 The locations are of the format used in `Info-history', i.e.
3045 \(FILENAME NODENAME BUFFERPOS\)."
3046 (let ((where '())
3047 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3048 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
3049 (info-file "emacs")) ;default
3050 ;; Determine which info file this command is documented in.
3051 (if (get command 'info-file)
3052 (setq info-file (get command 'info-file))
3053 ;; If it doesn't say explicitly, test its name against
3054 ;; various prefixes that we know.
3055 (let ((file-list Info-file-list-for-emacs))
3056 (while file-list
3057 (let* ((elt (car file-list))
3058 (name (if (consp elt)
3059 (car elt)
3060 elt))
3061 (file (if (consp elt) (cdr elt) elt))
3062 (regexp (concat "\\`" (regexp-quote name)
3063 "\\(\\'\\|-\\)")))
3064 (if (string-match regexp (symbol-name command))
3065 (setq info-file file file-list nil))
3066 (setq file-list (cdr file-list))))))
3067 (Info-find-node info-file "Top")
3068 (or (and (search-forward "\n* menu:" nil t)
3069 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3070 (error "Info file `%s' appears to lack an index" info-file))
3071 (goto-char (match-beginning 1))
3072 ;; Bind Info-history to nil, to prevent the index nodes from
3073 ;; getting into the node history.
3074 (let ((Info-history nil)
3075 node)
3076 (Info-goto-node (Info-extract-menu-node-name))
3077 (while
3078 (progn
3079 (goto-char (point-min))
3080 (while (re-search-forward cmd-desc nil t)
3081 (setq where
3082 (cons (list Info-current-file
3083 (match-string-no-properties 2)
3085 where)))
3086 (and (setq node (Info-extract-pointer "next" t))
3087 (string-match "\\<Index\\>" node)))
3088 (Info-goto-node node)))
3089 where))
3091 ;;;###autoload
3092 (defun Info-goto-emacs-command-node (command)
3093 "Go to the Info node in the Emacs manual for command COMMAND.
3094 The command is found by looking up in Emacs manual's indices
3095 or in another manual found via COMMAND's `info-file' property or
3096 the variable `Info-file-list-for-emacs'.
3097 COMMAND must be a symbol or string."
3098 (interactive "CFind documentation for command: ")
3099 ;; If command is given as a string, convert it to a symbol.
3100 (if (stringp command)
3101 (setq command (intern command)))
3102 (or (commandp command)
3103 (signal 'wrong-type-argument (list 'commandp command)))
3104 (let ((where (Info-find-emacs-command-nodes command)))
3105 (if where
3106 (let ((num-matches (length where)))
3107 ;; Get Info running, and pop to it in another window.
3108 (save-window-excursion
3109 (info))
3110 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3111 ;; Bind Info-history to nil, to prevent the last Index node
3112 ;; visited by Info-find-emacs-command-nodes from being
3113 ;; pushed onto the history.
3114 (let ((Info-history nil))
3115 (Info-find-node (car (car where))
3116 (car (cdr (car where)))))
3117 (if (> num-matches 1)
3118 (progn
3119 ;; (car where) will be pushed onto Info-history
3120 ;; when/if they go to another node. Put the other
3121 ;; nodes that were found on the history.
3122 (setq Info-history (nconc (cdr where) Info-history))
3123 (message "Found %d other entr%s. Use %s to see %s."
3124 (1- num-matches)
3125 (if (> num-matches 2) "ies" "y")
3126 (substitute-command-keys "\\[Info-last]")
3127 (if (> num-matches 2) "them" "it")))))
3128 (error "Couldn't find documentation for %s" command))))
3130 ;;;###autoload
3131 (defun Info-goto-emacs-key-command-node (key)
3132 "Go to the node in the Emacs manual which describes the command bound to KEY.
3133 KEY is a string.
3134 Interactively, if the binding is `execute-extended-command', a command is read.
3135 The command is found by looking up in Emacs manual's indices
3136 or in another manual found via COMMAND's `info-file' property or
3137 the variable `Info-file-list-for-emacs'."
3138 (interactive "kFind documentation for key: ")
3139 (let ((command (key-binding key)))
3140 (cond ((null command)
3141 (message "%s is undefined" (key-description key)))
3142 ((and (interactive-p)
3143 (eq command 'execute-extended-command))
3144 (Info-goto-emacs-command-node
3145 (read-command "Find documentation for command: ")))
3147 (Info-goto-emacs-command-node command)))))
3149 (defface Info-title-1-face
3150 '((((type tty pc) (class color)) :foreground "yellow" :weight bold)
3151 (t :height 1.2 :inherit Info-title-2-face))
3152 "Face for Info titles at level 1."
3153 :group 'info)
3155 (defface Info-title-2-face
3156 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
3157 (t :height 1.2 :inherit Info-title-3-face))
3158 "Face for Info titles at level 2."
3159 :group 'info)
3161 (defface Info-title-3-face
3162 '((((type tty pc) (class color)) :weight bold)
3163 (t :height 1.2 :inherit Info-title-4-face))
3164 "Face for Info titles at level 3."
3165 :group 'info)
3167 (defface Info-title-4-face
3168 '((((type tty pc) (class color)) :weight bold)
3169 (t :weight bold :inherit variable-pitch))
3170 "Face for Info titles at level 4."
3171 :group 'info)
3173 (defface info-menu-header
3174 '((((type tty pc))
3175 :underline t
3176 :weight bold)
3178 :inherit variable-pitch
3179 :weight bold))
3180 "Face for headers in Info menus."
3181 :group 'info)
3183 (defun Info-escape-percent (string)
3184 "Double all occurrences of `%' in STRING.
3186 Return a new string with all `%' characters replaced by `%%'.
3187 Preserve text properties."
3188 (let ((start 0)
3189 (end (length string))
3190 mb me m matches)
3191 (save-match-data
3192 (while (and (< start end) (string-match "%" string start))
3193 (setq mb (match-beginning 0)
3194 me (1+ mb)
3195 m (substring string mb me)
3196 matches (cons m
3197 (cons m
3198 (cons (substring string start mb)
3199 matches)))
3200 start me))
3201 (push (substring string start end) matches)
3202 (apply #'concat (nreverse matches)))))
3204 (defvar Info-next-link-keymap
3205 (let ((keymap (make-sparse-keymap)))
3206 (define-key keymap [header-line mouse-1] 'Info-next)
3207 (define-key keymap [header-line mouse-2] 'Info-next)
3208 (define-key keymap [header-line down-mouse-1] 'ignore)
3209 (define-key keymap [mouse-2] 'Info-next)
3210 keymap)
3211 "Keymap to put on the Next link in the text or the header line.")
3213 (defvar Info-prev-link-keymap
3214 (let ((keymap (make-sparse-keymap)))
3215 (define-key keymap [header-line mouse-1] 'Info-prev)
3216 (define-key keymap [header-line mouse-2] 'Info-prev)
3217 (define-key keymap [header-line down-mouse-1] 'ignore)
3218 (define-key keymap [mouse-2] 'Info-prev)
3219 keymap)
3220 "Keymap to put on the Prev link in the text or the header line.")
3223 (defvar Info-up-link-keymap
3224 (let ((keymap (make-sparse-keymap)))
3225 (define-key keymap [header-line mouse-1] 'Info-up)
3226 (define-key keymap [header-line mouse-2] 'Info-up)
3227 (define-key keymap [header-line down-mouse-1] 'ignore)
3228 (define-key keymap [mouse-2] 'Info-up)
3229 keymap)
3230 "Keymap to put on the Up link in the text or the header line.")
3232 (defun Info-fontify-node ()
3233 "Fontify the node."
3234 (save-excursion
3235 (let* ((inhibit-read-only t)
3236 (case-fold-search t)
3237 paragraph-markers
3238 (not-fontified-p ; the node hasn't already been fontified
3239 (not (let ((where (next-property-change (point-min))))
3240 (and where (not (= where (point-max)))))))
3241 (fontify-visited-p ; visited nodes need to be re-fontified
3242 (and Info-fontify-visited-nodes
3243 ;; Don't take time to refontify visited nodes in huge nodes
3244 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size))))
3246 ;; Fontify header line
3247 (goto-char (point-min))
3248 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3249 (goto-char (match-end 0))
3250 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3251 (goto-char (match-end 0))
3252 (let* ((nbeg (match-beginning 2))
3253 (nend (match-end 2))
3254 (tbeg (match-beginning 1))
3255 (tag (match-string 1)))
3256 (if (string-equal tag "Node")
3257 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3258 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3259 (put-text-property tbeg nend 'mouse-face 'highlight)
3260 (put-text-property tbeg nend
3261 'help-echo
3262 (concat "Go to node "
3263 (buffer-substring nbeg nend)))
3264 ;; Always set up the text property keymap.
3265 ;; It will either be used in the buffer
3266 ;; or copied in the header line.
3267 (put-text-property tbeg nend 'keymap
3268 (cond
3269 ((equal tag "Prev") Info-prev-link-keymap)
3270 ((equal tag "Next") Info-next-link-keymap)
3271 ((equal tag "Up") Info-up-link-keymap))))))
3272 (when Info-use-header-line
3273 (goto-char (point-min))
3274 (let ((header-end (line-end-position))
3275 header)
3276 ;; If we find neither Next: nor Prev: link, show the entire
3277 ;; node header. Otherwise, don't show the File: and Node:
3278 ;; parts, to avoid wasting precious space on information that
3279 ;; is available in the mode line.
3280 (if (re-search-forward
3281 "\\(next\\|up\\|prev[ious]*\\): "
3282 header-end t)
3283 (progn
3284 (goto-char (match-beginning 1))
3285 (setq header (buffer-substring (point) header-end)))
3286 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3287 (setq header
3288 (concat "No next, prev or up links -- "
3289 (buffer-substring (point) header-end)))
3290 (setq header (buffer-substring (point) header-end))))
3291 (put-text-property (point-min) (1+ (point-min))
3292 'header-line (Info-escape-percent header))
3293 ;; Hide the part of the first line
3294 ;; that is in the header, if it is just part.
3295 (unless (bobp)
3296 ;; Hide the punctuation at the end, too.
3297 (skip-chars-backward " \t,")
3298 (put-text-property (point) header-end 'invisible t)))))
3300 ;; Fontify titles
3301 (goto-char (point-min))
3302 (when not-fontified-p
3303 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
3304 nil t)
3305 (let* ((c (preceding-char))
3306 (face
3307 (cond ((= c ?*) 'Info-title-1-face)
3308 ((= c ?=) 'Info-title-2-face)
3309 ((= c ?-) 'Info-title-3-face)
3310 (t 'Info-title-4-face))))
3311 (put-text-property (match-beginning 1) (match-end 1)
3312 'font-lock-face face))
3313 ;; This is a serious problem for trying to handle multiple
3314 ;; frame types at once. We want this text to be invisible
3315 ;; on frames that can display the font above.
3316 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3317 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3318 '(invisible t front-sticky nil rear-nonsticky t)))))
3320 ;; Fontify cross references
3321 (goto-char (point-min))
3322 (when (or not-fontified-p fontify-visited-p)
3323 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3324 (let ((start (match-beginning 0))
3325 (next (point))
3326 other-tag)
3327 (when not-fontified-p
3328 (when Info-hide-note-references
3329 ;; *Note is often used where *note should have been
3330 (goto-char start)
3331 (skip-syntax-backward " ")
3332 (setq other-tag
3333 (cond ((memq (char-before) '(nil ?\. ?! ??))
3334 "See ")
3335 ((memq (char-before) '(?\, ?\; ?\: ?-))
3336 "see ")
3337 ((memq (char-before) '(?\( ?\[ ?\{))
3338 ;; Check whether the paren is preceded by
3339 ;; an end of sentence
3340 (skip-syntax-backward " (")
3341 (if (memq (char-before) '(nil ?\. ?! ??))
3342 "See "
3343 "see "))
3344 ((save-match-data (looking-at "\n\n"))
3345 "See ")))
3346 (goto-char next)
3347 (add-text-properties
3348 (match-beginning 1)
3349 (or (save-match-data
3350 ;; Don't hide \n after *Note
3351 (let ((start1 (match-beginning 1)))
3352 (if (string-match "\n" (match-string 1))
3353 (+ start1 (match-beginning 0)))))
3354 (match-end 1))
3355 (if (and other-tag (not (eq Info-hide-note-references 'hide)))
3356 `(display ,other-tag front-sticky nil rear-nonsticky t)
3357 '(invisible t front-sticky nil rear-nonsticky t))))
3358 (add-text-properties
3359 (match-beginning 2) (match-end 2)
3360 (list
3361 'help-echo (if (or (match-end 5)
3362 (not (equal (match-string 4) "")))
3363 (concat "mouse-2: go to " (or (match-string 5)
3364 (match-string 4)))
3365 "mouse-2: go to this node")
3366 'mouse-face 'highlight)))
3367 (when (or not-fontified-p fontify-visited-p)
3368 (add-text-properties
3369 (match-beginning 2) (match-end 2)
3370 (list
3371 'font-lock-face
3372 ;; Display visited nodes in a different face
3373 (if (and Info-fontify-visited-nodes
3374 (save-match-data
3375 (let* ((node (replace-regexp-in-string
3376 "^[ \t]+" ""
3377 (replace-regexp-in-string
3378 "[ \t\n]+" " "
3379 (or (match-string 5)
3380 (and (not (equal (match-string 4) ""))
3381 (match-string 4))
3382 (match-string 2)))))
3383 (file (file-name-nondirectory
3384 Info-current-file))
3385 (hl Info-history-list)
3386 res)
3387 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3388 (setq file (file-name-nondirectory
3389 (match-string 1 node))
3390 node (if (equal (match-string 2 node) "")
3391 "Top"
3392 (match-string 2 node))))
3393 (while hl
3394 (if (and (string-equal node (nth 1 (car hl)))
3395 (string-equal file
3396 (file-name-nondirectory
3397 (nth 0 (car hl)))))
3398 (setq res (car hl) hl nil)
3399 (setq hl (cdr hl))))
3400 res))) 'info-xref-visited 'info-xref))))
3401 (when not-fontified-p
3402 (when (memq Info-hide-note-references '(t hide))
3403 (add-text-properties (match-beginning 3) (match-end 3)
3404 '(invisible t front-sticky nil rear-nonsticky t))
3405 ;; Unhide the file name of the external reference in parens
3406 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
3407 (remove-text-properties (match-beginning 6) (match-end 6)
3408 '(invisible t front-sticky nil rear-nonsticky t)))
3409 ;; Unhide newline because hidden newlines cause too long lines
3410 (save-match-data
3411 (let ((beg3 (match-beginning 3))
3412 (end3 (match-end 3)))
3413 (if (and (string-match "\n[ \t]*" (match-string 3))
3414 (not (save-match-data
3415 (save-excursion
3416 (goto-char (1+ end3))
3417 (looking-at "[.)]*$")))))
3418 (remove-text-properties (+ beg3 (match-beginning 0))
3419 (+ beg3 (match-end 0))
3420 '(invisible t front-sticky nil rear-nonsticky t))))))
3421 (when (and Info-refill-paragraphs Info-hide-note-references)
3422 (push (set-marker (make-marker) start)
3423 paragraph-markers))))))
3425 ;; Refill paragraphs (experimental feature)
3426 (when (and not-fontified-p
3427 Info-refill-paragraphs
3428 paragraph-markers)
3429 (let ((fill-nobreak-invisible t)
3430 (fill-individual-varying-indent nil)
3431 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3432 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3433 (adaptive-fill-mode nil))
3434 (goto-char (point-max))
3435 (while paragraph-markers
3436 (let ((m (car paragraph-markers)))
3437 (setq paragraph-markers (cdr paragraph-markers))
3438 (when (< m (point))
3439 (goto-char m)
3440 (beginning-of-line)
3441 (let ((beg (point)))
3442 (when (zerop (forward-paragraph))
3443 (fill-individual-paragraphs beg (point) nil nil)
3444 (goto-char beg))))
3445 (set-marker m nil)))))
3447 ;; Fontify menu items
3448 (goto-char (point-min))
3449 (when (and (or not-fontified-p fontify-visited-p)
3450 (search-forward "\n* Menu:" nil t)
3451 (not (string-match "\\<Index\\>" Info-current-node))
3452 ;; Don't take time to annotate huge menus
3453 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3454 (let ((n 0)
3455 cont)
3456 (while (re-search-forward
3457 (concat "^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3458 Info-node-spec-re "\\([ \t]*\\)\\)")
3459 nil t)
3460 (when not-fontified-p
3461 (setq n (1+ n))
3462 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3463 (put-text-property (match-beginning 0)
3464 (1+ (match-beginning 0))
3465 'font-lock-face 'info-menu-5)))
3466 (when not-fontified-p
3467 (add-text-properties
3468 (match-beginning 1) (match-end 1)
3469 (list
3470 'help-echo (if (match-end 3)
3471 (concat "mouse-2: go to " (match-string 3))
3472 "mouse-2: go to this node")
3473 'mouse-face 'highlight)))
3474 (when (or not-fontified-p fontify-visited-p)
3475 (add-text-properties
3476 (match-beginning 1) (match-end 1)
3477 (list
3478 'font-lock-face
3479 ;; Display visited menu items in a different face
3480 (if (and Info-fontify-visited-nodes
3481 (save-match-data
3482 (let ((node (if (equal (match-string 3) "")
3483 (match-string 1)
3484 (match-string 3)))
3485 (file (file-name-nondirectory Info-current-file))
3486 (hl Info-history-list)
3487 res)
3488 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3489 (setq file (file-name-nondirectory
3490 (match-string 1 node))
3491 node (if (equal (match-string 2 node) "")
3492 "Top"
3493 (match-string 2 node))))
3494 (while hl
3495 (if (and (string-equal node (nth 1 (car hl)))
3496 (string-equal file
3497 (file-name-nondirectory
3498 (nth 0 (car hl)))))
3499 (setq res (car hl) hl nil)
3500 (setq hl (cdr hl))))
3501 res))) 'info-xref-visited 'info-xref))))
3502 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3503 (put-text-property (match-beginning 2) (1- (match-end 6))
3504 'invisible t)
3505 ;; Unhide the file name in parens
3506 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3507 (remove-text-properties (match-beginning 4) (match-end 4)
3508 '(invisible t)))
3509 ;; We need a stretchable space like :align-to but with
3510 ;; a minimum value.
3511 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3512 (if (>= 22 (- (match-end 1)
3513 (match-beginning 0)))
3514 '(space :align-to 24)
3515 '(space :width 2)))
3516 (setq cont (looking-at "."))
3517 (while (and (= (forward-line 1) 0)
3518 (looking-at "\\([ \t]+\\)[^*\n]"))
3519 (put-text-property (match-beginning 1) (1- (match-end 1))
3520 'invisible t)
3521 (put-text-property (1- (match-end 1)) (match-end 1)
3522 'display
3523 (if cont
3524 '(space :align-to 26)
3525 '(space :align-to 24)))
3526 (setq cont t))))))
3528 ;; Fontify menu headers
3529 ;; Add the face `info-menu-header' to any header before a menu entry
3530 (goto-char (point-min))
3531 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3532 (put-text-property (match-beginning 0) (match-end 0)
3533 'font-lock-face 'info-menu-header)
3534 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3535 (put-text-property (match-beginning 1) (match-end 1)
3536 'font-lock-face 'info-menu-header)))
3538 ;; Hide index line numbers
3539 (goto-char (point-min))
3540 (when (and not-fontified-p (string-match "\\<Index\\>" Info-current-node))
3541 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3542 (put-text-property (match-beginning 0) (match-end 0)
3543 'invisible t)))
3545 ;; Fontify http and ftp references
3546 (goto-char (point-min))
3547 (when not-fontified-p
3548 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3549 (add-text-properties (match-beginning 0) (match-end 0)
3550 '(font-lock-face info-xref
3551 mouse-face highlight
3552 help-echo "mouse-2: go to this URL"))))
3554 (set-buffer-modified-p nil))))
3557 ;; When an Info buffer is killed, make sure the associated tags buffer
3558 ;; is killed too.
3559 (defun Info-kill-buffer ()
3560 (and (eq major-mode 'Info-mode)
3561 Info-tag-table-buffer
3562 (kill-buffer Info-tag-table-buffer)))
3564 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
3566 ;;; Speedbar support:
3567 ;; These functions permit speedbar to display the "tags" in the
3568 ;; current info node.
3569 (eval-when-compile (require 'speedbar))
3571 (defvar Info-speedbar-key-map nil
3572 "Keymap used when in the info display mode.")
3574 (defun Info-install-speedbar-variables ()
3575 "Install those variables used by speedbar to enhance Info."
3576 (if Info-speedbar-key-map
3578 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3580 ;; Basic tree features
3581 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3582 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3583 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3584 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3587 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3588 Info-speedbar-key-map
3589 Info-speedbar-hierarchy-buttons)))
3591 (defvar Info-speedbar-menu-items
3592 '(["Browse Node" speedbar-edit-line t]
3593 ["Expand Node" speedbar-expand-line
3594 (save-excursion (beginning-of-line)
3595 (looking-at "[0-9]+: *.\\+. "))]
3596 ["Contract Node" speedbar-contract-line
3597 (save-excursion (beginning-of-line)
3598 (looking-at "[0-9]+: *.-. "))]
3600 "Additional menu-items to add to speedbar frame.")
3602 ;; Make sure our special speedbar major mode is loaded
3603 (if (featurep 'speedbar)
3604 (Info-install-speedbar-variables)
3605 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
3607 ;;; Info hierarchy display method
3608 ;;;###autoload
3609 (defun Info-speedbar-browser ()
3610 "Initialize speedbar to display an info node browser.
3611 This will add a speedbar major display mode."
3612 (interactive)
3613 (require 'speedbar)
3614 ;; Make sure that speedbar is active
3615 (speedbar-frame-mode 1)
3616 ;; Now, throw us into Info mode on speedbar.
3617 (speedbar-change-initial-expansion-list "Info")
3620 (eval-when-compile (defvar speedbar-attached-frame))
3622 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
3623 "Display an Info directory hierarchy in speedbar.
3624 DIRECTORY is the current directory in the attached frame.
3625 DEPTH is the current indentation depth.
3626 NODE is an optional argument that is used to represent the
3627 specific node to expand."
3628 (if (and (not node)
3629 (save-excursion (goto-char (point-min))
3630 (let ((case-fold-search t))
3631 (looking-at "Info Nodes:"))))
3632 ;; Update our "current node" maybe?
3634 ;; We cannot use the generic list code, that depends on all leaves
3635 ;; being known at creation time.
3636 (if (not node)
3637 (speedbar-with-writable (insert "Info Nodes:\n")))
3638 (let ((completions nil)
3639 (cf (selected-frame)))
3640 (select-frame speedbar-attached-frame)
3641 (save-window-excursion
3642 (setq completions
3643 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
3644 (select-frame cf)
3645 (if completions
3646 (speedbar-with-writable
3647 (dolist (completion completions)
3648 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
3649 (cdr completion)
3650 (car completion)
3651 'Info-speedbar-goto-node
3652 (cdr completion)
3653 'info-xref depth))
3655 nil))))
3657 (defun Info-speedbar-goto-node (text node indent)
3658 "When user clicks on TEXT, go to an info NODE.
3659 The INDENT level is ignored."
3660 (select-frame speedbar-attached-frame)
3661 (let* ((buff (or (get-buffer "*info*")
3662 (progn (info) (get-buffer "*info*"))))
3663 (bwin (get-buffer-window buff 0)))
3664 (if bwin
3665 (progn
3666 (select-window bwin)
3667 (raise-frame (window-frame bwin)))
3668 (if speedbar-power-click
3669 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3670 (select-frame speedbar-attached-frame)
3671 (switch-to-buffer buff)))
3672 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3673 (error "Invalid node %s" node)
3674 (Info-find-node (match-string 1 node) (match-string 2 node))
3675 ;; If we do a find-node, and we were in info mode, restore
3676 ;; the old default method. Once we are in info mode, it makes
3677 ;; sense to return to whatever method the user was using before.
3678 (if (string= speedbar-initial-expansion-list-name "Info")
3679 (speedbar-change-initial-expansion-list
3680 speedbar-previously-used-expansion-list-name)))))
3682 (defun Info-speedbar-expand-node (text token indent)
3683 "Expand the node the user clicked on.
3684 TEXT is the text of the button we clicked on, a + or - item.
3685 TOKEN is data related to this node (NAME . FILE).
3686 INDENT is the current indentation depth."
3687 (cond ((string-match "+" text) ;we have to expand this file
3688 (speedbar-change-expand-button-char ?-)
3689 (if (speedbar-with-writable
3690 (save-excursion
3691 (end-of-line) (forward-char 1)
3692 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
3693 (speedbar-change-expand-button-char ?-)
3694 (speedbar-change-expand-button-char ??)))
3695 ((string-match "-" text) ;we have to contract this node
3696 (speedbar-change-expand-button-char ?+)
3697 (speedbar-delete-subblock indent))
3698 (t (error "Ooops... not sure what to do")))
3699 (speedbar-center-buffer-smartly))
3701 (defun Info-speedbar-fetch-file-nodes (nodespec)
3702 "Fetch the subnodes from the info NODESPEC.
3703 NODESPEC is a string of the form: (file)node.
3704 Optional THISFILE represends the filename of"
3705 (save-excursion
3706 ;; Set up a buffer we can use to fake-out Info.
3707 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3708 (if (not (equal major-mode 'Info-mode))
3709 (Info-mode))
3710 ;; Get the node into this buffer
3711 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3712 (error "Invalid node specification %s" nodespec)
3713 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
3714 ;; Scan the created buffer
3715 (goto-char (point-min))
3716 (let ((completions nil)
3717 (case-fold-search t)
3718 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3719 (match-string 1 nodespec))))
3720 ;; Always skip the first one...
3721 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3722 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3723 (let ((name (match-string 1)))
3724 (push (cons name
3725 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3726 (match-string 1)
3727 (if (looking-at " *\\(([^)]+)\\)\\.")
3728 (concat (match-string 1) "Top")
3729 (concat "(" thisfile ")"
3730 (if (looking-at " \\([^.]+\\).")
3731 (match-string 1)
3732 name)))))
3733 completions)))
3734 (nreverse completions))))
3736 ;;; Info mode node listing
3737 ;; FIXME: Seems not to be used. -stef
3738 (defun Info-speedbar-buttons (buffer)
3739 "Create a speedbar display to help navigation in an Info file.
3740 BUFFER is the buffer speedbar is requesting buttons for."
3741 (if (save-excursion (goto-char (point-min))
3742 (let ((case-fold-search t))
3743 (not (looking-at "Info Nodes:"))))
3744 (erase-buffer))
3745 (Info-speedbar-hierarchy-buttons nil 0)
3748 (dolist (mess '("^Node has no Previous$"
3749 "^No menu in this node$"
3750 "^Node has no Next$"
3751 "^No cross-references in this node^"
3752 search-failed
3753 "^No \".*\" in index$"))
3754 (add-to-list 'debug-ignored-errors mess))
3756 ;;;; Desktop support
3758 (defun Info-desktop-buffer-misc-data (desktop-dirname)
3759 "Auxiliary information to be saved in desktop file."
3760 (list Info-current-file Info-current-node))
3762 ;;;###autoload
3763 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
3764 desktop-buffer-name
3765 desktop-buffer-misc)
3766 "Restore an info buffer specified in a desktop file."
3767 (let ((first (nth 0 desktop-buffer-misc))
3768 (second (nth 1 desktop-buffer-misc)))
3769 (when (and first second)
3770 (Info-find-node first second)
3771 (current-buffer))))
3773 (provide 'info)
3775 ;;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
3776 ;;; info.el ends here