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