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