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