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