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