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