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