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