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