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