Commit | Line | Data |
---|---|---|
e3431643 | 1 | ;;; info.el --- info package for Emacs. |
e5167999 | 2 | |
3ec18f3f KH |
3 | ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97 Free Software |
4 | ;; 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. |
e5167999 ER |
29 | |
30 | ;;; Code: | |
31 | ||
ded3e3d8 RS |
32 | (defgroup info nil |
33 | "Info subsystem" | |
34 | :group 'help | |
35 | :group 'docs) | |
36 | ||
37 | ||
a384cab3 JB |
38 | (defvar Info-history nil |
39 | "List of info nodes user has visited. | |
40 | Each element of list is a list (FILENAME NODENAME BUFFERPOS).") | |
41 | ||
ded3e3d8 | 42 | (defcustom Info-enable-edit nil |
d5913bf6 | 43 | "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node. |
ada0a60d RS |
44 | This is convenient if you want to write info files by hand. |
45 | However, we recommend that you not do this. | |
46 | It is better to write a Texinfo file and generate the Info file from that, | |
ded3e3d8 RS |
47 | because that gives you a printed manual as well." |
48 | :type 'boolean | |
49 | :group 'info) | |
a384cab3 | 50 | |
67f445d7 | 51 | (defvar Info-enable-active-nodes nil |
a384cab3 JB |
52 | "Non-nil allows Info to execute Lisp code associated with nodes. |
53 | The Lisp code is executed when the node is selected.") | |
67f445d7 | 54 | (put 'Info-enable-active-nodes 'risky-local-variable t) |
a384cab3 | 55 | |
ded3e3d8 RS |
56 | (defcustom Info-fontify t |
57 | "*Non-nil enables highlighting and fonts in Info nodes." | |
58 | :type 'boolean | |
59 | :group 'info) | |
552775bd | 60 | |
93480d70 RS |
61 | (defface info-node |
62 | '((t (:bold t :italic t))) | |
63 | "Face for Info node names." | |
64 | :group 'info) | |
65 | ||
66 | (defface info-menu-5 | |
67 | '((t (:underline t))) | |
68 | "Face for the fifth and tenth `*' in an Info menu." | |
69 | :group 'info) | |
70 | ||
71 | (defface info-xref | |
72 | '((t (:bold t))) | |
73 | "Face for Info cross-references." | |
74 | :group 'info) | |
75 | ||
ded3e3d8 RS |
76 | (defcustom Info-fontify-maximum-menu-size 30000 |
77 | "*Maximum size of menu to fontify if `Info-fontify' is non-nil." | |
78 | :type 'integer | |
79 | :group 'info) | |
bdf62a4d | 80 | |
118199d5 | 81 | (defvar Info-directory-list |
47d53769 | 82 | (let ((path (getenv "INFOPATH")) |
01a2b480 RS |
83 | ;; This is for older Emacs versions |
84 | ;; which might get this info.el from the Texinfo distribution. | |
85 | (path-separator (if (boundp 'path-separator) path-separator | |
86 | (if (eq system-type 'ms-dos) ";" ":"))) | |
0bf65919 | 87 | (source (expand-file-name "info/" source-directory)) |
0e7f9b35 | 88 | (sibling (if installation-directory |
0bf65919 RS |
89 | (expand-file-name "info/" installation-directory))) |
90 | alternative) | |
118199d5 RS |
91 | (if path |
92 | (let ((list nil) | |
93 | idx) | |
94 | (while (> (length path) 0) | |
792e773a | 95 | (setq idx (or (string-match path-separator path) (length path)) |
118199d5 RS |
96 | list (cons (substring path 0 idx) list) |
97 | path (substring path (min (1+ idx) | |
98 | (length path))))) | |
99 | (nreverse list)) | |
0bf65919 RS |
100 | (if (and sibling (file-exists-p sibling)) |
101 | (setq alternative sibling) | |
102 | (setq alternative source)) | |
103 | (if (or (member alternative Info-default-directory-list) | |
104 | (not (file-exists-p alternative)) | |
57f2b3e4 | 105 | ;; On DOS/NT, we use movable executables always, |
718b4478 | 106 | ;; and we must always find the Info dir at run time. |
57f2b3e4 | 107 | (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt)) |
718b4478 RS |
108 | nil |
109 | ;; Use invocation-directory for Info only if we used it for | |
110 | ;; exec-directory also. | |
111 | (not (string= exec-directory | |
0e7f9b35 RS |
112 | (expand-file-name "lib-src/" |
113 | installation-directory))))) | |
47d53769 | 114 | Info-default-directory-list |
0bf65919 RS |
115 | (reverse (cons alternative |
116 | (cdr (reverse Info-default-directory-list))))))) | |
a384cab3 | 117 | "List of directories to search for Info documentation files. |
aea2a8da | 118 | nil means not yet initialized. In this case, Info uses the environment |
44c327f9 | 119 | variable INFOPATH to initialize it, or `Info-default-directory-list' |
e5bd2125 RS |
120 | if there is no INFOPATH variable in the environment. |
121 | The last element of `Info-default-directory-list' is the directory | |
5c11086b | 122 | where Emacs installs the Info files that come with it. |
5da0f945 RS |
123 | |
124 | If you run the Emacs executable from the `src' directory in the Emacs | |
125 | source tree, the `info' directory in the source tree is used as the last | |
126 | element, in place of the installation Info directory. This is useful | |
127 | when you run a version of Emacs without installing it.") | |
a384cab3 | 128 | |
ded3e3d8 | 129 | (defcustom Info-additional-directory-list nil |
bdf62a4d | 130 | "List of additional directories to search for Info documentation files. |
ded3e3d8 RS |
131 | These directories are not searched for merging the `dir' file." |
132 | :type '(repeat directory) | |
133 | :group 'info) | |
bdf62a4d | 134 | |
a384cab3 | 135 | (defvar Info-current-file nil |
d6be34f3 RS |
136 | "Info file that Info is now looking at, or nil. |
137 | This is the name that was specified in Info, not the actual file name. | |
138 | It doesn't contain directory names or file name extensions added by Info.") | |
a384cab3 JB |
139 | |
140 | (defvar Info-current-subfile nil | |
141 | "Info subfile that is actually in the *info* buffer now, | |
142 | or nil if current info file is not split into subfiles.") | |
143 | ||
144 | (defvar Info-current-node nil | |
145 | "Name of node that Info is now looking at, or nil.") | |
146 | ||
c5fe2ff1 | 147 | (defvar Info-tag-table-marker nil |
a384cab3 JB |
148 | "Marker pointing at beginning of current Info file's tag table. |
149 | Marker points nowhere if file has no tag table.") | |
150 | ||
c5fe2ff1 RS |
151 | (defvar Info-tag-table-buffer nil |
152 | "Buffer used for indirect tag tables.") | |
153 | ||
552775bd RS |
154 | (defvar Info-current-file-completions nil |
155 | "Cached completion list for current Info file.") | |
156 | ||
1143a6b0 ER |
157 | (defvar Info-index-alternatives nil |
158 | "List of possible matches for last Info-index command.") | |
159 | ||
552775bd RS |
160 | (defvar Info-standalone nil |
161 | "Non-nil if Emacs was started solely as an Info browser.") | |
162 | ||
bd0c9168 | 163 | (defvar Info-suffix-list |
3c19e6c1 RS |
164 | ;; The MS-DOS list should work both when long file names are |
165 | ;; supported (Windows 9X), and when only 8+3 file names are available. | |
bd0c9168 RS |
166 | (if (eq system-type 'ms-dos) |
167 | '( (".gz" . "gunzip") | |
168 | (".z" . "gunzip") | |
3c19e6c1 RS |
169 | (".inz" . "gunzip") |
170 | (".igz" . "gunzip") | |
171 | (".info.Z" . "gunzip") | |
172 | (".info.gz" . "gunzip") | |
173 | ("-info.Z" . "gunzip") | |
174 | ("-info.gz" . "gunzip") | |
175 | ("/index.gz". "gunzip") | |
176 | ("/index.z" . "gunzip") | |
9b842cab | 177 | (".inf" . nil) |
3c19e6c1 RS |
178 | (".info" . nil) |
179 | ("-info" . nil) | |
180 | ("/index" . nil) | |
bd0c9168 | 181 | ("" . nil)) |
a70dc410 RS |
182 | '( (".info.Z". "uncompress") |
183 | (".info.Y". "unyabba") | |
184 | (".info.gz". "gunzip") | |
185 | (".info.z". "gunzip") | |
186 | (".info". nil) | |
187 | ("-info.Z". "uncompress") | |
188 | ("-info.Y". "unyabba") | |
189 | ("-info.gz". "gunzip") | |
190 | ("-info.z". "gunzip") | |
191 | ("-info". nil) | |
192 | ("/index.Z". "uncompress") | |
193 | ("/index.Y". "unyabba") | |
194 | ("/index.gz". "gunzip") | |
195 | ("/index.z". "gunzip") | |
196 | ("/index". nil) | |
197 | (".Z". "uncompress") | |
198 | (".Y". "unyabba") | |
199 | (".gz". "gunzip") | |
200 | (".z". "gunzip") | |
201 | ("". nil))) | |
1143a6b0 ER |
202 | "List of file name suffixes and associated decoding commands. |
203 | Each entry should be (SUFFIX . STRING); the file is given to | |
97f99202 KH |
204 | the command as standard input. If STRING is nil, no decoding is done. |
205 | Because the SUFFIXes are tried in order, the empty string should | |
206 | be last in the list.") | |
1143a6b0 | 207 | |
c8e9dd54 | 208 | ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot. |
bd0c9168 RS |
209 | ;; First, on ms-dos, delete some of the extension in FILENAME |
210 | ;; to make room. | |
211 | (defun info-insert-file-contents-1 (filename suffix) | |
212 | (if (not (eq system-type 'ms-dos)) | |
213 | (concat filename suffix) | |
214 | (let* ((sans-exts (file-name-sans-extension filename)) | |
c8e9dd54 RS |
215 | ;; How long is the extension in FILENAME (not counting the dot). |
216 | (ext-len (max 0 (- (length filename) (length sans-exts) 1))) | |
217 | ext-left) | |
9b842cab | 218 | ;; SUFFIX starts with a dot. If FILENAME already has one, |
1583fe94 | 219 | ;; get rid of the one in SUFFIX (unless suffix is empty). |
c8e9dd54 | 220 | (or (and (<= ext-len 0) |
9b842cab | 221 | (not (eq (aref filename (1- (length filename))) ?.))) |
1583fe94 | 222 | (= (length suffix) 0) |
9b842cab | 223 | (setq suffix (substring suffix 1))) |
c8e9dd54 RS |
224 | ;; How many chars of that extension should we keep? |
225 | (setq ext-left (min ext-len (max 0 (- 3 (length suffix))))) | |
bd0c9168 RS |
226 | ;; Get rid of the rest of the extension, and add SUFFIX. |
227 | (concat (substring filename 0 (- (length filename) | |
228 | (- ext-len ext-left))) | |
229 | suffix)))) | |
230 | ||
1143a6b0 ER |
231 | (defun info-insert-file-contents (filename &optional visit) |
232 | "Insert the contents of an info file in the current buffer. | |
233 | Do the right thing if the file has been compressed or zipped." | |
97f99202 KH |
234 | (let ((tail Info-suffix-list) |
235 | fullname decoder) | |
236 | (if (file-exists-p filename) | |
bd0c9168 RS |
237 | ;; FILENAME exists--see if that name contains a suffix. |
238 | ;; If so, set DECODE accordingly. | |
97f99202 KH |
239 | (progn |
240 | (while (and tail | |
241 | (not (string-match | |
242 | (concat (regexp-quote (car (car tail))) "$") | |
243 | filename))) | |
244 | (setq tail (cdr tail))) | |
245 | (setq fullname filename | |
246 | decoder (cdr (car tail)))) | |
bd0c9168 | 247 | ;; Try adding suffixes to FILENAME and see if we can find something. |
97f99202 | 248 | (while (and tail |
bd0c9168 RS |
249 | (not (file-exists-p (info-insert-file-contents-1 |
250 | filename (car (car tail)))))) | |
97f99202 | 251 | (setq tail (cdr tail))) |
bd0c9168 RS |
252 | ;; If we found a file with a suffix, set DECODER according to the suffix |
253 | ;; and set FULLNAME to the file's actual name. | |
9b842cab | 254 | (setq fullname (info-insert-file-contents-1 filename (car (car tail))) |
97f99202 KH |
255 | decoder (cdr (car tail))) |
256 | (or tail | |
bd0c9168 | 257 | (error "Can't find %s or any compressed version of it" filename))) |
e175bda2 RS |
258 | ;; check for conflict with jka-compr |
259 | (if (and (featurep 'jka-compr) | |
260 | (jka-compr-installed-p) | |
261 | (jka-compr-get-compression-info fullname)) | |
262 | (setq decoder nil)) | |
97f99202 | 263 | (if decoder |
3c19e6c1 RS |
264 | (progn |
265 | (insert-file-contents-literally fullname visit) | |
266 | (let ((buffer-read-only nil) | |
267 | (coding-system-for-write 'no-conversion) | |
268 | (default-directory (or (file-name-directory fullname) | |
269 | default-directory))) | |
270 | (call-process-region (point-min) (point-max) decoder t t))) | |
271 | (insert-file-contents fullname visit)))) | |
1143a6b0 | 272 | |
d282974b | 273 | ;;;###autoload (add-hook 'same-window-buffer-names "*info*") |
211d6309 | 274 | |
a384cab3 JB |
275 | ;;;###autoload |
276 | (defun info (&optional file) | |
277 | "Enter Info, the documentation browser. | |
278 | Optional argument FILE specifies the file to examine; | |
279 | the default is the top-level directory of Info. | |
280 | ||
281 | In interactive use, a prefix argument directs this command | |
e341dab2 RS |
282 | to read a file name from the minibuffer. |
283 | ||
284 | The search path for Info files is in the variable `Info-directory-list'. | |
285 | The top-level Info directory is made by combining all the files named `dir' | |
286 | in all the directories in that path." | |
a384cab3 JB |
287 | (interactive (if current-prefix-arg |
288 | (list (read-file-name "Info file name: " nil nil t)))) | |
a384cab3 JB |
289 | (if file |
290 | (Info-goto-node (concat "(" file ")")) | |
291 | (if (get-buffer "*info*") | |
211d6309 | 292 | (pop-to-buffer "*info*") |
a384cab3 JB |
293 | (Info-directory)))) |
294 | ||
552775bd RS |
295 | ;;;###autoload |
296 | (defun info-standalone () | |
297 | "Run Emacs as a standalone Info reader. | |
298 | Usage: emacs -f info-standalone [filename] | |
299 | In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself." | |
300 | (setq Info-standalone t) | |
301 | (if (and command-line-args-left | |
302 | (not (string-match "^-" (car command-line-args-left)))) | |
303 | (condition-case err | |
304 | (progn | |
305 | (info (car command-line-args-left)) | |
306 | (setq command-line-args-left (cdr command-line-args-left))) | |
307 | (error (send-string-to-terminal | |
308 | (format "%s\n" (if (eq (car-safe err) 'error) | |
309 | (nth 1 err) err))) | |
310 | (save-buffers-kill-emacs))) | |
311 | (info))) | |
312 | ||
a384cab3 JB |
313 | ;; Go to an info node specified as separate filename and nodename. |
314 | ;; no-going-back is non-nil if recovering from an error in this function; | |
315 | ;; it says do not attempt further (recursive) error recovery. | |
316 | (defun Info-find-node (filename nodename &optional no-going-back) | |
317 | ;; Convert filename to lower case if not found as specified. | |
318 | ;; Expand it. | |
319 | (if filename | |
320 | (let (temp temp-downcase found) | |
321 | (setq filename (substitute-in-file-name filename)) | |
f0e1cd33 | 322 | (if (string= (downcase filename) "dir") |
7ea13762 RS |
323 | (setq found t) |
324 | (let ((dirs (if (string-match "^\\./" filename) | |
325 | ;; If specified name starts with `./' | |
326 | ;; then just try current directory. | |
327 | '("./") | |
e175bda2 RS |
328 | (if (file-name-absolute-p filename) |
329 | ;; No point in searching for an | |
330 | ;; absolute file name | |
331 | '(nil) | |
332 | (if Info-additional-directory-list | |
333 | (append Info-directory-list | |
334 | Info-additional-directory-list) | |
335 | Info-directory-list))))) | |
7ea13762 RS |
336 | ;; Search the directory list for file FILENAME. |
337 | (while (and dirs (not found)) | |
338 | (setq temp (expand-file-name filename (car dirs))) | |
339 | (setq temp-downcase | |
340 | (expand-file-name (downcase filename) (car dirs))) | |
341 | ;; Try several variants of specified name. | |
35d4f4e8 RS |
342 | (let ((suffix-list Info-suffix-list)) |
343 | (while (and suffix-list (not found)) | |
344 | (cond ((file-exists-p | |
9b842cab RS |
345 | (info-insert-file-contents-1 |
346 | temp (car (car suffix-list)))) | |
35d4f4e8 RS |
347 | (setq found temp)) |
348 | ((file-exists-p | |
9b842cab RS |
349 | (info-insert-file-contents-1 |
350 | temp-downcase (car (car suffix-list)))) | |
35d4f4e8 RS |
351 | (setq found temp-downcase))) |
352 | (setq suffix-list (cdr suffix-list)))) | |
7ea13762 | 353 | (setq dirs (cdr dirs))))) |
a384cab3 JB |
354 | (if found |
355 | (setq filename found) | |
356 | (error "Info file %s does not exist" filename)))) | |
357 | ;; Record the node we are leaving. | |
358 | (if (and Info-current-file (not no-going-back)) | |
359 | (setq Info-history | |
360 | (cons (list Info-current-file Info-current-node (point)) | |
361 | Info-history))) | |
362 | ;; Go into info buffer. | |
c5fe2ff1 | 363 | (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*")) |
9e5c2f50 | 364 | (buffer-disable-undo (current-buffer)) |
a384cab3 JB |
365 | (or (eq major-mode 'Info-mode) |
366 | (Info-mode)) | |
367 | (widen) | |
368 | (setq Info-current-node nil) | |
369 | (unwind-protect | |
370 | (progn | |
371 | ;; Switch files if necessary | |
372 | (or (null filename) | |
373 | (equal Info-current-file filename) | |
374 | (let ((buffer-read-only nil)) | |
375 | (setq Info-current-file nil | |
376 | Info-current-subfile nil | |
552775bd | 377 | Info-current-file-completions nil |
a384cab3 JB |
378 | buffer-file-name nil) |
379 | (erase-buffer) | |
7ea13762 RS |
380 | (if (eq filename t) |
381 | (Info-insert-dir) | |
1143a6b0 | 382 | (info-insert-file-contents filename t) |
7ea13762 | 383 | (setq default-directory (file-name-directory filename))) |
a384cab3 | 384 | (set-buffer-modified-p nil) |
a384cab3 | 385 | ;; See whether file has a tag table. Record the location if yes. |
a384cab3 JB |
386 | (goto-char (point-max)) |
387 | (forward-line -8) | |
e90d1271 | 388 | ;; Use string-equal, not equal, to ignore text props. |
c5fe2ff1 RS |
389 | (if (not (or (string-equal nodename "*") |
390 | (not | |
391 | (search-forward "\^_\nEnd tag table\n" nil t)))) | |
a384cab3 JB |
392 | (let (pos) |
393 | ;; We have a tag table. Find its beginning. | |
394 | ;; Is this an indirect file? | |
395 | (search-backward "\nTag table:\n") | |
396 | (setq pos (point)) | |
397 | (if (save-excursion | |
398 | (forward-line 2) | |
399 | (looking-at "(Indirect)\n")) | |
400 | ;; It is indirect. Copy it to another buffer | |
401 | ;; and record that the tag table is in that buffer. | |
c5fe2ff1 RS |
402 | (let ((buf (current-buffer)) |
403 | (tagbuf | |
404 | (or Info-tag-table-buffer | |
405 | (generate-new-buffer " *info tag table*")))) | |
406 | (setq Info-tag-table-buffer tagbuf) | |
407 | (save-excursion | |
408 | (set-buffer tagbuf) | |
9e5c2f50 | 409 | (buffer-disable-undo (current-buffer)) |
a384cab3 JB |
410 | (setq case-fold-search t) |
411 | (erase-buffer) | |
c5fe2ff1 RS |
412 | (insert-buffer-substring buf)) |
413 | (set-marker Info-tag-table-marker | |
414 | (match-end 0) tagbuf)) | |
415 | (set-marker Info-tag-table-marker pos))) | |
416 | (set-marker Info-tag-table-marker nil)) | |
a384cab3 | 417 | (setq Info-current-file |
d6be34f3 | 418 | (if (eq filename t) "dir" filename)))) |
e90d1271 RS |
419 | ;; Use string-equal, not equal, to ignore text props. |
420 | (if (string-equal nodename "*") | |
a384cab3 JB |
421 | (progn (setq Info-current-node nodename) |
422 | (Info-set-mode-line)) | |
423 | ;; Search file for a suitable node. | |
a4223f96 RS |
424 | (let ((guesspos (point-min)) |
425 | (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]"))) | |
426 | ;; First get advice from tag table if file has one. | |
427 | ;; Also, if this is an indirect info file, | |
428 | ;; read the proper subfile into this buffer. | |
a384cab3 JB |
429 | (if (marker-position Info-tag-table-marker) |
430 | (save-excursion | |
c5fe2ff1 RS |
431 | (let ((m Info-tag-table-marker) |
432 | found found-mode) | |
433 | (save-excursion | |
434 | (set-buffer (marker-buffer m)) | |
435 | (goto-char m) | |
436 | (beginning-of-line) ;so re-search will work. | |
437 | (setq found (re-search-forward regexp nil t)) | |
438 | (if found | |
439 | (setq guesspos (read (current-buffer)))) | |
440 | (setq found-mode major-mode)) | |
441 | (if found | |
442 | (progn | |
443 | ;; If this is an indirect file, determine | |
444 | ;; which file really holds this node and | |
445 | ;; read it in. | |
446 | (if (not (eq found-mode 'Info-mode)) | |
447 | ;; Note that the current buffer must be | |
448 | ;; the *info* buffer on entry to | |
449 | ;; Info-read-subfile. Thus the hackery | |
450 | ;; above. | |
451 | (setq guesspos (Info-read-subfile guesspos)))) | |
452 | (error "No such node: %s" nodename))))) | |
a4223f96 RS |
453 | (goto-char (max (point-min) (- guesspos 1000))) |
454 | ;; Now search from our advised position (or from beg of buffer) | |
455 | ;; to find the actual node. | |
a384cab3 JB |
456 | (catch 'foo |
457 | (while (search-forward "\n\^_" nil t) | |
458 | (forward-line 1) | |
459 | (let ((beg (point))) | |
460 | (forward-line 1) | |
461 | (if (re-search-backward regexp beg t) | |
462 | (throw 'foo t)))) | |
463 | (error "No such node: %s" nodename))) | |
464 | (Info-select-node))) | |
465 | ;; If we did not finish finding the specified node, | |
466 | ;; go back to the previous one. | |
4db579ab | 467 | (or Info-current-node no-going-back (null Info-history) |
a384cab3 JB |
468 | (let ((hist (car Info-history))) |
469 | (setq Info-history (cdr Info-history)) | |
470 | (Info-find-node (nth 0 hist) (nth 1 hist) t) | |
471 | (goto-char (nth 2 hist))))) | |
472 | (goto-char (point-min))) | |
473 | ||
44c327f9 JB |
474 | ;; Cache the contents of the (virtual) dir file, once we have merged |
475 | ;; it for the first time, so we can save time subsequently. | |
7ea13762 RS |
476 | (defvar Info-dir-contents nil) |
477 | ||
44c327f9 JB |
478 | ;; Cache for the directory we decided to use for the default-directory |
479 | ;; of the merged dir text. | |
480 | (defvar Info-dir-contents-directory nil) | |
481 | ||
c142ab2d RS |
482 | ;; Record the file attributes of all the files from which we |
483 | ;; constructed Info-dir-contents. | |
484 | (defvar Info-dir-file-attributes nil) | |
485 | ||
7ea13762 | 486 | ;; Construct the Info directory node by merging the files named `dir' |
44c327f9 JB |
487 | ;; from various directories. Set the *info* buffer's |
488 | ;; default-directory to the first directory we actually get any text | |
489 | ;; from. | |
7ea13762 | 490 | (defun Info-insert-dir () |
c142ab2d RS |
491 | (if (and Info-dir-contents Info-dir-file-attributes |
492 | ;; Verify that none of the files we used has changed | |
493 | ;; since we used it. | |
494 | (eval (cons 'and | |
495 | (mapcar '(lambda (elt) | |
825d6f08 RS |
496 | (let ((curr (file-attributes (car elt)))) |
497 | ;; Don't compare the access time. | |
498 | (if curr (setcar (nthcdr 4 curr) 0)) | |
499 | (setcar (nthcdr 4 (cdr elt)) 0) | |
500 | (equal (cdr elt) curr))) | |
c142ab2d | 501 | Info-dir-file-attributes)))) |
7ea13762 RS |
502 | (insert Info-dir-contents) |
503 | (let ((dirs Info-directory-list) | |
f4008b6e | 504 | buffers buffer others nodes dirs-done) |
44c327f9 | 505 | |
825d6f08 RS |
506 | (setq Info-dir-file-attributes nil) |
507 | ||
44c327f9 | 508 | ;; Search the directory list for the directory file. |
7ea13762 | 509 | (while dirs |
8d1abb42 RS |
510 | (let ((truename (file-truename (expand-file-name (car dirs))))) |
511 | (or (member truename dirs-done) | |
512 | (member (directory-file-name truename) dirs-done) | |
513 | ;; Try several variants of specified name. | |
514 | ;; Try upcasing, appending `.info', or both. | |
825d6f08 RS |
515 | (let* (file |
516 | (attrs | |
517 | (or | |
518 | (progn (setq file (expand-file-name "dir" truename)) | |
519 | (file-attributes file)) | |
520 | (progn (setq file (expand-file-name "DIR" truename)) | |
521 | (file-attributes file)) | |
522 | (progn (setq file (expand-file-name "dir.info" truename)) | |
523 | (file-attributes file)) | |
524 | (progn (setq file (expand-file-name "DIR.INFO" truename)) | |
525 | (file-attributes file))))) | |
8d1abb42 RS |
526 | (setq dirs-done |
527 | (cons truename | |
528 | (cons (directory-file-name truename) | |
529 | dirs-done))) | |
825d6f08 RS |
530 | (if attrs |
531 | (save-excursion | |
532 | (or buffers | |
533 | (message "Composing main Info directory...")) | |
534 | (set-buffer (generate-new-buffer "info dir")) | |
535 | (insert-file-contents file) | |
536 | (setq buffers (cons (current-buffer) buffers) | |
537 | Info-dir-file-attributes | |
538 | (cons (cons file attrs) | |
539 | Info-dir-file-attributes)))))) | |
3296453b KH |
540 | (or (cdr dirs) (setq Info-dir-contents-directory |
541 | (file-name-as-directory (car dirs)))) | |
825d6f08 RS |
542 | (setq dirs (cdr dirs)))) |
543 | ||
4db579ab | 544 | (or buffers |
81e14cb2 | 545 | (error "Can't find the Info directory node")) |
44c327f9 | 546 | ;; Distinguish the dir file that comes with Emacs from all the |
f4008b6e RS |
547 | ;; others. Yes, that is really what this is supposed to do. |
548 | ;; If it doesn't work, fix it. | |
7ea13762 RS |
549 | (setq buffer (car buffers) |
550 | others (cdr buffers)) | |
44c327f9 | 551 | |
debcea0c KH |
552 | ;; Insert the entire original dir file as a start; note that we've |
553 | ;; already saved its default directory to use as the default | |
554 | ;; directory for the whole concatenation. | |
7ea13762 | 555 | (insert-buffer buffer) |
44c327f9 | 556 | |
7ea13762 RS |
557 | ;; Look at each of the other buffers one by one. |
558 | (while others | |
559 | (let ((other (car others))) | |
560 | ;; In each, find all the menus. | |
561 | (save-excursion | |
562 | (set-buffer other) | |
563 | (goto-char (point-min)) | |
564 | ;; Find each menu, and add an elt to NODES for it. | |
565 | (while (re-search-forward "^\\* Menu:" nil t) | |
566 | (let (beg nodename end) | |
567 | (forward-line 1) | |
568 | (setq beg (point)) | |
3a6ade8a | 569 | (search-backward "\n\^_") |
7ea13762 RS |
570 | (search-forward "Node: ") |
571 | (setq nodename (Info-following-node-name)) | |
3a6ade8a | 572 | (search-forward "\n\^_" nil 'move) |
7ea13762 RS |
573 | (beginning-of-line) |
574 | (setq end (point)) | |
575 | (setq nodes (cons (list nodename other beg end) nodes)))))) | |
576 | (setq others (cdr others))) | |
577 | ;; Add to the main menu a menu item for each other node. | |
578 | (re-search-forward "^\\* Menu:") | |
579 | (forward-line 1) | |
580 | (let ((menu-items '("top")) | |
581 | (nodes nodes) | |
582 | (case-fold-search t) | |
3a6ade8a | 583 | (end (save-excursion (search-forward "\^_" nil t) (point)))) |
7ea13762 RS |
584 | (while nodes |
585 | (let ((nodename (car (car nodes)))) | |
c3a29d70 RS |
586 | (save-excursion |
587 | (or (member (downcase nodename) menu-items) | |
588 | (re-search-forward (concat "^\\* " | |
589 | (regexp-quote nodename) | |
590 | "::") | |
591 | end t) | |
592 | (progn | |
593 | (insert "* " nodename "::" "\n") | |
594 | (setq menu-items (cons nodename menu-items)))))) | |
7ea13762 RS |
595 | (setq nodes (cdr nodes)))) |
596 | ;; Now take each node of each of the other buffers | |
597 | ;; and merge it into the main buffer. | |
598 | (while nodes | |
599 | (let ((nodename (car (car nodes)))) | |
600 | (goto-char (point-min)) | |
601 | ;; Find the like-named node in the main buffer. | |
3a6ade8a | 602 | (if (re-search-forward (concat "\n\^_.*\n.*Node: " |
7ea13762 RS |
603 | (regexp-quote nodename) |
604 | "[,\n\t]") | |
605 | nil t) | |
606 | (progn | |
3a6ade8a | 607 | (search-forward "\n\^_" nil 'move) |
25869acf RS |
608 | (beginning-of-line) |
609 | (insert "\n")) | |
7ea13762 RS |
610 | ;; If none exists, add one. |
611 | (goto-char (point-max)) | |
dfbf6104 | 612 | (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n")) |
7ea13762 RS |
613 | ;; Merge the text from the other buffer's menu |
614 | ;; into the menu in the like-named node in the main buffer. | |
25869acf | 615 | (apply 'insert-buffer-substring (cdr (car nodes)))) |
7ea13762 RS |
616 | (setq nodes (cdr nodes))) |
617 | ;; Kill all the buffers we just made. | |
618 | (while buffers | |
619 | (kill-buffer (car buffers)) | |
825d6f08 RS |
620 | (setq buffers (cdr buffers))) |
621 | (message "Composing main Info directory...done")) | |
44c327f9 JB |
622 | (setq Info-dir-contents (buffer-string))) |
623 | (setq default-directory Info-dir-contents-directory)) | |
7ea13762 | 624 | |
c5fe2ff1 RS |
625 | ;; Note that on entry to this function the current-buffer must be the |
626 | ;; *info* buffer; not the info tags buffer. | |
a384cab3 | 627 | (defun Info-read-subfile (nodepos) |
a361deba RS |
628 | ;; NODEPOS is either a position (in the Info file as a whole, |
629 | ;; not relative to a subfile) or the name of a subfile. | |
a384cab3 JB |
630 | (let (lastfilepos |
631 | lastfilename) | |
a361deba RS |
632 | (if (numberp nodepos) |
633 | (save-excursion | |
634 | (set-buffer (marker-buffer Info-tag-table-marker)) | |
635 | (goto-char (point-min)) | |
636 | (search-forward "\n\^_") | |
637 | (forward-line 2) | |
638 | (catch 'foo | |
639 | (while (not (looking-at "\^_")) | |
640 | (if (not (eolp)) | |
641 | (let ((beg (point)) | |
642 | thisfilepos thisfilename) | |
643 | (search-forward ": ") | |
644 | (setq thisfilename (buffer-substring beg (- (point) 2))) | |
645 | (setq thisfilepos (read (current-buffer))) | |
646 | ;; read in version 19 stops at the end of number. | |
647 | ;; Advance to the next line. | |
648 | (forward-line 1) | |
649 | (if (> thisfilepos nodepos) | |
650 | (throw 'foo t)) | |
651 | (setq lastfilename thisfilename) | |
652 | (setq lastfilepos thisfilepos)) | |
653 | (forward-line 1))))) | |
654 | (setq lastfilename nodepos) | |
655 | (setq lastfilepos 0)) | |
c5fe2ff1 RS |
656 | ;; Assume previous buffer is in Info-mode. |
657 | ;; (set-buffer (get-buffer "*info*")) | |
a384cab3 JB |
658 | (or (equal Info-current-subfile lastfilename) |
659 | (let ((buffer-read-only nil)) | |
660 | (setq buffer-file-name nil) | |
661 | (widen) | |
662 | (erase-buffer) | |
1143a6b0 | 663 | (info-insert-file-contents lastfilename) |
a384cab3 JB |
664 | (set-buffer-modified-p nil) |
665 | (setq Info-current-subfile lastfilename))) | |
666 | (goto-char (point-min)) | |
667 | (search-forward "\n\^_") | |
a361deba RS |
668 | (if (numberp nodepos) |
669 | (+ (- nodepos lastfilepos) (point))))) | |
a384cab3 JB |
670 | |
671 | ;; Select the info node that point is in. | |
672 | (defun Info-select-node () | |
673 | (save-excursion | |
674 | ;; Find beginning of node. | |
675 | (search-backward "\n\^_") | |
676 | (forward-line 2) | |
677 | ;; Get nodename spelled as it is in the node. | |
678 | (re-search-forward "Node:[ \t]*") | |
679 | (setq Info-current-node | |
70d78eb6 RS |
680 | (buffer-substring-no-properties (point) |
681 | (progn | |
682 | (skip-chars-forward "^,\t\n") | |
683 | (point)))) | |
a384cab3 JB |
684 | (Info-set-mode-line) |
685 | ;; Find the end of it, and narrow. | |
686 | (beginning-of-line) | |
687 | (let (active-expression) | |
688 | (narrow-to-region (point) | |
689 | (if (re-search-forward "\n[\^_\f]" nil t) | |
690 | (prog1 | |
691 | (1- (point)) | |
692 | (if (looking-at "[\n\^_\f]*execute: ") | |
693 | (progn | |
694 | (goto-char (match-end 0)) | |
695 | (setq active-expression | |
696 | (read (current-buffer)))))) | |
697 | (point-max))) | |
f05f43e7 | 698 | (if Info-enable-active-nodes (eval active-expression)) |
552775bd | 699 | (if Info-fontify (Info-fontify-node)) |
f05f43e7 | 700 | (run-hooks 'Info-selection-hook)))) |
a384cab3 JB |
701 | |
702 | (defun Info-set-mode-line () | |
703 | (setq mode-line-buffer-identification | |
704 | (concat | |
a580e884 | 705 | " Info: (" |
a384cab3 JB |
706 | (if Info-current-file |
707 | (file-name-nondirectory Info-current-file) | |
708 | "") | |
709 | ")" | |
710 | (or Info-current-node "")))) | |
711 | \f | |
712 | ;; Go to an info node specified with a filename-and-nodename string | |
713 | ;; of the sort that is found in pointers in nodes. | |
714 | ||
715 | (defun Info-goto-node (nodename) | |
716 | "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME." | |
552775bd | 717 | (interactive (list (Info-read-node-name "Goto node: "))) |
a384cab3 JB |
718 | (let (filename) |
719 | (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)" | |
720 | nodename) | |
721 | (setq filename (if (= (match-beginning 1) (match-end 1)) | |
722 | "" | |
723 | (substring nodename (match-beginning 2) (match-end 2))) | |
724 | nodename (substring nodename (match-beginning 3) (match-end 3))) | |
725 | (let ((trim (string-match "\\s *\\'" filename))) | |
726 | (if trim (setq filename (substring filename 0 trim)))) | |
727 | (let ((trim (string-match "\\s *\\'" nodename))) | |
728 | (if trim (setq nodename (substring nodename 0 trim)))) | |
e579232c | 729 | (if transient-mark-mode (deactivate-mark)) |
a384cab3 JB |
730 | (Info-find-node (if (equal filename "") nil filename) |
731 | (if (equal nodename "") "Top" nodename)))) | |
552775bd | 732 | |
03524be6 RS |
733 | ;; This function is used as the "completion table" while reading a node name. |
734 | ;; It does completion using the alist in completion-table | |
735 | ;; unless STRING starts with an open-paren. | |
736 | (defun Info-read-node-name-1 (string predicate code) | |
737 | (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\()))) | |
738 | (cond ((eq code nil) | |
739 | (if no-completion | |
740 | string | |
741 | (try-completion string completion-table predicate))) | |
742 | ((eq code t) | |
743 | (if no-completion | |
744 | nil | |
745 | (all-completions string completion-table predicate))) | |
746 | ((eq code 'lambda) | |
747 | (if no-completion | |
748 | t | |
749 | (assoc string completion-table)))))) | |
750 | ||
552775bd RS |
751 | (defun Info-read-node-name (prompt &optional default) |
752 | (let* ((completion-ignore-case t) | |
03524be6 | 753 | (completion-table (Info-build-node-completions)) |
b6d61ffa | 754 | (nodename (completing-read prompt 'Info-read-node-name-1 nil t))) |
552775bd RS |
755 | (if (equal nodename "") |
756 | (or default | |
757 | (Info-read-node-name prompt)) | |
758 | nodename))) | |
759 | ||
760 | (defun Info-build-node-completions () | |
761 | (or Info-current-file-completions | |
762 | (let ((compl nil)) | |
763 | (save-excursion | |
764 | (save-restriction | |
765 | (if (marker-buffer Info-tag-table-marker) | |
c5fe2ff1 RS |
766 | (let ((marker Info-tag-table-marker)) |
767 | (set-buffer (marker-buffer marker)) | |
cedb118c | 768 | (widen) |
c5fe2ff1 | 769 | (goto-char marker) |
552775bd RS |
770 | (while (re-search-forward "\nNode: \\(.*\\)\177" nil t) |
771 | (setq compl | |
772 | (cons (list (buffer-substring (match-beginning 1) | |
773 | (match-end 1))) | |
774 | compl)))) | |
775 | (widen) | |
776 | (goto-char (point-min)) | |
777 | (while (search-forward "\n\^_" nil t) | |
778 | (forward-line 1) | |
779 | (let ((beg (point))) | |
780 | (forward-line 1) | |
781 | (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]" | |
782 | beg t) | |
783 | (setq compl | |
784 | (cons (list (buffer-substring (match-beginning 1) | |
785 | (match-end 1))) | |
786 | compl)))))))) | |
787 | (setq Info-current-file-completions compl)))) | |
a384cab3 | 788 | \f |
aea2a8da JB |
789 | (defun Info-restore-point (hl) |
790 | "If this node has been visited, restore the point value when we left." | |
cedb118c RS |
791 | (while hl |
792 | (if (and (equal (nth 0 (car hl)) Info-current-file) | |
e90d1271 RS |
793 | ;; Use string-equal, not equal, to ignore text props. |
794 | (string-equal (nth 1 (car hl)) Info-current-node)) | |
cedb118c | 795 | (progn |
d96504df KH |
796 | (goto-char (nth 2 (car hl))) |
797 | (setq hl nil)) ;terminate the while at next iter | |
cedb118c | 798 | (setq hl (cdr hl))))) |
aea2a8da | 799 | \f |
a384cab3 | 800 | (defvar Info-last-search nil |
d5913bf6 | 801 | "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.") |
a384cab3 JB |
802 | |
803 | (defun Info-search (regexp) | |
804 | "Search for REGEXP, starting from point, and select node it's found in." | |
805 | (interactive "sSearch (regexp): ") | |
e579232c | 806 | (if transient-mark-mode (deactivate-mark)) |
a384cab3 JB |
807 | (if (equal regexp "") |
808 | (setq regexp Info-last-search) | |
809 | (setq Info-last-search regexp)) | |
810 | (let ((found ()) current | |
811 | (onode Info-current-node) | |
812 | (ofile Info-current-file) | |
813 | (opoint (point)) | |
a361deba | 814 | (ostart (window-start)) |
a384cab3 JB |
815 | (osubfile Info-current-subfile)) |
816 | (save-excursion | |
817 | (save-restriction | |
818 | (widen) | |
819 | (if (null Info-current-subfile) | |
820 | (progn (re-search-forward regexp) (setq found (point))) | |
821 | (condition-case err | |
822 | (progn (re-search-forward regexp) (setq found (point))) | |
823 | (search-failed nil))))) | |
824 | (if (not found) ;can only happen in subfile case -- else would have erred | |
825 | (unwind-protect | |
826 | (let ((list ())) | |
c5fe2ff1 RS |
827 | (save-excursion |
828 | (set-buffer (marker-buffer Info-tag-table-marker)) | |
a384cab3 | 829 | (goto-char (point-min)) |
c5fe2ff1 RS |
830 | (search-forward "\n\^_\nIndirect:") |
831 | (save-restriction | |
832 | (narrow-to-region (point) | |
833 | (progn (search-forward "\n\^_") | |
834 | (1- (point)))) | |
835 | (goto-char (point-min)) | |
836 | (search-forward (concat "\n" osubfile ": ")) | |
837 | (beginning-of-line) | |
838 | (while (not (eobp)) | |
839 | (re-search-forward "\\(^.*\\): [0-9]+$") | |
840 | (goto-char (+ (match-end 1) 2)) | |
841 | (setq list (cons (cons (read (current-buffer)) | |
842 | (buffer-substring | |
843 | (match-beginning 1) (match-end 1))) | |
844 | list)) | |
845 | (goto-char (1+ (match-end 0)))) | |
846 | (setq list (nreverse list) | |
847 | current (car (car list)) | |
848 | list (cdr list)))) | |
a384cab3 JB |
849 | (while list |
850 | (message "Searching subfile %s..." (cdr (car list))) | |
851 | (Info-read-subfile (car (car list))) | |
852 | (setq list (cdr list)) | |
dfbf6104 | 853 | ;; (goto-char (point-min)) |
a384cab3 JB |
854 | (if (re-search-forward regexp nil t) |
855 | (setq found (point) list ()))) | |
856 | (if found | |
857 | (message "") | |
858 | (signal 'search-failed (list regexp)))) | |
859 | (if (not found) | |
a361deba | 860 | (progn (Info-read-subfile osubfile) |
a384cab3 | 861 | (goto-char opoint) |
a361deba RS |
862 | (Info-select-node) |
863 | (set-window-start (selected-window) ostart))))) | |
a384cab3 JB |
864 | (widen) |
865 | (goto-char found) | |
866 | (Info-select-node) | |
e90d1271 RS |
867 | ;; Use string-equal, not equal, to ignore text props. |
868 | (or (and (string-equal onode Info-current-node) | |
a384cab3 JB |
869 | (equal ofile Info-current-file)) |
870 | (setq Info-history (cons (list ofile onode opoint) | |
871 | Info-history))))) | |
872 | \f | |
873 | ;; Extract the value of the node-pointer named NAME. | |
874 | ;; If there is none, use ERRORNAME in the error message; | |
875 | ;; if ERRORNAME is nil, just return nil. | |
876 | (defun Info-extract-pointer (name &optional errorname) | |
877 | (save-excursion | |
878 | (goto-char (point-min)) | |
879 | (forward-line 1) | |
880 | (if (re-search-backward (concat name ":") nil t) | |
881 | (progn | |
882 | (goto-char (match-end 0)) | |
883 | (Info-following-node-name)) | |
884 | (if (eq errorname t) | |
885 | nil | |
ce35dad9 | 886 | (error "Node has no %s" (capitalize (or errorname name))))))) |
a384cab3 | 887 | |
7ea13762 RS |
888 | ;; Return the node name in the buffer following point. |
889 | ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp | |
c5fe2ff1 | 890 | ;; saying which chars may appear in the node name. |
a384cab3 JB |
891 | (defun Info-following-node-name (&optional allowedchars) |
892 | (skip-chars-forward " \t") | |
70d78eb6 | 893 | (buffer-substring-no-properties |
a384cab3 JB |
894 | (point) |
895 | (progn | |
896 | (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]")) | |
897 | (skip-chars-forward (concat (or allowedchars "^,\t\n") "(")) | |
898 | (if (looking-at "(") | |
899 | (skip-chars-forward "^)"))) | |
900 | (skip-chars-backward " ") | |
901 | (point)))) | |
902 | ||
903 | (defun Info-next () | |
904 | "Go to the next node of this node." | |
905 | (interactive) | |
906 | (Info-goto-node (Info-extract-pointer "next"))) | |
907 | ||
908 | (defun Info-prev () | |
909 | "Go to the previous node of this node." | |
910 | (interactive) | |
911 | (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))) | |
912 | ||
913 | (defun Info-up () | |
914 | "Go to the superior node of this node." | |
915 | (interactive) | |
aea2a8da JB |
916 | (Info-goto-node (Info-extract-pointer "up")) |
917 | (Info-restore-point Info-history)) | |
a384cab3 JB |
918 | |
919 | (defun Info-last () | |
920 | "Go back to the last node visited." | |
921 | (interactive) | |
922 | (or Info-history | |
923 | (error "This is the first Info node you looked at")) | |
924 | (let (filename nodename opoint) | |
925 | (setq filename (car (car Info-history))) | |
926 | (setq nodename (car (cdr (car Info-history)))) | |
927 | (setq opoint (car (cdr (cdr (car Info-history))))) | |
928 | (setq Info-history (cdr Info-history)) | |
929 | (Info-find-node filename nodename) | |
930 | (setq Info-history (cdr Info-history)) | |
931 | (goto-char opoint))) | |
932 | ||
933 | (defun Info-directory () | |
934 | "Go to the Info directory node." | |
935 | (interactive) | |
936 | (Info-find-node "dir" "top")) | |
937 | \f | |
938 | (defun Info-follow-reference (footnotename) | |
939 | "Follow cross reference named NAME to the node it refers to. | |
940 | NAME may be an abbreviation of the reference name." | |
941 | (interactive | |
942 | (let ((completion-ignore-case t) | |
67bc89ab | 943 | completions default alt-default (start-point (point)) str i bol eol) |
a384cab3 | 944 | (save-excursion |
67bc89ab RS |
945 | ;; Store end and beginning of line. |
946 | (end-of-line) | |
947 | (setq eol (point)) | |
948 | (beginning-of-line) | |
949 | (setq bol (point)) | |
950 | ||
a384cab3 JB |
951 | (goto-char (point-min)) |
952 | (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t) | |
953 | (setq str (buffer-substring | |
954 | (match-beginning 1) | |
955 | (1- (point)))) | |
956 | ;; See if this one should be the default. | |
957 | (and (null default) | |
1f179e27 | 958 | (<= (match-beginning 0) start-point) |
a384cab3 JB |
959 | (<= start-point (point)) |
960 | (setq default t)) | |
67bc89ab RS |
961 | ;; See if this one should be the alternate default. |
962 | (and (null alt-default) | |
963 | (and (<= bol (match-beginning 0)) | |
964 | (<= (point) eol)) | |
965 | (setq alt-default t)) | |
a384cab3 JB |
966 | (setq i 0) |
967 | (while (setq i (string-match "[ \n\t]+" str i)) | |
968 | (setq str (concat (substring str 0 i) " " | |
969 | (substring str (match-end 0)))) | |
970 | (setq i (1+ i))) | |
971 | ;; Record as a completion and perhaps as default. | |
972 | (if (eq default t) (setq default str)) | |
67bc89ab | 973 | (if (eq alt-default t) (setq alt-default str)) |
ec6d29af KH |
974 | ;; Don't add this string if it's a duplicate. |
975 | ;; We use a loop instead of "(assoc str completions)" because | |
976 | ;; we want to do a case-insensitive compare. | |
977 | (let ((tail completions) | |
978 | (tem (downcase str))) | |
979 | (while (and tail | |
980 | (not (string-equal tem (downcase (car (car tail)))))) | |
981 | (setq tail (cdr tail))) | |
982 | (or tail | |
983 | (setq completions | |
984 | (cons (cons str nil) | |
985 | completions)))))) | |
67bc89ab RS |
986 | ;; If no good default was found, try an alternate. |
987 | (or default | |
988 | (setq default alt-default)) | |
989 | ;; If only one cross-reference found, then make it default. | |
990 | (if (eq (length completions) 1) | |
991 | (setq default (car (car completions)))) | |
a384cab3 | 992 | (if completions |
b0ebdfe5 RS |
993 | (let ((input (completing-read (if default |
994 | (concat "Follow reference named: (" | |
995 | default ") ") | |
996 | "Follow reference named: ") | |
997 | completions nil t))) | |
998 | (list (if (equal input "") | |
999 | default input))) | |
a384cab3 | 1000 | (error "No cross-references in this node")))) |
3ffefa79 | 1001 | (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))) |
a384cab3 JB |
1002 | (while (setq i (string-match " " str i)) |
1003 | (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i)))) | |
1004 | (setq i (+ i 6))) | |
1005 | (save-excursion | |
1006 | (goto-char (point-min)) | |
1007 | (or (re-search-forward str nil t) | |
1008 | (error "No cross-reference named %s" footnotename)) | |
1009 | (goto-char (+ (match-beginning 0) 5)) | |
1010 | (setq target | |
1011 | (Info-extract-menu-node-name "Bad format cross reference" t))) | |
1012 | (while (setq i (string-match "[ \t\n]+" target i)) | |
1013 | (setq target (concat (substring target 0 i) " " | |
1014 | (substring target (match-end 0)))) | |
1015 | (setq i (+ i 1))) | |
1016 | (Info-goto-node target))) | |
1017 | ||
1018 | (defun Info-extract-menu-node-name (&optional errmessage multi-line) | |
1019 | (skip-chars-forward " \t\n") | |
1020 | (let ((beg (point)) | |
1021 | str i) | |
1022 | (skip-chars-forward "^:") | |
1023 | (forward-char 1) | |
1024 | (setq str | |
1025 | (if (looking-at ":") | |
70d78eb6 | 1026 | (buffer-substring-no-properties beg (1- (point))) |
a384cab3 JB |
1027 | (skip-chars-forward " \t\n") |
1028 | (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n")))) | |
1029 | (while (setq i (string-match "\n" str i)) | |
1030 | (aset str i ?\ )) | |
2e52ff59 RS |
1031 | ;; Collapse multiple spaces. |
1032 | (while (string-match " +" str) | |
1033 | (setq str (replace-match " " t t str))) | |
a384cab3 JB |
1034 | str)) |
1035 | ||
e8adde3f | 1036 | ;; No one calls this. |
9e5c2f50 RS |
1037 | ;;(defun Info-menu-item-sequence (list) |
1038 | ;; (while list | |
e8adde3f | 1039 | ;; (Info-menu (car list)) |
9e5c2f50 | 1040 | ;; (setq list (cdr list)))) |
a384cab3 | 1041 | |
e8adde3f RS |
1042 | (defun Info-complete-menu-item (string predicate action) |
1043 | (let ((case-fold-search t)) | |
1044 | (cond ((eq action nil) | |
1045 | (let (completions | |
1046 | (pattern (concat "\n\\* \\(" | |
1047 | (regexp-quote string) | |
1048 | "[^:\t\n]*\\):"))) | |
1049 | (save-excursion | |
1050 | (set-buffer Info-complete-menu-buffer) | |
1051 | (goto-char (point-min)) | |
763da090 | 1052 | (search-forward "\n* Menu:") |
e8adde3f RS |
1053 | (while (re-search-forward pattern nil t) |
1054 | (setq completions (cons (cons (format "%s" | |
1055 | (buffer-substring | |
1056 | (match-beginning 1) | |
1057 | (match-end 1))) | |
1058 | (match-beginning 1)) | |
1059 | completions)))) | |
1060 | (try-completion string completions predicate))) | |
1061 | ((eq action t) | |
1062 | (let (completions | |
1063 | (pattern (concat "\n\\* \\(" | |
1064 | (regexp-quote string) | |
1065 | "[^:\t\n]*\\):"))) | |
1066 | (save-excursion | |
1067 | (set-buffer Info-complete-menu-buffer) | |
1068 | (goto-char (point-min)) | |
763da090 | 1069 | (search-forward "\n* Menu:") |
e8adde3f RS |
1070 | (while (re-search-forward pattern nil t) |
1071 | (setq completions (cons (cons (format "%s" | |
1072 | (buffer-substring | |
1073 | (match-beginning 1) | |
1074 | (match-end 1))) | |
1075 | (match-beginning 1)) | |
1076 | completions)))) | |
1077 | (all-completions string completions predicate))) | |
1078 | (t | |
1079 | (save-excursion | |
1080 | (set-buffer Info-complete-menu-buffer) | |
1081 | (goto-char (point-min)) | |
763da090 | 1082 | (search-forward "\n* Menu:") |
e8adde3f RS |
1083 | (re-search-forward (concat "\n\\* " |
1084 | (regexp-quote string) | |
1085 | ":") | |
1086 | nil t)))))) | |
1087 | ||
1088 | ||
a384cab3 JB |
1089 | (defun Info-menu (menu-item) |
1090 | "Go to node for menu item named (or abbreviated) NAME. | |
1091 | Completion is allowed, and the menu item point is on is the default." | |
1092 | (interactive | |
1093 | (let ((completions '()) | |
1094 | ;; If point is within a menu item, use that item as the default | |
1095 | (default nil) | |
1096 | (p (point)) | |
211d6309 | 1097 | beg |
a384cab3 JB |
1098 | (last nil)) |
1099 | (save-excursion | |
1100 | (goto-char (point-min)) | |
1101 | (if (not (search-forward "\n* menu:" nil t)) | |
1102 | (error "No menu in this node")) | |
e8adde3f RS |
1103 | (setq beg (point)) |
1104 | (and (< (point) p) | |
1105 | (save-excursion | |
1106 | (goto-char p) | |
1107 | (end-of-line) | |
1108 | (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t) | |
1109 | (setq default (format "%s" (buffer-substring | |
1110 | (match-beginning 1) | |
1111 | (match-end 1))))))) | |
a384cab3 JB |
1112 | (let ((item nil)) |
1113 | (while (null item) | |
e8adde3f RS |
1114 | (setq item (let ((completion-ignore-case t) |
1115 | (Info-complete-menu-buffer (current-buffer))) | |
a384cab3 JB |
1116 | (completing-read (if default |
1117 | (format "Menu item (default %s): " | |
1118 | default) | |
1119 | "Menu item: ") | |
e8adde3f | 1120 | 'Info-complete-menu-item nil t))) |
aea2a8da JB |
1121 | ;; we rely on the fact that completing-read accepts an input |
1122 | ;; of "" even when the require-match argument is true and "" | |
1123 | ;; is not a valid possibility | |
a384cab3 JB |
1124 | (if (string= item "") |
1125 | (if default | |
1126 | (setq item default) | |
1127 | ;; ask again | |
1128 | (setq item nil)))) | |
1129 | (list item)))) | |
1130 | ;; there is a problem here in that if several menu items have the same | |
1131 | ;; name you can only go to the node of the first with this command. | |
1132 | (Info-goto-node (Info-extract-menu-item menu-item))) | |
1133 | ||
1134 | (defun Info-extract-menu-item (menu-item) | |
1135 | (setq menu-item (regexp-quote menu-item)) | |
1136 | (save-excursion | |
1137 | (goto-char (point-min)) | |
1138 | (or (search-forward "\n* menu:" nil t) | |
1139 | (error "No menu in this node")) | |
de3fa0b2 RS |
1140 | (or (re-search-forward (concat "\n\\* " menu-item ":") nil t) |
1141 | (re-search-forward (concat "\n\\* " menu-item) nil t) | |
a384cab3 JB |
1142 | (error "No such item in menu")) |
1143 | (beginning-of-line) | |
1144 | (forward-char 2) | |
1145 | (Info-extract-menu-node-name))) | |
1146 | ||
1147 | ;; If COUNT is nil, use the last item in the menu. | |
1148 | (defun Info-extract-menu-counting (count) | |
1149 | (save-excursion | |
1150 | (goto-char (point-min)) | |
1151 | (or (search-forward "\n* menu:" nil t) | |
1152 | (error "No menu in this node")) | |
1153 | (if count | |
1154 | (or (search-forward "\n* " nil t count) | |
1155 | (error "Too few items in menu")) | |
1156 | (while (search-forward "\n* " nil t) | |
1157 | nil)) | |
1158 | (Info-extract-menu-node-name))) | |
1159 | ||
e38e7367 RM |
1160 | (defun Info-nth-menu-item () |
1161 | "Go to the node of the Nth menu item. | |
1162 | N is the digit argument used to invoke this command." | |
a384cab3 | 1163 | (interactive) |
e38e7367 RM |
1164 | (Info-goto-node |
1165 | (Info-extract-menu-counting | |
1166 | (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0)))) | |
a384cab3 JB |
1167 | |
1168 | (defun Info-top-node () | |
1169 | "Go to the Top node of this file." | |
1170 | (interactive) | |
1171 | (Info-goto-node "Top")) | |
1172 | ||
1173 | (defun Info-final-node () | |
1174 | "Go to the final node in this file." | |
1175 | (interactive) | |
1176 | (Info-goto-node "Top") | |
1177 | (let (Info-history) | |
1178 | ;; Go to the last node in the menu of Top. | |
1179 | (Info-goto-node (Info-extract-menu-counting nil)) | |
1180 | ;; If the last node in the menu is not last in pointer structure, | |
1181 | ;; move forward until we can't go any farther. | |
1182 | (while (Info-forward-node t t) nil) | |
1183 | ;; Then keep moving down to last subnode, unless we reach an index. | |
1184 | (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
1185 | (save-excursion (search-forward "\n* Menu:" nil t))) | |
1186 | (Info-goto-node (Info-extract-menu-counting nil))))) | |
1187 | ||
1188 | (defun Info-forward-node (&optional not-down no-error) | |
1189 | "Go forward one node, considering all nodes as forming one sequence." | |
1190 | (interactive) | |
1191 | (goto-char (point-min)) | |
1192 | (forward-line 1) | |
1193 | ;; three possibilities, in order of priority: | |
1194 | ;; 1. next node is in a menu in this node (but not in an index) | |
1195 | ;; 2. next node is next at same level | |
1196 | ;; 3. next node is up and next | |
1197 | (cond ((and (not not-down) | |
1198 | (save-excursion (search-forward "\n* menu:" nil t)) | |
1199 | (not (string-match "\\<index\\>" Info-current-node))) | |
463f48f4 | 1200 | (Info-goto-node (Info-extract-menu-counting 1)) |
a384cab3 JB |
1201 | t) |
1202 | ((save-excursion (search-backward "next:" nil t)) | |
1203 | (Info-next) | |
1204 | t) | |
1205 | ((and (save-excursion (search-backward "up:" nil t)) | |
e90d1271 RS |
1206 | ;; Use string-equal, not equal, to ignore text props. |
1207 | (not (string-equal (downcase (Info-extract-pointer "up")) | |
1208 | "top"))) | |
a384cab3 JB |
1209 | (let ((old-node Info-current-node)) |
1210 | (Info-up) | |
1211 | (let (Info-history success) | |
1212 | (unwind-protect | |
1213 | (setq success (Info-forward-node t no-error)) | |
1214 | (or success (Info-goto-node old-node)))))) | |
1215 | (no-error nil) | |
1216 | (t (error "No pointer forward from this node")))) | |
1217 | ||
1218 | (defun Info-backward-node () | |
1219 | "Go backward one node, considering all nodes as forming one sequence." | |
1220 | (interactive) | |
1221 | (let ((prevnode (Info-extract-pointer "prev[ious]*" t)) | |
1222 | (upnode (Info-extract-pointer "up" t))) | |
1223 | (cond ((and upnode (string-match "(" upnode)) | |
1224 | (error "First node in file")) | |
1225 | ((and upnode (or (null prevnode) | |
e90d1271 RS |
1226 | ;; Use string-equal, not equal, |
1227 | ;; to ignore text properties. | |
1228 | (string-equal (downcase prevnode) | |
1229 | (downcase upnode)))) | |
a384cab3 JB |
1230 | (Info-up)) |
1231 | (prevnode | |
1232 | ;; If we move back at the same level, | |
1233 | ;; go down to find the last subnode*. | |
1234 | (Info-prev) | |
1235 | (let (Info-history) | |
1236 | (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
1237 | (save-excursion (search-forward "\n* Menu:" nil t))) | |
1238 | (Info-goto-node (Info-extract-menu-counting nil))))) | |
1239 | (t | |
1240 | (error "No pointer backward from this node"))))) | |
1241 | ||
1242 | (defun Info-exit () | |
1243 | "Exit Info by selecting some other buffer." | |
1244 | (interactive) | |
552775bd RS |
1245 | (if Info-standalone |
1246 | (save-buffers-kill-emacs) | |
ffc43758 | 1247 | (bury-buffer))) |
a384cab3 | 1248 | |
253db917 ER |
1249 | (defun Info-next-menu-item () |
1250 | (interactive) | |
1251 | (save-excursion | |
1252 | (forward-line -1) | |
1253 | (search-forward "\n* menu:" nil t) | |
1254 | (or (search-forward "\n* " nil t) | |
1255 | (error "No more items in menu")) | |
1256 | (Info-goto-node (Info-extract-menu-node-name)))) | |
1257 | ||
1258 | (defun Info-last-menu-item () | |
1259 | (interactive) | |
1260 | (save-excursion | |
1261 | (forward-line 1) | |
0a56332b RS |
1262 | (let ((beg (save-excursion |
1263 | (and (search-backward "\n* menu:" nil t) | |
1264 | (point))))) | |
1265 | (or (and beg (search-backward "\n* " beg t)) | |
1266 | (error "No previous items in menu"))) | |
1267 | (Info-goto-node (save-excursion | |
1268 | (goto-char (match-end 0)) | |
1269 | (Info-extract-menu-node-name))))) | |
253db917 | 1270 | |
552775bd | 1271 | (defmacro Info-no-error (&rest body) |
253db917 ER |
1272 | (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil))) |
1273 | ||
1274 | (defun Info-next-preorder () | |
3c9179ea RS |
1275 | "Go to the next subnode or the next node, or go up a level." |
1276 | (interactive) | |
1277 | (cond ((Info-no-error (Info-next-menu-item))) | |
1278 | ((Info-no-error (Info-next))) | |
1279 | ((Info-no-error (Info-up)) | |
ed690657 KH |
1280 | ;; Since we have already gone thru all the items in this menu, |
1281 | ;; go up to the end of this node. | |
b54d0f0e RS |
1282 | (goto-char (point-max)) |
1283 | ;; Since logically we are done with the node with that menu, | |
1284 | ;; move on from it. | |
1285 | (Info-next-preorder)) | |
3c9179ea RS |
1286 | (t |
1287 | (error "No more nodes")))) | |
253db917 ER |
1288 | |
1289 | (defun Info-last-preorder () | |
1290 | "Go to the last node, popping up a level if there is none." | |
1291 | (interactive) | |
0a56332b RS |
1292 | (cond ((Info-no-error |
1293 | (Info-last-menu-item) | |
1294 | ;; If we go down a menu item, go to the end of the node | |
1295 | ;; so we can scroll back through it. | |
ed690657 | 1296 | (goto-char (point-max))) |
b54d0f0e RS |
1297 | ;; Keep going down, as long as there are nested menu nodes. |
1298 | (while (Info-no-error | |
1299 | (Info-last-menu-item) | |
1300 | ;; If we go down a menu item, go to the end of the node | |
1301 | ;; so we can scroll back through it. | |
1302 | (goto-char (point-max)))) | |
ed690657 KH |
1303 | (recenter -1)) |
1304 | ((Info-no-error (Info-prev)) | |
1305 | (goto-char (point-max)) | |
b54d0f0e RS |
1306 | (while (Info-no-error |
1307 | (Info-last-menu-item) | |
1308 | ;; If we go down a menu item, go to the end of the node | |
1309 | ;; so we can scroll back through it. | |
1310 | (goto-char (point-max)))) | |
ed690657 KH |
1311 | (recenter -1)) |
1312 | ((Info-no-error (Info-up)) | |
1313 | (goto-char (point-min)) | |
1314 | (or (search-forward "\n* Menu:" nil t) | |
1315 | (goto-char (point-max)))) | |
1316 | (t (error "No previous nodes")))) | |
253db917 ER |
1317 | |
1318 | (defun Info-scroll-up () | |
3f32dc86 | 1319 | "Scroll one screenful forward in Info, considering all nodes as one sequence. |
280d11ed RS |
1320 | Once you scroll far enough in a node that its menu appears on the screen |
1321 | but after point, the next scroll moves into its first subnode. | |
1322 | ||
1323 | When you scroll past the end of a node, that goes to the next node; if | |
1324 | this node has no successor, it moves to the parent node's successor, | |
1325 | and so on. If point is inside the menu of a node, it moves to | |
1326 | subnode indicated by the following menu item. (That case won't | |
1327 | normally result from this command, but can happen in other ways.)" | |
1328 | ||
253db917 | 1329 | (interactive) |
0a56332b RS |
1330 | (if (or (< (window-start) (point-min)) |
1331 | (> (window-start) (point-max))) | |
1332 | (set-window-start (selected-window) (point))) | |
1333 | (let ((virtual-end (save-excursion | |
1334 | (goto-char (point-min)) | |
1335 | (if (search-forward "\n* Menu:" nil t) | |
1336 | (point) | |
1337 | (point-max))))) | |
1338 | (if (or (< virtual-end (window-start)) | |
1339 | (pos-visible-in-window-p virtual-end)) | |
1340 | (Info-next-preorder) | |
1341 | (scroll-up)))) | |
253db917 ER |
1342 | |
1343 | (defun Info-scroll-down () | |
3f32dc86 | 1344 | "Scroll one screenful back in Info, considering all nodes as one sequence. |
ed690657 KH |
1345 | Within the menu of a node, this goes to its last subnode. |
1346 | When you scroll past the beginning of a node, that goes to the | |
1347 | previous node or back up to the parent node." | |
253db917 | 1348 | (interactive) |
0a56332b RS |
1349 | (if (or (< (window-start) (point-min)) |
1350 | (> (window-start) (point-max))) | |
1351 | (set-window-start (selected-window) (point))) | |
b54d0f0e RS |
1352 | (let* ((current-point (point)) |
1353 | (virtual-end (save-excursion | |
1354 | (beginning-of-line) | |
1355 | (setq current-point (point)) | |
1356 | (goto-char (point-min)) | |
1357 | (search-forward "\n* Menu:" | |
1358 | current-point | |
1359 | t)))) | |
0a56332b RS |
1360 | (if (or virtual-end (pos-visible-in-window-p (point-min))) |
1361 | (Info-last-preorder) | |
1362 | (scroll-down)))) | |
253db917 | 1363 | |
56cda6f5 | 1364 | (defun Info-next-reference (&optional recur) |
552775bd RS |
1365 | "Move cursor to the next cross-reference or menu item in the node." |
1366 | (interactive) | |
1367 | (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:") | |
1368 | (old-pt (point))) | |
1369 | (or (eobp) (forward-char 1)) | |
1370 | (or (re-search-forward pat nil t) | |
1371 | (progn | |
1372 | (goto-char (point-min)) | |
1373 | (or (re-search-forward pat nil t) | |
1374 | (progn | |
1375 | (goto-char old-pt) | |
1376 | (error "No cross references in this node"))))) | |
1377 | (goto-char (match-beginning 0)) | |
1378 | (if (looking-at "\\* Menu:") | |
56cda6f5 RS |
1379 | (if recur |
1380 | (error "No cross references in this node") | |
1381 | (Info-next-reference t))))) | |
552775bd | 1382 | |
56cda6f5 | 1383 | (defun Info-prev-reference (&optional recur) |
552775bd RS |
1384 | "Move cursor to the previous cross-reference or menu item in the node." |
1385 | (interactive) | |
1386 | (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:") | |
1387 | (old-pt (point))) | |
1388 | (or (re-search-backward pat nil t) | |
1389 | (progn | |
1390 | (goto-char (point-max)) | |
1391 | (or (re-search-backward pat nil t) | |
1392 | (progn | |
1393 | (goto-char old-pt) | |
1394 | (error "No cross references in this node"))))) | |
1395 | (goto-char (match-beginning 0)) | |
1396 | (if (looking-at "\\* Menu:") | |
56cda6f5 RS |
1397 | (if recur |
1398 | (error "No cross references in this node") | |
1399 | (Info-prev-reference t))))) | |
552775bd | 1400 | |
1143a6b0 ER |
1401 | (defun Info-index (topic) |
1402 | "Look up a string in the index for this file. | |
1403 | The index is defined as the first node in the top-level menu whose | |
1404 | name contains the word \"Index\", plus any immediately following | |
1405 | nodes whose names also contain the word \"Index\". | |
1406 | If there are no exact matches to the specified topic, this chooses | |
1407 | the first match which is a case-insensitive substring of a topic. | |
1408 | Use the `,' command to see the other matches. | |
1409 | Give a blank topic name to go to the Index node itself." | |
1410 | (interactive "sIndex topic: ") | |
1411 | (let ((orignode Info-current-node) | |
1412 | (rnode nil) | |
b4d8de7d | 1413 | (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)" |
1143a6b0 ER |
1414 | (regexp-quote topic))) |
1415 | node) | |
1416 | (Info-goto-node "Top") | |
1417 | (or (search-forward "\n* menu:" nil t) | |
1418 | (error "No index")) | |
1419 | (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t) | |
1420 | (error "No index")) | |
1421 | (goto-char (match-beginning 1)) | |
c696ac76 RS |
1422 | ;; Here, and subsequently in this function, |
1423 | ;; we bind Info-history to nil for internal node-switches | |
1424 | ;; so that we don't put junk in the history. | |
1425 | ;; In the first Info-goto-node call, above, we do update the history | |
1426 | ;; because that is what the user's previous node choice into it. | |
1427 | (let ((Info-history nil)) | |
1143a6b0 ER |
1428 | (Info-goto-node (Info-extract-menu-node-name))) |
1429 | (or (equal topic "") | |
1430 | (let ((matches nil) | |
1431 | (exact nil) | |
c696ac76 | 1432 | (Info-history nil) |
1143a6b0 ER |
1433 | found) |
1434 | (while | |
1435 | (progn | |
1436 | (goto-char (point-min)) | |
1437 | (while (re-search-forward pattern nil t) | |
1438 | (setq matches | |
1439 | (cons (list (buffer-substring (match-beginning 1) | |
1440 | (match-end 1)) | |
1441 | (buffer-substring (match-beginning 2) | |
1442 | (match-end 2)) | |
1443 | Info-current-node | |
1444 | (string-to-int (concat "0" | |
1445 | (buffer-substring | |
1446 | (match-beginning 3) | |
1447 | (match-end 3))))) | |
1448 | matches))) | |
1449 | (and (setq node (Info-extract-pointer "next" t)) | |
1450 | (string-match "\\<Index\\>" node))) | |
1451 | (Info-goto-node node)) | |
1452 | (or matches | |
1453 | (progn | |
81e14cb2 | 1454 | (Info-goto-node orignode) |
920bdaab | 1455 | (error "No `%s' in index" topic))) |
1143a6b0 ER |
1456 | ;; Here it is a feature that assoc is case-sensitive. |
1457 | (while (setq found (assoc topic matches)) | |
1458 | (setq exact (cons found exact) | |
1459 | matches (delq found matches))) | |
1460 | (setq Info-index-alternatives (nconc exact (nreverse matches))) | |
1461 | (Info-index-next 0))))) | |
1462 | ||
1463 | (defun Info-index-next (num) | |
1464 | "Go to the next matching index item from the last `i' command." | |
1465 | (interactive "p") | |
1466 | (or Info-index-alternatives | |
882e61bf | 1467 | (error "No previous `i' command")) |
1143a6b0 ER |
1468 | (while (< num 0) |
1469 | (setq num (+ num (length Info-index-alternatives)))) | |
1470 | (while (> num 0) | |
1471 | (setq Info-index-alternatives | |
1472 | (nconc (cdr Info-index-alternatives) | |
1473 | (list (car Info-index-alternatives))) | |
1474 | num (1- num))) | |
1475 | (Info-goto-node (nth 1 (car Info-index-alternatives))) | |
1476 | (if (> (nth 3 (car Info-index-alternatives)) 0) | |
1477 | (forward-line (nth 3 (car Info-index-alternatives))) | |
1478 | (forward-line 3) ; don't search in headers | |
1479 | (let ((name (car (car Info-index-alternatives)))) | |
920bdaab RS |
1480 | (Info-find-index-name name))) |
1481 | (message "Found `%s' in %s. %s" | |
1143a6b0 ER |
1482 | (car (car Info-index-alternatives)) |
1483 | (nth 2 (car Info-index-alternatives)) | |
1484 | (if (cdr Info-index-alternatives) | |
1485 | "(Press `,' for more)" | |
1486 | "(Only match)"))) | |
1487 | ||
920bdaab RS |
1488 | (defun Info-find-index-name (name) |
1489 | "Move point to the place within the current node where NAME is defined." | |
1490 | (if (or (re-search-forward (format | |
1491 | "[a-zA-Z]+: %s\\( \\|$\\)" | |
1492 | (regexp-quote name)) nil t) | |
1493 | (search-forward (format "`%s'" name) nil t) | |
1494 | (and (string-match "\\`.*\\( (.*)\\)\\'" name) | |
1495 | (search-forward | |
1496 | (format "`%s'" (substring name 0 (match-beginning 1))) | |
1497 | nil t)) | |
1498 | (search-forward name nil t)) | |
1499 | (beginning-of-line) | |
1500 | (goto-char (point-min)))) | |
1501 | ||
a384cab3 JB |
1502 | (defun Info-undefined () |
1503 | "Make command be undefined in Info." | |
1504 | (interactive) | |
1505 | (ding)) | |
1506 | ||
1507 | (defun Info-help () | |
1508 | "Enter the Info tutorial." | |
1509 | (interactive) | |
1510 | (delete-other-windows) | |
1511 | (Info-find-node "info" | |
1512 | (if (< (window-height) 23) | |
1513 | "Help-Small-Screen" | |
1514 | "Help"))) | |
1515 | ||
1516 | (defun Info-summary () | |
1517 | "Display a brief summary of all Info commands." | |
1518 | (interactive) | |
1519 | (save-window-excursion | |
1520 | (switch-to-buffer "*Help*") | |
1521 | (erase-buffer) | |
1522 | (insert (documentation 'Info-mode)) | |
9d29f94c | 1523 | (help-mode) |
a384cab3 JB |
1524 | (goto-char (point-min)) |
1525 | (let (ch flag) | |
1526 | (while (progn (setq flag (not (pos-visible-in-window-p (point-max)))) | |
1527 | (message (if flag "Type Space to see more" | |
1528 | "Type Space to return to Info")) | |
1614c867 | 1529 | (if (not (eq ?\ (setq ch (read-event)))) |
dbc4e1c1 | 1530 | (progn (setq unread-command-events (list ch)) nil) |
a384cab3 | 1531 | flag)) |
552775bd RS |
1532 | (scroll-up))) |
1533 | (bury-buffer "*Help*"))) | |
a384cab3 JB |
1534 | \f |
1535 | (defun Info-get-token (pos start all &optional errorstring) | |
1536 | "Return the token around POS, | |
1537 | POS must be somewhere inside the token | |
1538 | START is a regular expression which will match the | |
1539 | beginning of the tokens delimited string | |
1540 | ALL is a regular expression with a single | |
90a715f0 | 1541 | parenthesized subpattern which is the token to be |
a384cab3 JB |
1542 | returned. E.g. '{\(.*\)}' would return any string |
1543 | enclosed in braces around POS. | |
1544 | SIG optional fourth argument, controls action on no match | |
1545 | nil: return nil | |
1546 | t: beep | |
1547 | a string: signal an error, using that string." | |
1548 | (save-excursion | |
1549 | (goto-char pos) | |
345d9d73 RS |
1550 | ;; First look for a match for START that goes across POS. |
1551 | (while (and (not (bobp)) (> (point) (- pos (length start))) | |
1552 | (not (looking-at start))) | |
1553 | (forward-char -1)) | |
1554 | ;; If we did not find one, search back for START | |
1555 | ;; (this finds only matches that end at or before POS). | |
1556 | (or (looking-at start) | |
1557 | (progn | |
1558 | (goto-char pos) | |
1559 | (re-search-backward start (max (point-min) (- pos 200)) 'yes))) | |
373377ed RS |
1560 | (let (found) |
1561 | (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes) | |
1562 | (not (setq found (and (<= (match-beginning 0) pos) | |
1563 | (> (match-end 0) pos)))))) | |
1564 | (if (and found (<= (match-beginning 0) pos) | |
1565 | (> (match-end 0) pos)) | |
1566 | (buffer-substring (match-beginning 1) (match-end 1)) | |
1567 | (cond ((null errorstring) | |
1568 | nil) | |
1569 | ((eq errorstring t) | |
1570 | (beep) | |
1571 | nil) | |
1572 | (t | |
1573 | (error "No %s around position %d" errorstring pos))))))) | |
a384cab3 | 1574 | |
981947af | 1575 | (defun Info-mouse-follow-nearest-node (click) |
f9969361 RS |
1576 | "\\<Info-mode-map>Follow a node reference near point. |
1577 | Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click. | |
981947af | 1578 | At end of the node's text, moves to the next node, or up if none." |
f9969361 | 1579 | (interactive "e") |
9e5c2f50 RS |
1580 | (let* ((start (event-start click)) |
1581 | (window (car start)) | |
1582 | (pos (car (cdr start)))) | |
1583 | (select-window window) | |
1584 | (goto-char pos)) | |
981947af KH |
1585 | (and (not (Info-try-follow-nearest-node)) |
1586 | (save-excursion (forward-line 1) (eobp)) | |
ed690657 | 1587 | (Info-next-preorder))) |
981947af KH |
1588 | |
1589 | (defun Info-follow-nearest-node () | |
1590 | "\\<Info-mode-map>Follow a node reference near point. | |
1591 | Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is. | |
1592 | If no reference to follow, moves to the next node, or up if none." | |
1593 | (interactive) | |
1594 | (or (Info-try-follow-nearest-node) | |
ed690657 | 1595 | (Info-next-preorder))) |
981947af KH |
1596 | |
1597 | ;; Common subroutine. | |
1598 | (defun Info-try-follow-nearest-node () | |
1599 | "Follow a node reference near point. Return non-nil if successful." | |
a384cab3 JB |
1600 | (let (node) |
1601 | (cond | |
981947af KH |
1602 | ((setq node (Info-get-token (point) "\\*note[ \n]" |
1603 | "\\*note[ \n]\\([^:]*\\):")) | |
a384cab3 | 1604 | (Info-follow-reference node)) |
bc2ada62 | 1605 | ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::")) |
a384cab3 | 1606 | (Info-goto-node node)) |
bc2ada62 | 1607 | ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):")) |
a384cab3 | 1608 | (Info-menu node)) |
bc2ada62 | 1609 | ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)")) |
a384cab3 | 1610 | (Info-goto-node node)) |
bc2ada62 | 1611 | ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)")) |
a384cab3 | 1612 | (Info-goto-node node)) |
bc2ada62 | 1613 | ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)")) |
a384cab3 | 1614 | (Info-goto-node "Top")) |
bc2ada62 | 1615 | ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)")) |
981947af KH |
1616 | (Info-goto-node node))) |
1617 | node)) | |
a384cab3 JB |
1618 | \f |
1619 | (defvar Info-mode-map nil | |
1620 | "Keymap containing Info commands.") | |
1621 | (if Info-mode-map | |
1622 | nil | |
1623 | (setq Info-mode-map (make-keymap)) | |
1624 | (suppress-keymap Info-mode-map) | |
1625 | (define-key Info-mode-map "." 'beginning-of-buffer) | |
253db917 | 1626 | (define-key Info-mode-map " " 'Info-scroll-up) |
981947af | 1627 | (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node) |
552775bd RS |
1628 | (define-key Info-mode-map "\t" 'Info-next-reference) |
1629 | (define-key Info-mode-map "\e\t" 'Info-prev-reference) | |
e38e7367 RM |
1630 | (define-key Info-mode-map "1" 'Info-nth-menu-item) |
1631 | (define-key Info-mode-map "2" 'Info-nth-menu-item) | |
1632 | (define-key Info-mode-map "3" 'Info-nth-menu-item) | |
1633 | (define-key Info-mode-map "4" 'Info-nth-menu-item) | |
1634 | (define-key Info-mode-map "5" 'Info-nth-menu-item) | |
1635 | (define-key Info-mode-map "6" 'Info-nth-menu-item) | |
1636 | (define-key Info-mode-map "7" 'Info-nth-menu-item) | |
1637 | (define-key Info-mode-map "8" 'Info-nth-menu-item) | |
1638 | (define-key Info-mode-map "9" 'Info-nth-menu-item) | |
82a4c008 | 1639 | (define-key Info-mode-map "0" 'undefined) |
a384cab3 JB |
1640 | (define-key Info-mode-map "?" 'Info-summary) |
1641 | (define-key Info-mode-map "]" 'Info-forward-node) | |
1642 | (define-key Info-mode-map "[" 'Info-backward-node) | |
1643 | (define-key Info-mode-map "<" 'Info-top-node) | |
1644 | (define-key Info-mode-map ">" 'Info-final-node) | |
1645 | (define-key Info-mode-map "b" 'beginning-of-buffer) | |
1646 | (define-key Info-mode-map "d" 'Info-directory) | |
1647 | (define-key Info-mode-map "e" 'Info-edit) | |
1648 | (define-key Info-mode-map "f" 'Info-follow-reference) | |
1649 | (define-key Info-mode-map "g" 'Info-goto-node) | |
1650 | (define-key Info-mode-map "h" 'Info-help) | |
1143a6b0 | 1651 | (define-key Info-mode-map "i" 'Info-index) |
a384cab3 JB |
1652 | (define-key Info-mode-map "l" 'Info-last) |
1653 | (define-key Info-mode-map "m" 'Info-menu) | |
1654 | (define-key Info-mode-map "n" 'Info-next) | |
1655 | (define-key Info-mode-map "p" 'Info-prev) | |
1656 | (define-key Info-mode-map "q" 'Info-exit) | |
1657 | (define-key Info-mode-map "s" 'Info-search) | |
47fc33ca RS |
1658 | ;; For consistency with Rmail. |
1659 | (define-key Info-mode-map "\M-s" 'Info-search) | |
db0c9809 | 1660 | (define-key Info-mode-map "t" 'Info-top-node) |
a384cab3 | 1661 | (define-key Info-mode-map "u" 'Info-up) |
1143a6b0 | 1662 | (define-key Info-mode-map "," 'Info-index-next) |
803eaf50 | 1663 | (define-key Info-mode-map "\177" 'Info-scroll-down) |
981947af | 1664 | (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node) |
aea2a8da | 1665 | ) |
75a209d4 RS |
1666 | |
1667 | (defun Info-check-pointer (item) | |
1668 | ;; Non-nil if ITEM is present in this node. | |
1669 | (condition-case nil | |
1670 | (Info-extract-pointer item) | |
1671 | (error nil))) | |
1672 | ||
1673 | (easy-menu-define Info-mode-menu Info-mode-map | |
1674 | "Menu for info files." | |
1675 | '("Info" | |
1676 | ["Up" Info-up (Info-check-pointer "up")] | |
1677 | ["Next" Info-next (Info-check-pointer "next")] | |
1678 | ["Previous" Info-prev (Info-check-pointer "prev[ious]*")] | |
1679 | ("Menu item" ["You should never see this" report-emacs-bug t]) | |
1680 | ("Reference" ["You should never see this" report-emacs-bug t]) | |
1681 | ["Search..." Info-search t] | |
1682 | ["Goto node..." Info-goto-node t] | |
1683 | ["Last" Info-last Info-history] | |
1684 | ["Exit" Info-exit t])) | |
1685 | ||
1686 | (defvar Info-menu-last-node nil) | |
1687 | ;; Last node the menu was created for. | |
1688 | ||
1689 | (defun Info-menu-update () | |
1690 | ;; Update the Info menu for the current node. | |
1691 | (condition-case nil | |
1692 | (if (or (not (eq major-mode 'Info-mode)) | |
1693 | (eq Info-current-node Info-menu-last-node)) | |
1694 | () | |
1695 | ;; Update menu menu. | |
1696 | (let* ((Info-complete-menu-buffer (current-buffer)) | |
1697 | (items (nreverse (condition-case nil | |
1698 | (Info-complete-menu-item | |
1699 | "" (lambda (e) t) t) | |
1700 | (error nil)))) | |
1701 | entries current | |
1702 | (number 0)) | |
1703 | (while (and items (< number 9)) | |
1704 | (setq current (car items) | |
1705 | items (cdr items) | |
1706 | number (1+ number)) | |
1707 | (setq entries (cons `[,current | |
1708 | (Info-menu ,current) | |
1709 | :keys ,(format "%d" number)] | |
1710 | entries))) | |
1711 | (if items | |
1712 | (setq entries (cons ["Other..." Info-menu t] entries))) | |
1713 | (or entries | |
1714 | (setq entries (list ["No menu" nil nil]))) | |
1715 | (easy-menu-change '("Info") "Menu item" (nreverse entries))) | |
1716 | ;; Update reference menu. Code stolen from `Info-follow-reference'. | |
1717 | (let ((items nil) | |
1718 | str i entries current | |
1719 | (number 0)) | |
1720 | (save-excursion | |
1721 | (goto-char (point-min)) | |
1722 | (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t) | |
1723 | (setq str (buffer-substring | |
1724 | (match-beginning 1) | |
1725 | (1- (point)))) | |
1726 | (setq i 0) | |
1727 | (while (setq i (string-match "[ \n\t]+" str i)) | |
1728 | (setq str (concat (substring str 0 i) " " | |
1729 | (substring str (match-end 0)))) | |
1730 | (setq i (1+ i))) | |
1731 | (setq items | |
1732 | (cons str items)))) | |
1733 | (while (and items (< number 9)) | |
1734 | (setq current (car items) | |
1735 | items (cdr items) | |
1736 | number (1+ number)) | |
1737 | (setq entries (cons `[,current | |
1738 | (Info-follow-reference ,current) | |
1739 | t] | |
1740 | entries))) | |
1741 | (if items | |
1742 | (setq entries (cons ["Other..." Info-follow-reference t] | |
1743 | entries))) | |
1744 | (or entries | |
1745 | (setq entries (list ["No references" nil nil]))) | |
1746 | (easy-menu-change '("Info") "Reference" (nreverse entries))) | |
1747 | ;; Update last seen node. | |
1748 | (setq Info-menu-last-node (current-buffer))) | |
1749 | ;; Try to avoid entering infinite beep mode in case of errors. | |
1750 | (error (ding)))) | |
1751 | ||
a384cab3 JB |
1752 | \f |
1753 | ;; Info mode is suitable only for specially formatted data. | |
1754 | (put 'info-mode 'mode-class 'special) | |
1755 | ||
1756 | (defun Info-mode () | |
1757 | "\\<Info-mode-map> | |
1758 | Info mode provides commands for browsing through the Info documentation tree. | |
1759 | Documentation in Info is divided into \"nodes\", each of which discusses | |
1760 | one topic and contains references to other nodes which discuss related | |
1761 | topics. Info has commands to follow the references and show you other nodes. | |
1762 | ||
1763 | \\[Info-help] Invoke the Info tutorial. | |
1764 | ||
1765 | Selecting other nodes: | |
21d5959f RS |
1766 | \\[Info-mouse-follow-nearest-node] |
1767 | Follow a node reference you click on. | |
1768 | This works with menu items, cross references, and | |
1769 | the \"next\", \"previous\" and \"up\", depending on where you click. | |
a384cab3 | 1770 | \\[Info-next] Move to the \"next\" node of this node. |
bc2ada62 | 1771 | \\[Info-prev] Move to the \"previous\" node of this node. |
a384cab3 JB |
1772 | \\[Info-up] Move \"up\" from this node. |
1773 | \\[Info-menu] Pick menu item specified by name (or abbreviation). | |
1774 | Picking a menu item causes another node to be selected. | |
aea2a8da | 1775 | \\[Info-directory] Go to the Info directory node. |
a384cab3 JB |
1776 | \\[Info-follow-reference] Follow a cross reference. Reads name of reference. |
1777 | \\[Info-last] Move to the last node you were at. | |
1143a6b0 ER |
1778 | \\[Info-index] Look up a topic in this file's Index and move to that node. |
1779 | \\[Info-index-next] (comma) Move to the next match from a previous `i' command. | |
a384cab3 JB |
1780 | |
1781 | Moving within a node: | |
8884bb82 | 1782 | \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is |
803eaf50 | 1783 | already visible, try to go to the next menu entry, or up if there is none. |
8884bb82 | 1784 | \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is |
803eaf50 ER |
1785 | already visible, try to go to the previous menu entry, or up if there is none. |
1786 | \\[beginning-of-buffer] Go to beginning of node. | |
a384cab3 | 1787 | |
a384cab3 JB |
1788 | Advanced commands: |
1789 | \\[Info-exit] Quit Info: reselect previously selected buffer. | |
1790 | \\[Info-edit] Edit contents of selected node. | |
1791 | 1 Pick first item in node's menu. | |
1792 | 2, 3, 4, 5 Pick second ... fifth item in node's menu. | |
1793 | \\[Info-goto-node] Move to node specified by name. | |
1794 | You may include a filename as well, as (FILENAME)NODENAME. | |
552775bd | 1795 | \\[universal-argument] \\[info] Move to new Info file with completion. |
a384cab3 | 1796 | \\[Info-search] Search through this Info file for specified regexp, |
803eaf50 | 1797 | and select the node in which the next occurrence is found. |
552775bd RS |
1798 | \\[Info-next-reference] Move cursor to next cross-reference or menu item. |
1799 | \\[Info-prev-reference] Move cursor to previous cross-reference or menu item." | |
a384cab3 JB |
1800 | (kill-all-local-variables) |
1801 | (setq major-mode 'Info-mode) | |
1802 | (setq mode-name "Info") | |
f73299f3 | 1803 | (setq tab-width 8) |
a384cab3 | 1804 | (use-local-map Info-mode-map) |
75a209d4 RS |
1805 | (make-local-hook 'activate-menubar-hook) |
1806 | (add-hook 'activate-menubar-hook 'Info-menu-update nil t) | |
a384cab3 JB |
1807 | (set-syntax-table text-mode-syntax-table) |
1808 | (setq local-abbrev-table text-mode-abbrev-table) | |
1809 | (setq case-fold-search t) | |
1810 | (setq buffer-read-only t) | |
a384cab3 JB |
1811 | (make-local-variable 'Info-current-file) |
1812 | (make-local-variable 'Info-current-subfile) | |
1813 | (make-local-variable 'Info-current-node) | |
1814 | (make-local-variable 'Info-tag-table-marker) | |
c5fe2ff1 RS |
1815 | (setq Info-tag-table-marker (make-marker)) |
1816 | (make-local-variable 'Info-tag-table-buffer) | |
1817 | (setq Info-tag-table-buffer nil) | |
a384cab3 | 1818 | (make-local-variable 'Info-history) |
1143a6b0 | 1819 | (make-local-variable 'Info-index-alternatives) |
93480d70 RS |
1820 | ;; This is for the sake of the invisible text we use handling titles. |
1821 | (make-local-variable 'line-move-ignore-invisible) | |
1822 | (setq line-move-ignore-invisible t) | |
a384cab3 JB |
1823 | (Info-set-mode-line) |
1824 | (run-hooks 'Info-mode-hook)) | |
1825 | ||
1826 | (defvar Info-edit-map nil | |
1827 | "Local keymap used within `e' command of Info.") | |
1828 | (if Info-edit-map | |
1829 | nil | |
1830 | (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map)) | |
1831 | (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit)) | |
1832 | ||
1833 | ;; Info-edit mode is suitable only for specially formatted data. | |
1834 | (put 'info-edit-mode 'mode-class 'special) | |
1835 | ||
1836 | (defun Info-edit-mode () | |
1837 | "Major mode for editing the contents of an Info node. | |
a426b157 | 1838 | Like text mode with the addition of `Info-cease-edit' |
a384cab3 JB |
1839 | which returns to Info mode for browsing. |
1840 | \\{Info-edit-map}" | |
a384cab3 JB |
1841 | (use-local-map Info-edit-map) |
1842 | (setq major-mode 'Info-edit-mode) | |
1843 | (setq mode-name "Info Edit") | |
1844 | (kill-local-variable 'mode-line-buffer-identification) | |
1845 | (setq buffer-read-only nil) | |
2c609f53 | 1846 | (force-mode-line-update) |
e82c28f9 KH |
1847 | (buffer-enable-undo (current-buffer)) |
1848 | (run-hooks 'Info-edit-mode-hook)) | |
1849 | ||
1850 | (defun Info-edit () | |
1851 | "Edit the contents of this Info node. | |
1852 | Allowed only if variable `Info-enable-edit' is non-nil." | |
1853 | (interactive) | |
1854 | (or Info-enable-edit | |
1855 | (error "Editing info nodes is not enabled")) | |
1856 | (Info-edit-mode) | |
8ab3e50b | 1857 | (message "%s" (substitute-command-keys |
e82c28f9 | 1858 | "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info"))) |
a384cab3 JB |
1859 | |
1860 | (defun Info-cease-edit () | |
1861 | "Finish editing Info node; switch back to Info proper." | |
1862 | (interactive) | |
1863 | ;; Do this first, so nothing has changed if user C-g's at query. | |
1864 | (and (buffer-modified-p) | |
1865 | (y-or-n-p "Save the file? ") | |
1866 | (save-buffer)) | |
1867 | (use-local-map Info-mode-map) | |
1868 | (setq major-mode 'Info-mode) | |
1869 | (setq mode-name "Info") | |
1870 | (Info-set-mode-line) | |
1871 | (setq buffer-read-only t) | |
2c609f53 | 1872 | (force-mode-line-update) |
a384cab3 JB |
1873 | (and (marker-position Info-tag-table-marker) |
1874 | (buffer-modified-p) | |
1875 | (message "Tags may have changed. Use Info-tagify if necessary"))) | |
f0a8a3f1 | 1876 | \f |
f88ab1c9 RS |
1877 | (defvar Info-file-list-for-emacs |
1878 | '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc") | |
1879 | "List of Info files that describe Emacs commands. | |
1880 | An element can be a file name, or a list of the form (PREFIX . FILE) | |
1881 | where PREFIX is a name prefix and FILE is the file to look in. | |
1882 | If the element is just a file name, the file name also serves as the prefix.") | |
1883 | ||
f0a8a3f1 | 1884 | (defun Info-find-emacs-command-nodes (command) |
f88ab1c9 | 1885 | "Return a list of locations documenting COMMAND. |
f57b2cd8 RS |
1886 | The `info-file' property of COMMAND says which Info manual to search. |
1887 | If COMMAND has no property, the variable `Info-file-list-for-emacs' | |
1888 | defines heuristics for which Info manual to try. | |
f0a8a3f1 RM |
1889 | The locations are of the format used in Info-history, i.e. |
1890 | \(FILENAME NODENAME BUFFERPOS\)." | |
f0a8a3f1 RM |
1891 | (let ((where '()) |
1892 | (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command)) | |
f88ab1c9 RS |
1893 | ":\\s *\\(.*\\)\\.$")) |
1894 | (info-file "emacs")) ;default | |
1895 | ;; Determine which info file this command is documented in. | |
1896 | (if (get command 'info-file) | |
1897 | (setq info-file (get command 'info-file)) | |
1898 | ;; If it doesn't say explicitly, test its name against | |
1899 | ;; various prefixes that we know. | |
1900 | (let ((file-list Info-file-list-for-emacs)) | |
1901 | (while file-list | |
1902 | (let* ((elt (car file-list)) | |
1903 | (name (if (consp elt) | |
1904 | (car elt) | |
1905 | elt)) | |
1906 | (file (if (consp elt) (cdr elt) elt)) | |
f57b2cd8 | 1907 | (regexp (concat "\\`" (regexp-quote name) |
f88ab1c9 RS |
1908 | "\\(\\'\\|-\\)"))) |
1909 | (if (string-match regexp (symbol-name command)) | |
1910 | (setq info-file file file-list nil)) | |
1911 | (setq file-list (cdr file-list)))))) | |
f0a8a3f1 | 1912 | (save-excursion |
f88ab1c9 RS |
1913 | (condition-case nil |
1914 | (Info-find-node info-file "Command Index") | |
1915 | ;; Some manuals may not have a separate Command Index node, | |
1916 | ;; so try just Index instead. | |
1917 | (error | |
1918 | (Info-find-node info-file "Index"))) | |
f0a8a3f1 RM |
1919 | ;; Take the index node off the Info history. |
1920 | (setq Info-history (cdr Info-history)) | |
1921 | (goto-char (point-max)) | |
1922 | (while (re-search-backward cmd-desc nil t) | |
1923 | (setq where (cons (list Info-current-file | |
1924 | (buffer-substring | |
1925 | (match-beginning 1) | |
1926 | (match-end 1)) | |
1927 | 0) | |
1928 | where))) | |
1929 | where))) | |
1930 | ||
1931 | ;;;###autoload | |
1932 | (defun Info-goto-emacs-command-node (command) | |
e0568e86 | 1933 | "Go to the Info node in the Emacs manual for command COMMAND. |
f88ab1c9 | 1934 | The command is found by looking up in Emacs manual's Command Index |
f57b2cd8 RS |
1935 | or in another manual found via COMMAND's `info-file' property or |
1936 | the variable `Info-file-list-for-emacs'." | |
f0a8a3f1 RM |
1937 | (interactive "CFind documentation for command: ") |
1938 | (or (commandp command) | |
1939 | (signal 'wrong-type-argument (list 'commandp command))) | |
1940 | (let ((where (Info-find-emacs-command-nodes command))) | |
1941 | (if where | |
1942 | (let ((num-matches (length where))) | |
1943 | ;; Get Info running, and pop to it in another window. | |
1944 | (save-window-excursion | |
1945 | (info)) | |
c5fe2ff1 RS |
1946 | ;; FIXME It would be cool if this could use a buffer other |
1947 | ;; than *info*. | |
f0a8a3f1 RM |
1948 | (pop-to-buffer "*info*") |
1949 | (Info-find-node (car (car where)) | |
1950 | (car (cdr (car where)))) | |
1951 | (if (> num-matches 1) | |
1952 | (progn | |
1953 | ;; Info-find-node already pushed (car where) onto | |
1954 | ;; Info-history. Put the other nodes that were found on | |
1955 | ;; the history. | |
1956 | (setq Info-history (nconc (cdr where) Info-history)) | |
8ab3e50b | 1957 | (message "Found %d other entr%s. Use %s to see %s." |
cedb118c RS |
1958 | (1- num-matches) |
1959 | (if (> num-matches 2) "ies" "y") | |
8ab3e50b | 1960 | (substitute-command-keys "\\[Info-last]") |
cedb118c | 1961 | (if (> num-matches 2) "them" "it"))))) |
e9b81433 | 1962 | (error "Couldn't find documentation for %s" command)))) |
f0a8a3f1 RM |
1963 | |
1964 | ;;;###autoload | |
1965 | (defun Info-goto-emacs-key-command-node (key) | |
1966 | "Go to the Info node in the Emacs manual the command bound to KEY, a string. | |
e0568e86 | 1967 | Interactively, if the binding is execute-extended-command, a command is read. |
f88ab1c9 | 1968 | The command is found by looking up in Emacs manual's Command Index |
f57b2cd8 RS |
1969 | or in another manual found via COMMAND's `info-file' property or |
1970 | the variable `Info-file-list-for-emacs'." | |
f0a8a3f1 RM |
1971 | (interactive "kFind documentation for key:") |
1972 | (let ((command (key-binding key))) | |
1973 | (cond ((null command) | |
9e5c2f50 | 1974 | (message "%s is undefined" (key-description key))) |
f0a8a3f1 RM |
1975 | ((and (interactive-p) |
1976 | (eq command 'execute-extended-command)) | |
1977 | (Info-goto-emacs-command-node | |
1978 | (read-command "Find documentation for command: "))) | |
1979 | (t | |
1980 | (Info-goto-emacs-command-node command))))) | |
552775bd | 1981 | \f |
ded3e3d8 | 1982 | (defcustom Info-title-face-alist |
98d8273c KH |
1983 | '((?* bold underline) |
1984 | (?= bold-italic underline) | |
1985 | (?- italic underline)) | |
1986 | "*Alist of face or list of faces to use for pseudo-underlined titles. | |
ded3e3d8 RS |
1987 | The alist key is the character the title is underlined with (?*, ?= or ?-)." |
1988 | :type '(repeat (list character face face)) | |
1989 | :group 'info) | |
98d8273c | 1990 | |
552775bd RS |
1991 | (defun Info-fontify-node () |
1992 | (save-excursion | |
1993 | (let ((buffer-read-only nil)) | |
1994 | (goto-char (point-min)) | |
1995 | (if (looking-at "^File: [^,: \t]+,?[ \t]+") | |
1996 | (progn | |
1997 | (goto-char (match-end 0)) | |
1998 | (while | |
1999 | (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?") | |
2000 | (goto-char (match-end 0)) | |
2001 | (put-text-property (match-beginning 1) (match-end 1) | |
9a87b430 RS |
2002 | 'face 'info-xref) |
2003 | (put-text-property (match-beginning 1) (match-end 1) | |
2004 | 'mouse-face 'highlight)))) | |
552775bd | 2005 | (goto-char (point-min)) |
98d8273c KH |
2006 | (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$" |
2007 | nil t) | |
2008 | (put-text-property (match-beginning 1) (match-end 1) | |
2009 | 'face | |
2e518b7d | 2010 | (cdr (assq (preceding-char) Info-title-face-alist))) |
93480d70 RS |
2011 | ;; This is a serious problem for trying to handle multiple |
2012 | ;; frame types at once. We want this text to be invisible | |
2013 | ;; on frames that can display the font above. | |
2014 | (if (memq (framep (selected-frame)) '(x pc w32)) | |
2015 | (put-text-property (match-end 1) (match-end 2) | |
2016 | 'invisible t))) | |
98d8273c | 2017 | (goto-char (point-min)) |
7757c476 | 2018 | (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t) |
552775bd RS |
2019 | (if (= (char-after (1- (match-beginning 0))) ?\") ; hack |
2020 | nil | |
2021 | (put-text-property (match-beginning 1) (match-end 1) | |
9a87b430 RS |
2022 | 'face 'info-xref) |
2023 | (put-text-property (match-beginning 1) (match-end 1) | |
2024 | 'mouse-face 'highlight))) | |
552775bd RS |
2025 | (goto-char (point-min)) |
2026 | (if (and (search-forward "\n* Menu:" nil t) | |
2027 | (not (string-match "\\<Index\\>" Info-current-node)) | |
2028 | ;; Don't take time to annotate huge menus | |
34a0a4ee | 2029 | (< (- (point-max) (point)) Info-fontify-maximum-menu-size)) |
552775bd RS |
2030 | (let ((n 0)) |
2031 | (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t) | |
2032 | (setq n (1+ n)) | |
2033 | (if (memq n '(5 9)) ; visual aids to help with 1-9 keys | |
2034 | (put-text-property (match-beginning 0) | |
2035 | (1+ (match-beginning 0)) | |
2036 | 'face 'info-menu-5)) | |
2037 | (put-text-property (match-beginning 1) (match-end 1) | |
9a87b430 RS |
2038 | 'face 'info-node) |
2039 | (put-text-property (match-beginning 1) (match-end 1) | |
2040 | 'mouse-face 'highlight)))) | |
552775bd | 2041 | (set-buffer-modified-p nil)))) |
c5fe2ff1 RS |
2042 | \f |
2043 | ||
2044 | ;; When an Info buffer is killed, make sure the associated tags buffer | |
2045 | ;; is killed too. | |
2046 | (defun Info-kill-buffer () | |
2047 | (and (eq major-mode 'Info-mode) | |
2048 | Info-tag-table-buffer | |
2049 | (kill-buffer Info-tag-table-buffer))) | |
2050 | ||
2051 | (add-hook 'kill-buffer-hook 'Info-kill-buffer) | |
2052 | ||
49116ac0 JB |
2053 | |
2054 | (provide 'info) | |
2055 | ||
1a06eabd | 2056 | ;;; info.el ends here |