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