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