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