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