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