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