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