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