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