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