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