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