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