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