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