Mercurial > emacs
annotate lisp/info.el @ 680:f99c8512cd41
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 03 Jun 1992 20:43:49 +0000 |
parents | 08eb386dd0f3 |
children | a8d94735277e |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; info.el --- info package for Emacs -- could use a "create node" feature. |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
325 | 3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 (defvar Info-history nil | |
22 "List of info nodes user has visited. | |
23 Each element of list is a list (FILENAME NODENAME BUFFERPOS).") | |
24 | |
25 (defvar Info-enable-edit nil | |
680
f99c8512cd41
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
26 "*Non-nil means the \\<info-mode-map>\\[Info-edit] command in Info can edit the current node. |
f99c8512cd41
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
27 This is convenient if you want to write info files by hand. |
f99c8512cd41
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
28 However, we recommend that you not do this. |
f99c8512cd41
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
29 It is better to write a Texinfo file and generate the Info file from that, |
f99c8512cd41
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
30 because that gives you a printed manual as well.") |
325 | 31 |
32 (defvar Info-enable-active-nodes t | |
33 "Non-nil allows Info to execute Lisp code associated with nodes. | |
34 The Lisp code is executed when the node is selected.") | |
35 | |
540 | 36 (defvar Info-default-directory-list nil |
37 "List of default directories to search for Info documentation files. | |
38 This value is used as the default for `Info-directory-list'. It is set | |
39 in paths.el.") | |
40 | |
41 (defvar Info-directory-list nil | |
325 | 42 "List of directories to search for Info documentation files. |
540 | 43 nil means not yet initialized. In this case, Info uses the environment |
44 variable INFODIR to initialize it, or `Info-default-directory-list' | |
45 if there is no INFODIR variable in the environment.") | |
325 | 46 |
47 (defvar Info-current-file nil | |
48 "Info file that Info is now looking at, or nil.") | |
49 | |
50 (defvar Info-current-subfile nil | |
51 "Info subfile that is actually in the *info* buffer now, | |
52 or nil if current info file is not split into subfiles.") | |
53 | |
54 (defvar Info-current-node nil | |
55 "Name of node that Info is now looking at, or nil.") | |
56 | |
57 (defvar Info-tag-table-marker (make-marker) | |
58 "Marker pointing at beginning of current Info file's tag table. | |
59 Marker points nowhere if file has no tag table.") | |
60 | |
61 ;;;###autoload | |
62 (defun info (&optional file) | |
63 "Enter Info, the documentation browser. | |
64 Optional argument FILE specifies the file to examine; | |
65 the default is the top-level directory of Info. | |
66 | |
67 In interactive use, a prefix argument directs this command | |
68 to read a file name from the minibuffer." | |
69 (interactive (if current-prefix-arg | |
70 (list (read-file-name "Info file name: " nil nil t)))) | |
540 | 71 (or Info-directory-list |
72 (setq Info-directory-list | |
73 (let ((path (getenv "INFOPATH"))) | |
74 (if path | |
75 (let ((list nil) | |
76 idx) | |
77 (while (> (length path) 0) | |
78 (setq idx (or (string-match ":" path) (length path)) | |
79 list (cons (substring path 0 idx) list) | |
80 path (substring path (min (1+ idx) | |
81 (length path))))) | |
82 (nreverse list)) | |
83 Info-default-directory-list)))) | |
325 | 84 (if file |
85 (Info-goto-node (concat "(" file ")")) | |
86 (if (get-buffer "*info*") | |
87 (switch-to-buffer "*info*") | |
88 (Info-directory)))) | |
89 | |
90 ;; Go to an info node specified as separate filename and nodename. | |
91 ;; no-going-back is non-nil if recovering from an error in this function; | |
92 ;; it says do not attempt further (recursive) error recovery. | |
93 (defun Info-find-node (filename nodename &optional no-going-back) | |
94 ;; Convert filename to lower case if not found as specified. | |
95 ;; Expand it. | |
96 (if filename | |
97 (let (temp temp-downcase found) | |
98 (setq filename (substitute-in-file-name filename)) | |
99 (let ((dirs (if (string-match "^\\./" filename) | |
100 ;; If specified name starts with `./' | |
101 ;; then just try current directory. | |
102 '("./") | |
103 Info-directory-list))) | |
104 ;; Search the directory list for file FILENAME. | |
105 (while (and dirs (not found)) | |
106 (setq temp (expand-file-name filename (car dirs))) | |
107 (setq temp-downcase | |
108 (expand-file-name (downcase filename) (car dirs))) | |
109 ;; Try several variants of specified name. | |
110 ;; Try downcasing, appending `.info', or both. | |
111 (cond ((file-exists-p temp) | |
112 (setq found temp)) | |
113 ((file-exists-p temp-downcase) | |
114 (setq found temp-downcase)) | |
115 ((file-exists-p (concat temp ".info")) | |
116 (setq found (concat temp ".info"))) | |
117 ((file-exists-p (concat temp-downcase ".info")) | |
118 (setq found (concat temp-downcase ".info")))) | |
119 (setq dirs (cdr dirs)))) | |
120 (if found | |
121 (setq filename found) | |
122 (error "Info file %s does not exist" filename)))) | |
123 ;; Record the node we are leaving. | |
124 (if (and Info-current-file (not no-going-back)) | |
125 (setq Info-history | |
126 (cons (list Info-current-file Info-current-node (point)) | |
127 Info-history))) | |
128 ;; Go into info buffer. | |
129 (switch-to-buffer "*info*") | |
130 (buffer-flush-undo (current-buffer)) | |
131 (or (eq major-mode 'Info-mode) | |
132 (Info-mode)) | |
133 (widen) | |
134 (setq Info-current-node nil) | |
135 (unwind-protect | |
136 (progn | |
137 ;; Switch files if necessary | |
138 (or (null filename) | |
139 (equal Info-current-file filename) | |
140 (let ((buffer-read-only nil)) | |
141 (setq Info-current-file nil | |
142 Info-current-subfile nil | |
143 buffer-file-name nil) | |
144 (erase-buffer) | |
145 (insert-file-contents filename t) | |
146 (set-buffer-modified-p nil) | |
147 (setq default-directory (file-name-directory filename)) | |
148 ;; See whether file has a tag table. Record the location if yes. | |
149 (set-marker Info-tag-table-marker nil) | |
150 (goto-char (point-max)) | |
151 (forward-line -8) | |
152 (or (equal nodename "*") | |
153 (not (search-forward "\^_\nEnd tag table\n" nil t)) | |
154 (let (pos) | |
155 ;; We have a tag table. Find its beginning. | |
156 ;; Is this an indirect file? | |
157 (search-backward "\nTag table:\n") | |
158 (setq pos (point)) | |
159 (if (save-excursion | |
160 (forward-line 2) | |
161 (looking-at "(Indirect)\n")) | |
162 ;; It is indirect. Copy it to another buffer | |
163 ;; and record that the tag table is in that buffer. | |
164 (save-excursion | |
165 (let ((buf (current-buffer))) | |
166 (set-buffer (get-buffer-create " *info tag table*")) | |
167 (buffer-flush-undo (current-buffer)) | |
168 (setq case-fold-search t) | |
169 (erase-buffer) | |
170 (insert-buffer-substring buf) | |
171 (set-marker Info-tag-table-marker | |
172 (match-end 0)))) | |
173 (set-marker Info-tag-table-marker pos)))) | |
174 (setq Info-current-file | |
175 (file-name-sans-versions buffer-file-name)))) | |
176 (if (equal nodename "*") | |
177 (progn (setq Info-current-node nodename) | |
178 (Info-set-mode-line)) | |
179 ;; Search file for a suitable node. | |
180 ;; First get advice from tag table if file has one. | |
181 ;; Also, if this is an indirect info file, | |
182 ;; read the proper subfile into this buffer. | |
183 (let ((guesspos (point-min))) | |
184 (if (marker-position Info-tag-table-marker) | |
185 (save-excursion | |
186 (set-buffer (marker-buffer Info-tag-table-marker)) | |
187 (goto-char Info-tag-table-marker) | |
188 (if (search-forward (concat "Node: " nodename "\177") nil t) | |
189 (progn | |
190 (setq guesspos (read (current-buffer))) | |
191 ;; If this is an indirect file, | |
192 ;; determine which file really holds this node | |
193 ;; and read it in. | |
194 (if (not (eq (current-buffer) (get-buffer "*info*"))) | |
195 (setq guesspos | |
196 (Info-read-subfile guesspos)))) | |
197 (error "No such node: \"%s\"" nodename)))) | |
198 (goto-char (max (point-min) (- guesspos 1000)))) | |
199 ;; Now search from our advised position (or from beg of buffer) | |
200 ;; to find the actual node. | |
201 (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]"))) | |
202 (catch 'foo | |
203 (while (search-forward "\n\^_" nil t) | |
204 (forward-line 1) | |
205 (let ((beg (point))) | |
206 (forward-line 1) | |
207 (if (re-search-backward regexp beg t) | |
208 (throw 'foo t)))) | |
209 (error "No such node: %s" nodename))) | |
210 (Info-select-node))) | |
211 ;; If we did not finish finding the specified node, | |
212 ;; go back to the previous one. | |
213 (or Info-current-node no-going-back | |
214 (let ((hist (car Info-history))) | |
215 (setq Info-history (cdr Info-history)) | |
216 (Info-find-node (nth 0 hist) (nth 1 hist) t) | |
217 (goto-char (nth 2 hist))))) | |
218 (goto-char (point-min))) | |
219 | |
220 (defun Info-read-subfile (nodepos) | |
221 (set-buffer (marker-buffer Info-tag-table-marker)) | |
222 (goto-char (point-min)) | |
223 (search-forward "\n\^_") | |
224 (let (lastfilepos | |
225 lastfilename) | |
226 (forward-line 2) | |
227 (catch 'foo | |
228 (while (not (looking-at "\^_")) | |
229 (if (not (eolp)) | |
230 (let ((beg (point)) | |
231 thisfilepos thisfilename) | |
232 (search-forward ": ") | |
233 (setq thisfilename (buffer-substring beg (- (point) 2))) | |
234 (setq thisfilepos (read (current-buffer))) | |
235 ;; read in version 19 stops at the end of number. | |
236 ;; Advance to the next line. | |
237 (forward-line 1) | |
238 (if (> thisfilepos nodepos) | |
239 (throw 'foo t)) | |
240 (setq lastfilename thisfilename) | |
241 (setq lastfilepos thisfilepos)) | |
242 (forward-line 1)))) | |
243 (set-buffer (get-buffer "*info*")) | |
244 (or (equal Info-current-subfile lastfilename) | |
245 (let ((buffer-read-only nil)) | |
246 (setq buffer-file-name nil) | |
247 (widen) | |
248 (erase-buffer) | |
249 (insert-file-contents lastfilename) | |
250 (set-buffer-modified-p nil) | |
251 (setq Info-current-subfile lastfilename))) | |
252 (goto-char (point-min)) | |
253 (search-forward "\n\^_") | |
254 (+ (- nodepos lastfilepos) (point)))) | |
255 | |
256 ;; Select the info node that point is in. | |
257 (defun Info-select-node () | |
258 (save-excursion | |
259 ;; Find beginning of node. | |
260 (search-backward "\n\^_") | |
261 (forward-line 2) | |
262 ;; Get nodename spelled as it is in the node. | |
263 (re-search-forward "Node:[ \t]*") | |
264 (setq Info-current-node | |
265 (buffer-substring (point) | |
266 (progn | |
267 (skip-chars-forward "^,\t\n") | |
268 (point)))) | |
269 (Info-set-mode-line) | |
270 ;; Find the end of it, and narrow. | |
271 (beginning-of-line) | |
272 (let (active-expression) | |
273 (narrow-to-region (point) | |
274 (if (re-search-forward "\n[\^_\f]" nil t) | |
275 (prog1 | |
276 (1- (point)) | |
277 (if (looking-at "[\n\^_\f]*execute: ") | |
278 (progn | |
279 (goto-char (match-end 0)) | |
280 (setq active-expression | |
281 (read (current-buffer)))))) | |
282 (point-max))) | |
283 (if Info-enable-active-nodes (eval active-expression))))) | |
284 | |
285 (defun Info-set-mode-line () | |
286 (setq mode-line-buffer-identification | |
287 (concat | |
288 "Info: (" | |
289 (if Info-current-file | |
290 (file-name-nondirectory Info-current-file) | |
291 "") | |
292 ")" | |
293 (or Info-current-node "")))) | |
294 | |
295 ;; Go to an info node specified with a filename-and-nodename string | |
296 ;; of the sort that is found in pointers in nodes. | |
297 | |
298 (defun Info-goto-node (nodename) | |
299 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME." | |
300 (interactive "sGoto node: ") | |
301 (let (filename) | |
302 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)" | |
303 nodename) | |
304 (setq filename (if (= (match-beginning 1) (match-end 1)) | |
305 "" | |
306 (substring nodename (match-beginning 2) (match-end 2))) | |
307 nodename (substring nodename (match-beginning 3) (match-end 3))) | |
308 (let ((trim (string-match "\\s *\\'" filename))) | |
309 (if trim (setq filename (substring filename 0 trim)))) | |
310 (let ((trim (string-match "\\s *\\'" nodename))) | |
311 (if trim (setq nodename (substring nodename 0 trim)))) | |
312 (Info-find-node (if (equal filename "") nil filename) | |
313 (if (equal nodename "") "Top" nodename)))) | |
314 | |
540 | 315 (defun Info-restore-point (hl) |
316 "If this node has been visited, restore the point value when we left." | |
317 (if hl | |
318 (if (and (equal (nth 0 (car hl)) Info-current-file) | |
319 (equal (nth 1 (car hl)) Info-current-node)) | |
320 (goto-char (nth 2 (car hl))) | |
321 (Info-restore-point (cdr hl))))) | |
322 | |
325 | 323 (defvar Info-last-search nil |
324 "Default regexp for \\<info-mode-map>\\[Info-search] command to search for.") | |
325 | |
326 (defun Info-search (regexp) | |
327 "Search for REGEXP, starting from point, and select node it's found in." | |
328 (interactive "sSearch (regexp): ") | |
329 (if (equal regexp "") | |
330 (setq regexp Info-last-search) | |
331 (setq Info-last-search regexp)) | |
332 (let ((found ()) current | |
333 (onode Info-current-node) | |
334 (ofile Info-current-file) | |
335 (opoint (point)) | |
336 (osubfile Info-current-subfile)) | |
337 (save-excursion | |
338 (save-restriction | |
339 (widen) | |
340 (if (null Info-current-subfile) | |
341 (progn (re-search-forward regexp) (setq found (point))) | |
342 (condition-case err | |
343 (progn (re-search-forward regexp) (setq found (point))) | |
344 (search-failed nil))))) | |
345 (if (not found) ;can only happen in subfile case -- else would have erred | |
346 (unwind-protect | |
347 (let ((list ())) | |
348 (set-buffer (marker-buffer Info-tag-table-marker)) | |
349 (goto-char (point-min)) | |
350 (search-forward "\n\^_\nIndirect:") | |
351 (save-restriction | |
352 (narrow-to-region (point) | |
353 (progn (search-forward "\n\^_") | |
354 (1- (point)))) | |
355 (goto-char (point-min)) | |
356 (search-forward (concat "\n" osubfile ": ")) | |
357 (beginning-of-line) | |
358 (while (not (eobp)) | |
359 (re-search-forward "\\(^.*\\): [0-9]+$") | |
360 (goto-char (+ (match-end 1) 2)) | |
361 (setq list (cons (cons (read (current-buffer)) | |
362 (buffer-substring (match-beginning 1) | |
363 (match-end 1))) | |
364 list)) | |
365 (goto-char (1+ (match-end 0)))) | |
366 (setq list (nreverse list) | |
367 current (car (car list)) | |
368 list (cdr list))) | |
369 (while list | |
370 (message "Searching subfile %s..." (cdr (car list))) | |
371 (Info-read-subfile (car (car list))) | |
372 (setq list (cdr list)) | |
373 (goto-char (point-min)) | |
374 (if (re-search-forward regexp nil t) | |
375 (setq found (point) list ()))) | |
376 (if found | |
377 (message "") | |
378 (signal 'search-failed (list regexp)))) | |
379 (if (not found) | |
380 (progn (Info-read-subfile opoint) | |
381 (goto-char opoint) | |
382 (Info-select-node))))) | |
383 (widen) | |
384 (goto-char found) | |
385 (Info-select-node) | |
386 (or (and (equal onode Info-current-node) | |
387 (equal ofile Info-current-file)) | |
388 (setq Info-history (cons (list ofile onode opoint) | |
389 Info-history))))) | |
390 | |
391 ;; Extract the value of the node-pointer named NAME. | |
392 ;; If there is none, use ERRORNAME in the error message; | |
393 ;; if ERRORNAME is nil, just return nil. | |
394 (defun Info-extract-pointer (name &optional errorname) | |
395 (save-excursion | |
396 (goto-char (point-min)) | |
397 (forward-line 1) | |
398 (if (re-search-backward (concat name ":") nil t) | |
399 (progn | |
400 (goto-char (match-end 0)) | |
401 (Info-following-node-name)) | |
402 (if (eq errorname t) | |
403 nil | |
404 (error (concat "Node has no " (capitalize (or errorname name)))))))) | |
405 | |
406 (defun Info-following-node-name (&optional allowedchars) | |
407 (skip-chars-forward " \t") | |
408 (buffer-substring | |
409 (point) | |
410 (progn | |
411 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]")) | |
412 (skip-chars-forward (concat (or allowedchars "^,\t\n") "(")) | |
413 (if (looking-at "(") | |
414 (skip-chars-forward "^)"))) | |
415 (skip-chars-backward " ") | |
416 (point)))) | |
417 | |
418 (defun Info-next () | |
419 "Go to the next node of this node." | |
420 (interactive) | |
421 (Info-goto-node (Info-extract-pointer "next"))) | |
422 | |
423 (defun Info-prev () | |
424 "Go to the previous node of this node." | |
425 (interactive) | |
426 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))) | |
427 | |
428 (defun Info-up () | |
429 "Go to the superior node of this node." | |
430 (interactive) | |
540 | 431 (Info-goto-node (Info-extract-pointer "up")) |
432 (Info-restore-point Info-history)) | |
325 | 433 |
434 (defun Info-last () | |
435 "Go back to the last node visited." | |
436 (interactive) | |
437 (or Info-history | |
438 (error "This is the first Info node you looked at")) | |
439 (let (filename nodename opoint) | |
440 (setq filename (car (car Info-history))) | |
441 (setq nodename (car (cdr (car Info-history)))) | |
442 (setq opoint (car (cdr (cdr (car Info-history))))) | |
443 (setq Info-history (cdr Info-history)) | |
444 (Info-find-node filename nodename) | |
445 (setq Info-history (cdr Info-history)) | |
446 (goto-char opoint))) | |
447 | |
448 (defun Info-directory () | |
449 "Go to the Info directory node." | |
450 (interactive) | |
451 (Info-find-node "dir" "top")) | |
452 | |
453 (defun Info-follow-reference (footnotename) | |
454 "Follow cross reference named NAME to the node it refers to. | |
455 NAME may be an abbreviation of the reference name." | |
456 (interactive | |
457 (let ((completion-ignore-case t) | |
458 completions default (start-point (point)) str i) | |
459 (save-excursion | |
460 (goto-char (point-min)) | |
461 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t) | |
462 (setq str (buffer-substring | |
463 (match-beginning 1) | |
464 (1- (point)))) | |
465 ;; See if this one should be the default. | |
466 (and (null default) | |
467 (< (match-beginning 0) start-point) | |
468 (<= start-point (point)) | |
469 (setq default t)) | |
470 (setq i 0) | |
471 (while (setq i (string-match "[ \n\t]+" str i)) | |
472 (setq str (concat (substring str 0 i) " " | |
473 (substring str (match-end 0)))) | |
474 (setq i (1+ i))) | |
475 ;; Record as a completion and perhaps as default. | |
476 (if (eq default t) (setq default str)) | |
477 (setq completions | |
478 (cons (cons str nil) | |
479 completions)))) | |
480 (if completions | |
481 (list (completing-read (if default | |
482 (concat "Follow reference named: (" | |
483 default ") ") | |
484 "Follow reference named: ") | |
485 completions default t)) | |
486 (error "No cross-references in this node")))) | |
487 (let (target beg i (str (concat "\\*note " footnotename))) | |
488 (while (setq i (string-match " " str i)) | |
489 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i)))) | |
490 (setq i (+ i 6))) | |
491 (save-excursion | |
492 (goto-char (point-min)) | |
493 (or (re-search-forward str nil t) | |
494 (error "No cross-reference named %s" footnotename)) | |
495 (goto-char (+ (match-beginning 0) 5)) | |
496 (setq target | |
497 (Info-extract-menu-node-name "Bad format cross reference" t))) | |
498 (while (setq i (string-match "[ \t\n]+" target i)) | |
499 (setq target (concat (substring target 0 i) " " | |
500 (substring target (match-end 0)))) | |
501 (setq i (+ i 1))) | |
502 (Info-goto-node target))) | |
503 | |
504 (defun Info-extract-menu-node-name (&optional errmessage multi-line) | |
505 (skip-chars-forward " \t\n") | |
506 (let ((beg (point)) | |
507 str i) | |
508 (skip-chars-forward "^:") | |
509 (forward-char 1) | |
510 (setq str | |
511 (if (looking-at ":") | |
512 (buffer-substring beg (1- (point))) | |
513 (skip-chars-forward " \t\n") | |
514 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n")))) | |
515 (while (setq i (string-match "\n" str i)) | |
516 (aset str i ?\ )) | |
517 str)) | |
518 | |
519 (defun Info-menu-item-sequence (list) | |
520 (while list | |
521 (Info-menu-item (car list)) | |
522 (setq list (cdr list)))) | |
523 | |
524 (defun Info-menu (menu-item) | |
525 "Go to node for menu item named (or abbreviated) NAME. | |
526 Completion is allowed, and the menu item point is on is the default." | |
527 (interactive | |
528 (let ((completions '()) | |
529 ;; If point is within a menu item, use that item as the default | |
530 (default nil) | |
531 (p (point)) | |
532 (last nil)) | |
533 (save-excursion | |
534 (goto-char (point-min)) | |
535 (if (not (search-forward "\n* menu:" nil t)) | |
536 (error "No menu in this node")) | |
537 (while (re-search-forward | |
538 "\n\\* \\([^:\t\n]*\\):" nil t) | |
539 (if (and (null default) | |
540 (prog1 (if last (< last p) nil) | |
541 (setq last (match-beginning 0))) | |
542 (<= p last)) | |
543 (setq default (car (car completions)))) | |
544 (setq completions (cons (cons (buffer-substring | |
545 (match-beginning 1) | |
546 (match-end 1)) | |
547 (match-beginning 1)) | |
548 completions))) | |
549 (if (and (null default) last | |
550 (< last p) | |
551 (<= p (progn (end-of-line) (point)))) | |
552 (setq default (car (car completions))))) | |
553 (let ((item nil)) | |
554 (while (null item) | |
555 (setq item (let ((completion-ignore-case t)) | |
556 (completing-read (if default | |
557 (format "Menu item (default %s): " | |
558 default) | |
559 "Menu item: ") | |
560 completions nil t))) | |
540 | 561 ;; we rely on the fact that completing-read accepts an input |
562 ;; of "" even when the require-match argument is true and "" | |
563 ;; is not a valid possibility | |
325 | 564 (if (string= item "") |
565 (if default | |
566 (setq item default) | |
567 ;; ask again | |
568 (setq item nil)))) | |
569 (list item)))) | |
570 ;; there is a problem here in that if several menu items have the same | |
571 ;; name you can only go to the node of the first with this command. | |
572 (Info-goto-node (Info-extract-menu-item menu-item))) | |
573 | |
574 (defun Info-extract-menu-item (menu-item) | |
575 (setq menu-item (regexp-quote menu-item)) | |
576 (save-excursion | |
577 (goto-char (point-min)) | |
578 (or (search-forward "\n* menu:" nil t) | |
579 (error "No menu in this node")) | |
580 (or (re-search-forward (concat "\n* " menu-item ":") nil t) | |
581 (re-search-forward (concat "\n* " menu-item) nil t) | |
582 (error "No such item in menu")) | |
583 (beginning-of-line) | |
584 (forward-char 2) | |
585 (Info-extract-menu-node-name))) | |
586 | |
587 ;; If COUNT is nil, use the last item in the menu. | |
588 (defun Info-extract-menu-counting (count) | |
589 (save-excursion | |
590 (goto-char (point-min)) | |
591 (or (search-forward "\n* menu:" nil t) | |
592 (error "No menu in this node")) | |
593 (if count | |
594 (or (search-forward "\n* " nil t count) | |
595 (error "Too few items in menu")) | |
596 (while (search-forward "\n* " nil t) | |
597 nil)) | |
598 (Info-extract-menu-node-name))) | |
599 | |
600 (defun Info-first-menu-item () | |
601 "Go to the node of the first menu item." | |
602 (interactive) | |
603 (Info-goto-node (Info-extract-menu-counting 1))) | |
604 | |
605 (defun Info-second-menu-item () | |
606 "Go to the node of the second menu item." | |
607 (interactive) | |
608 (Info-goto-node (Info-extract-menu-counting 2))) | |
609 | |
610 (defun Info-third-menu-item () | |
611 "Go to the node of the third menu item." | |
612 (interactive) | |
613 (Info-goto-node (Info-extract-menu-counting 3))) | |
614 | |
615 (defun Info-fourth-menu-item () | |
616 "Go to the node of the fourth menu item." | |
617 (interactive) | |
618 (Info-goto-node (Info-extract-menu-counting 4))) | |
619 | |
620 (defun Info-fifth-menu-item () | |
621 "Go to the node of the fifth menu item." | |
622 (interactive) | |
623 (Info-goto-node (Info-extract-menu-counting 5))) | |
624 | |
625 (defun Info-top-node () | |
626 "Go to the Top node of this file." | |
627 (interactive) | |
628 (Info-goto-node "Top")) | |
629 | |
630 (defun Info-final-node () | |
631 "Go to the final node in this file." | |
632 (interactive) | |
633 (Info-goto-node "Top") | |
634 (let (Info-history) | |
635 ;; Go to the last node in the menu of Top. | |
636 (Info-goto-node (Info-extract-menu-counting nil)) | |
637 ;; If the last node in the menu is not last in pointer structure, | |
638 ;; move forward until we can't go any farther. | |
639 (while (Info-forward-node t t) nil) | |
640 ;; Then keep moving down to last subnode, unless we reach an index. | |
641 (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
642 (save-excursion (search-forward "\n* Menu:" nil t))) | |
643 (Info-goto-node (Info-extract-menu-counting nil))))) | |
644 | |
645 (defun Info-forward-node (&optional not-down no-error) | |
646 "Go forward one node, considering all nodes as forming one sequence." | |
647 (interactive) | |
648 (goto-char (point-min)) | |
649 (forward-line 1) | |
650 ;; three possibilities, in order of priority: | |
651 ;; 1. next node is in a menu in this node (but not in an index) | |
652 ;; 2. next node is next at same level | |
653 ;; 3. next node is up and next | |
654 (cond ((and (not not-down) | |
655 (save-excursion (search-forward "\n* menu:" nil t)) | |
656 (not (string-match "\\<index\\>" Info-current-node))) | |
657 (Info-first-menu-item) | |
658 t) | |
659 ((save-excursion (search-backward "next:" nil t)) | |
660 (Info-next) | |
661 t) | |
662 ((and (save-excursion (search-backward "up:" nil t)) | |
663 (not (equal (downcase (Info-extract-pointer "up")) "top"))) | |
664 (let ((old-node Info-current-node)) | |
665 (Info-up) | |
666 (let (Info-history success) | |
667 (unwind-protect | |
668 (setq success (Info-forward-node t no-error)) | |
669 (or success (Info-goto-node old-node)))))) | |
670 (no-error nil) | |
671 (t (error "No pointer forward from this node")))) | |
672 | |
673 (defun Info-backward-node () | |
674 "Go backward one node, considering all nodes as forming one sequence." | |
675 (interactive) | |
676 (let ((prevnode (Info-extract-pointer "prev[ious]*" t)) | |
677 (upnode (Info-extract-pointer "up" t))) | |
678 (cond ((and upnode (string-match "(" upnode)) | |
679 (error "First node in file")) | |
680 ((and upnode (or (null prevnode) | |
681 (equal (downcase prevnode) (downcase upnode)))) | |
682 (Info-up)) | |
683 (prevnode | |
684 ;; If we move back at the same level, | |
685 ;; go down to find the last subnode*. | |
686 (Info-prev) | |
687 (let (Info-history) | |
688 (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
689 (save-excursion (search-forward "\n* Menu:" nil t))) | |
690 (Info-goto-node (Info-extract-menu-counting nil))))) | |
691 (t | |
692 (error "No pointer backward from this node"))))) | |
693 | |
694 (defun Info-exit () | |
695 "Exit Info by selecting some other buffer." | |
696 (interactive) | |
697 (switch-to-buffer (prog1 (other-buffer (current-buffer)) | |
698 (bury-buffer (current-buffer))))) | |
699 | |
700 (defun Info-undefined () | |
701 "Make command be undefined in Info." | |
702 (interactive) | |
703 (ding)) | |
704 | |
705 (defun Info-help () | |
706 "Enter the Info tutorial." | |
707 (interactive) | |
708 (delete-other-windows) | |
709 (Info-find-node "info" | |
710 (if (< (window-height) 23) | |
711 "Help-Small-Screen" | |
712 "Help"))) | |
713 | |
714 (defun Info-summary () | |
715 "Display a brief summary of all Info commands." | |
716 (interactive) | |
717 (save-window-excursion | |
718 (switch-to-buffer "*Help*") | |
719 (erase-buffer) | |
720 (insert (documentation 'Info-mode)) | |
721 (goto-char (point-min)) | |
722 (let (ch flag) | |
723 (while (progn (setq flag (not (pos-visible-in-window-p (point-max)))) | |
724 (message (if flag "Type Space to see more" | |
725 "Type Space to return to Info")) | |
726 (if (/= ?\ (setq ch (read-char))) | |
727 (progn (setq unread-command-char ch) nil) | |
728 flag)) | |
729 (scroll-up))))) | |
730 | |
731 (defun Info-get-token (pos start all &optional errorstring) | |
732 "Return the token around POS, | |
733 POS must be somewhere inside the token | |
734 START is a regular expression which will match the | |
735 beginning of the tokens delimited string | |
736 ALL is a regular expression with a single | |
737 parenthized subpattern which is the token to be | |
738 returned. E.g. '{\(.*\)}' would return any string | |
739 enclosed in braces around POS. | |
740 SIG optional fourth argument, controls action on no match | |
741 nil: return nil | |
742 t: beep | |
743 a string: signal an error, using that string." | |
744 (save-excursion | |
745 (goto-char pos) | |
746 (re-search-backward start (max (point-min) (- pos 200)) 'yes) | |
747 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes) | |
748 (not (and (<= (match-beginning 0) pos) | |
749 (> (match-end 0) pos))))) | |
750 (if (and (<= (match-beginning 0) pos) | |
751 (> (match-end 0) pos)) | |
752 (buffer-substring (match-beginning 1) (match-end 1)) | |
753 (cond ((null errorstring) | |
754 nil) | |
755 ((eq errorstring t) | |
756 (beep) | |
757 nil) | |
758 (t | |
759 (error "No %s around position %d" errorstring pos)))))) | |
760 | |
540 | 761 (defun Info-follow-nearest-node (click) |
325 | 762 "\\<Info-mode-map>Follow a node reference near point. Like \\[Info-menu], \\Info-follow-reference], \\[Info-next], \\[Info-previous] or \\Info-up] command. |
763 At end of the node's text, moves to the next node." | |
540 | 764 (interactive "K") |
765 (let* ((relative-coordinates (coordinates-in-window-p (mouse-coords click) | |
325 | 766 (selected-window))) |
767 (rel-x (car relative-coordinates)) | |
540 | 768 (rel-y (cdr relative-coordinates))) |
325 | 769 (move-to-window-line rel-y) |
770 (move-to-column rel-x)) | |
771 (let (node) | |
772 (cond | |
773 ((setq node (Info-get-token (point) "\\*note " "\\*note \\([^:]*\\):" t)) | |
774 (Info-follow-reference node)) | |
775 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::" t)) | |
776 (Info-goto-node node)) | |
777 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):" t)) | |
778 (Info-menu node)) | |
779 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)" t)) | |
780 (Info-goto-node node)) | |
781 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)" t)) | |
782 (Info-goto-node node)) | |
783 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)" t)) | |
784 (Info-goto-node "Top")) | |
785 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)" t)) | |
786 (Info-goto-node node)) | |
787 ((save-excursion (forward-line 1) (eobp)) | |
788 (Info-next))) | |
789 )) | |
790 | |
791 (defvar Info-mode-map nil | |
792 "Keymap containing Info commands.") | |
793 (if Info-mode-map | |
794 nil | |
795 (setq Info-mode-map (make-keymap)) | |
796 (suppress-keymap Info-mode-map) | |
797 (define-key Info-mode-map "." 'beginning-of-buffer) | |
798 (define-key Info-mode-map " " 'scroll-up) | |
799 (define-key Info-mode-map "1" 'Info-first-menu-item) | |
800 (define-key Info-mode-map "2" 'Info-second-menu-item) | |
801 (define-key Info-mode-map "3" 'Info-third-menu-item) | |
802 (define-key Info-mode-map "4" 'Info-fourth-menu-item) | |
803 (define-key Info-mode-map "5" 'Info-fifth-menu-item) | |
804 (define-key Info-mode-map "6" 'undefined) | |
805 (define-key Info-mode-map "7" 'undefined) | |
806 (define-key Info-mode-map "8" 'undefined) | |
807 (define-key Info-mode-map "9" 'undefined) | |
808 (define-key Info-mode-map "0" 'undefined) | |
809 (define-key Info-mode-map "?" 'Info-summary) | |
810 (define-key Info-mode-map "]" 'Info-forward-node) | |
811 (define-key Info-mode-map "[" 'Info-backward-node) | |
812 (define-key Info-mode-map "<" 'Info-top-node) | |
813 (define-key Info-mode-map ">" 'Info-final-node) | |
814 (define-key Info-mode-map "b" 'beginning-of-buffer) | |
815 (define-key Info-mode-map "d" 'Info-directory) | |
816 (define-key Info-mode-map "e" 'Info-edit) | |
817 (define-key Info-mode-map "f" 'Info-follow-reference) | |
818 (define-key Info-mode-map "g" 'Info-goto-node) | |
819 (define-key Info-mode-map "h" 'Info-help) | |
820 (define-key Info-mode-map "l" 'Info-last) | |
821 (define-key Info-mode-map "m" 'Info-menu) | |
822 (define-key Info-mode-map "n" 'Info-next) | |
823 (define-key Info-mode-map "p" 'Info-prev) | |
824 (define-key Info-mode-map "q" 'Info-exit) | |
825 (define-key Info-mode-map "s" 'Info-search) | |
826 (define-key Info-mode-map "u" 'Info-up) | |
540 | 827 (define-key Info-mode-map "\177" 'scroll-down) |
828 ) | |
325 | 829 |
830 ;; Info mode is suitable only for specially formatted data. | |
831 (put 'info-mode 'mode-class 'special) | |
832 | |
833 (defun Info-mode () | |
834 "\\<Info-mode-map> | |
835 Info mode provides commands for browsing through the Info documentation tree. | |
836 Documentation in Info is divided into \"nodes\", each of which discusses | |
837 one topic and contains references to other nodes which discuss related | |
838 topics. Info has commands to follow the references and show you other nodes. | |
839 | |
840 \\[Info-help] Invoke the Info tutorial. | |
841 | |
842 Selecting other nodes: | |
843 \\[Info-next] Move to the \"next\" node of this node. | |
844 \\[Info-previous] Move to the \"previous\" node of this node. | |
845 \\[Info-up] Move \"up\" from this node. | |
846 \\[Info-menu] Pick menu item specified by name (or abbreviation). | |
847 Picking a menu item causes another node to be selected. | |
540 | 848 \\[Info-directory] Go to the Info directory node. |
325 | 849 \\[Info-follow-reference] Follow a cross reference. Reads name of reference. |
850 \\[Info-last] Move to the last node you were at. | |
851 | |
852 Moving within a node: | |
853 \\[scroll-up] scroll forward a full screen. \\[scroll-down] scroll backward. | |
854 \\[beginning-of-buffer] Go to beginning of node. | |
855 | |
856 Advanced commands: | |
857 \\[Info-exit] Quit Info: reselect previously selected buffer. | |
858 \\[Info-edit] Edit contents of selected node. | |
859 1 Pick first item in node's menu. | |
860 2, 3, 4, 5 Pick second ... fifth item in node's menu. | |
861 \\[Info-goto-node] Move to node specified by name. | |
862 You may include a filename as well, as (FILENAME)NODENAME. | |
863 \\[Info-search] Search through this Info file for specified regexp, | |
864 and select the node in which the next occurrence is found." | |
865 (kill-all-local-variables) | |
866 (setq major-mode 'Info-mode) | |
867 (setq mode-name "Info") | |
868 (use-local-map Info-mode-map) | |
869 (set-syntax-table text-mode-syntax-table) | |
870 (setq local-abbrev-table text-mode-abbrev-table) | |
871 (setq case-fold-search t) | |
872 (setq buffer-read-only t) | |
873 (make-local-variable 'Info-current-file) | |
874 (make-local-variable 'Info-current-subfile) | |
875 (make-local-variable 'Info-current-node) | |
876 (make-local-variable 'Info-tag-table-marker) | |
877 (make-local-variable 'Info-history) | |
878 (Info-set-mode-line) | |
879 (run-hooks 'Info-mode-hook)) | |
880 | |
881 (defvar Info-edit-map nil | |
882 "Local keymap used within `e' command of Info.") | |
883 (if Info-edit-map | |
884 nil | |
885 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map)) | |
886 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit)) | |
887 | |
888 ;; Info-edit mode is suitable only for specially formatted data. | |
889 (put 'info-edit-mode 'mode-class 'special) | |
890 | |
891 (defun Info-edit-mode () | |
892 "Major mode for editing the contents of an Info node. | |
893 Like text mode with the addition of Info-cease-edit | |
894 which returns to Info mode for browsing. | |
895 \\{Info-edit-map}" | |
896 ) | |
897 | |
898 (defun Info-edit () | |
899 "Edit the contents of this Info node. | |
900 Allowed only if variable `Info-enable-edit' is non-nil." | |
901 (interactive) | |
902 (or Info-enable-edit | |
903 (error "Editing info nodes is not enabled")) | |
904 (use-local-map Info-edit-map) | |
905 (setq major-mode 'Info-edit-mode) | |
906 (setq mode-name "Info Edit") | |
907 (kill-local-variable 'mode-line-buffer-identification) | |
908 (setq buffer-read-only nil) | |
909 ;; Make mode line update. | |
910 (set-buffer-modified-p (buffer-modified-p)) | |
911 (message (substitute-command-keys | |
912 "Editing: Type \\<info-mode-map>\\[Info-cease-edit] to return to info"))) | |
913 | |
914 (defun Info-cease-edit () | |
915 "Finish editing Info node; switch back to Info proper." | |
916 (interactive) | |
917 ;; Do this first, so nothing has changed if user C-g's at query. | |
918 (and (buffer-modified-p) | |
919 (y-or-n-p "Save the file? ") | |
920 (save-buffer)) | |
921 (use-local-map Info-mode-map) | |
922 (setq major-mode 'Info-mode) | |
923 (setq mode-name "Info") | |
924 (Info-set-mode-line) | |
925 (setq buffer-read-only t) | |
926 ;; Make mode line update. | |
927 (set-buffer-modified-p (buffer-modified-p)) | |
928 (and (marker-position Info-tag-table-marker) | |
929 (buffer-modified-p) | |
930 (message "Tags may have changed. Use Info-tagify if necessary"))) | |
359 | 931 |
932 (defun Info-find-emacs-command-nodes (command) | |
933 "Return a list of locations documenting COMMAND in the Emacs Info manual. | |
934 The locations are of the format used in Info-history, i.e. | |
935 \(FILENAME NODENAME BUFFERPOS\)." | |
936 (require 'info) | |
937 (let ((where '()) | |
938 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command)) | |
939 ":\\s *\\(.*\\)\\.$"))) | |
940 (save-excursion | |
941 (Info-find-node "emacs" "Command Index") | |
942 ;; Take the index node off the Info history. | |
943 (setq Info-history (cdr Info-history)) | |
944 (goto-char (point-max)) | |
945 (while (re-search-backward cmd-desc nil t) | |
946 (setq where (cons (list Info-current-file | |
947 (buffer-substring | |
948 (match-beginning 1) | |
949 (match-end 1)) | |
950 0) | |
951 where))) | |
952 where))) | |
953 | |
954 ;;;###autoload | |
955 (defun Info-goto-emacs-command-node (command) | |
956 "Go to the Info node in the Emacs manual for command COMMAND." | |
957 (interactive "CFind documentation for command: ") | |
958 (or (commandp command) | |
959 (signal 'wrong-type-argument (list 'commandp command))) | |
960 (let ((where (Info-find-emacs-command-nodes command))) | |
961 (if where | |
962 (let ((num-matches (length where))) | |
963 ;; Get Info running, and pop to it in another window. | |
964 (save-window-excursion | |
965 (info)) | |
966 (pop-to-buffer "*info*") | |
967 (Info-find-node (car (car where)) | |
968 (car (cdr (car where)))) | |
969 (if (> num-matches 1) | |
970 (progn | |
971 ;; Info-find-node already pushed (car where) onto | |
972 ;; Info-history. Put the other nodes that were found on | |
973 ;; the history. | |
974 (setq Info-history (nconc (cdr where) Info-history)) | |
975 (message (substitute-command-keys | |
976 "Found %d other entr%. Use \\[Info-last] to see %s." | |
977 (1- num-matches) | |
978 (if (> num-matches 2) "ies" "y") | |
979 (if (> num-matches 2) "them" "it")))))) | |
980 (error "Couldn't find documentation for %s." command)))) | |
981 ;;;###autoload | |
982 (define-key help-map "\C-f" 'Info-goto-emacs-command-node) | |
983 | |
984 ;;;###autoload | |
985 (defun Info-goto-emacs-key-command-node (key) | |
986 "Go to the Info node in the Emacs manual the command bound to KEY, a string. | |
987 Interactively, if the binding is execute-extended-command, a command is read." | |
988 (interactive "kFind documentation for key:") | |
989 (let ((command (key-binding key))) | |
990 (cond ((null command) | |
991 (message "%s is undefined" (key-description keys))) | |
992 ((and (interactive-p) | |
993 (eq command 'execute-extended-command)) | |
994 (Info-goto-emacs-command-node | |
995 (read-command "Find documentation for command: "))) | |
996 (t | |
997 (Info-goto-emacs-command-node command))))) | |
998 ;;;###autoload | |
999 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node) | |
584 | 1000 |
1001 (provide 'info) | |
1002 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1003 ;;; info.el ends here |