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