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