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