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