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