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