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