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