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