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