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