Mercurial > emacs
annotate lisp/textmodes/texinfmt.el @ 2563:c8ae06bda9fa
(global-map): Remove function key bindings that duplicate stuff in
loaddefs.el.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 23 Apr 1993 02:21:02 +0000 |
parents | fb0ed5a1d0f3 |
children | 57089987a2de |
rev | line source |
---|---|
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
1 ;;; texinfmt.el --- convert Texinfo files to Info files. |
189 | 2 |
841 | 3 ;; Copyright (C) 1985, 1986, 1988, 1990 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
5 ;; Author: Robert J. Chassell <bob@gnu.ai.mit.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
6 ;; Version: 2.00 |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: tex, help |
189 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
189 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
25 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
26 |
189 | 27 ;; Updated May 1990 to correspond, more or less, to version 2.8 of |
28 ;; texinfo.tex. NOTE: texinfmt.el is being phased out; it is being | |
29 ;; replaced by makeinfo.c, which is faster and provides better error | |
30 ;; checking. | |
31 ;; Robert J. Chassell, bob@ai.mit.edu | |
32 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
33 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
34 |
189 | 35 (defvar texinfo-format-syntax-table nil) |
36 | |
37 (defvar texinfo-vindex) | |
38 (defvar texinfo-findex) | |
39 (defvar texinfo-cindex) | |
40 (defvar texinfo-pindex) | |
41 (defvar texinfo-tindex) | |
42 (defvar texinfo-kindex) | |
43 (defvar texinfo-last-node) | |
44 (defvar texinfo-node-names) | |
45 | |
46 (if texinfo-format-syntax-table | |
47 nil | |
48 (setq texinfo-format-syntax-table (make-syntax-table)) | |
49 (modify-syntax-entry ?\" " " texinfo-format-syntax-table) | |
50 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table) | |
51 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table) | |
52 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table) | |
53 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table) | |
54 (modify-syntax-entry ?\] "." texinfo-format-syntax-table) | |
55 (modify-syntax-entry ?\( "." texinfo-format-syntax-table) | |
56 (modify-syntax-entry ?\) "." texinfo-format-syntax-table) | |
57 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table) | |
58 (modify-syntax-entry ?} "){" texinfo-format-syntax-table) | |
59 (modify-syntax-entry ?\' "." texinfo-format-syntax-table)) | |
60 | |
258 | 61 ;;;###autoload |
189 | 62 (defun texinfo-format-buffer (&optional notagify) |
63 "Process the current buffer as texinfo code, into an Info file. | |
64 The Info file output is generated in a buffer visiting the Info file | |
65 names specified in the @setfilename command. | |
66 | |
67 Non-nil argument (prefix, if interactive) means don't make tag table | |
68 and don't split the file if large. You can use Info-tagify and | |
69 Info-split to do these manually." | |
70 (interactive "P") | |
71 (let ((lastmessage "Formatting Info file...")) | |
72 (message lastmessage) | |
73 (texinfo-format-buffer-1) | |
74 (if notagify | |
75 nil | |
76 (if (> (buffer-size) 30000) | |
77 (progn | |
78 (message (setq lastmessage "Making tags table for Info file...")) | |
79 (Info-tagify))) | |
80 (if (> (buffer-size) 100000) | |
81 (progn | |
82 (message (setq lastmessage "Splitting Info file...")) | |
83 (Info-split)))) | |
84 (message (concat lastmessage | |
85 (if (interactive-p) "done. Now save it." "done."))))) | |
86 | |
87 | |
88 (defun texinfo-format-buffer-1 () | |
89 (let (texinfo-format-filename | |
90 texinfo-example-start | |
91 texinfo-command-start | |
92 texinfo-command-end | |
93 texinfo-command-name | |
94 texinfo-last-node | |
95 texinfo-vindex | |
96 texinfo-findex | |
97 texinfo-cindex | |
98 texinfo-pindex | |
99 texinfo-tindex | |
100 texinfo-kindex | |
101 texinfo-stack | |
102 texinfo-node-names | |
103 (texinfo-footnote-number 0) | |
104 last-input-buffer | |
105 outfile | |
106 (fill-column fill-column) | |
107 (input-buffer (current-buffer)) | |
108 (input-directory default-directory)) | |
109 (save-excursion | |
110 (goto-char (point-min)) | |
111 (search-forward "@setfilename") | |
112 (setq texinfo-command-end (point)) | |
113 (setq outfile (texinfo-parse-line-arg))) | |
114 (find-file outfile) | |
115 (texinfo-mode) | |
116 (set-syntax-table texinfo-format-syntax-table) | |
117 (erase-buffer) | |
118 (insert-buffer-substring input-buffer) | |
119 (goto-char (point-min)) | |
120 (search-forward "@setfilename") | |
121 (beginning-of-line) | |
122 (delete-region (point-min) (point)) | |
123 ;; Remove @bye at end of file, if it is there. | |
124 (goto-char (point-max)) | |
125 (if (search-backward "@bye" nil t) | |
126 (delete-region (point) (point-max))) | |
127 ;; Make sure buffer ends in a newline. | |
128 (or (= (preceding-char) ?\n) | |
129 (insert "\n")) | |
130 ;; Scan the whole buffer, converting to Info format. | |
131 (texinfo-format-scan) | |
132 ;; Return data for indices. | |
133 (goto-char (point-min)) | |
134 (list outfile | |
135 texinfo-vindex texinfo-findex texinfo-cindex | |
136 texinfo-pindex texinfo-tindex texinfo-kindex))) | |
137 | |
138 (defvar texinfo-region-buffer-name "*Info Region*" | |
139 "*Name of the temporary buffer used by \\[texinfo-format-region].") | |
140 | |
258 | 141 ;;;###autoload |
189 | 142 (defun texinfo-format-region (region-beginning region-ending) |
143 "Convert the current region of the Texinfo file to Info format. | |
144 This lets you see what that part of the file will look like in Info. | |
145 The command is bound to \\[texinfo-format-region]. The text that is | |
146 converted to Info is stored in a temporary buffer." | |
147 (interactive "r") | |
148 (message "Converting region to Info format...") | |
149 (let (texinfo-command-start | |
150 texinfo-command-end | |
151 texinfo-command-name | |
152 texinfo-vindex | |
153 texinfo-findex | |
154 texinfo-cindex | |
155 texinfo-pindex | |
156 texinfo-tindex | |
157 texinfo-kindex | |
158 texinfo-stack | |
159 texinfo-format-filename | |
160 texinfo-example-start | |
161 texinfo-last-node | |
162 texinfo-node-names | |
163 (texinfo-footnote-number 0) | |
164 last-input-buffer | |
165 (fill-column fill-column) | |
166 (input-buffer (current-buffer)) | |
167 (input-directory default-directory) | |
168 filename-beginning | |
169 filename-ending) | |
170 | |
171 ;;; Find a buffer to use. | |
172 | |
173 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) | |
174 | |
175 ;; Insert the region into the buffer. | |
176 (erase-buffer) | |
177 | |
178 (save-excursion | |
179 (set-buffer input-buffer) | |
180 (save-excursion | |
181 (save-restriction | |
182 (widen) | |
183 (goto-char (point-min)) | |
184 ;; Initialize the buffer with the filename | |
185 ;; or else explain that a filename is needed. | |
186 (or (search-forward "@setfilename" | |
187 (save-excursion (forward-line 100) (point)) t) | |
188 (error "The texinfo file needs a line saying: @setfilename <name>")) | |
189 (beginning-of-line) | |
190 (setq filename-beginning (point)) | |
191 (forward-line 1) | |
192 (setq filename-ending (point))))) | |
193 | |
194 ;; Insert the @setfilename line into the buffer. | |
195 (insert-buffer-substring input-buffer | |
196 (min filename-beginning region-beginning) | |
197 filename-ending) | |
198 | |
199 ;; Insert the region into the buffer. | |
200 (insert-buffer-substring input-buffer | |
201 (max region-beginning filename-ending) | |
202 region-ending) | |
203 | |
204 (texinfo-mode) | |
205 | |
206 ;; Install a syntax table useful for scanning command operands. | |
207 (set-syntax-table texinfo-format-syntax-table) | |
208 | |
209 ;; If the region includes the effective end of the data, | |
210 ;; discard everything after that. | |
211 (goto-char (point-max)) | |
212 (if (re-search-backward "^@bye" nil t) | |
213 (delete-region (point) (point-max))) | |
214 ;; Make sure buffer ends in a newline. | |
215 (or (= (preceding-char) ?\n) | |
216 (insert "\n")) | |
217 | |
218 ;; Now convert for real. | |
219 (goto-char (point-min)) | |
220 (texinfo-format-scan) | |
221 (goto-char (point-min))) | |
222 | |
223 (message "Done.")) | |
224 | |
225 | |
226 ;; Perform those texinfo-to-info conversions that apply to the whole input | |
227 ;; uniformly. | |
228 (defun texinfo-format-scan () | |
229 ;; Convert left and right quotes to typewriter font quotes. | |
230 (goto-char (point-min)) | |
231 (while (search-forward "``" nil t) | |
232 (replace-match "\"")) | |
233 (goto-char (point-min)) | |
234 (while (search-forward "''" nil t) | |
235 (replace-match "\"")) | |
236 ;; Scan for @-commands. | |
237 (goto-char (point-min)) | |
238 (while (search-forward "@" nil t) | |
239 (if (looking-at "[@{}'` *]") | |
240 ;; Handle a few special @-followed-by-one-char commands. | |
241 (if (= (following-char) ?*) | |
242 (progn | |
243 ;; remove command | |
244 (delete-region (1- (point)) (1+ (point))) | |
245 ;; insert return if not at end of line; | |
246 ;; else line is already broken. | |
247 (if (not (= (following-char) ?\n)) | |
248 (insert ?\n))) | |
249 ;; The other characters are simply quoted. Delete the @. | |
250 (delete-char -1) | |
251 (forward-char 1)) | |
252 ;; @ is followed by a command-word; find the end of the word. | |
253 (setq texinfo-command-start (1- (point))) | |
254 (if (= (char-syntax (following-char)) ?w) | |
255 (forward-word 1) | |
256 (forward-char 1)) | |
257 (setq texinfo-command-end (point)) | |
258 ;; Call the handler for this command. | |
259 (setq texinfo-command-name | |
260 (intern (buffer-substring (1+ texinfo-command-start) | |
261 texinfo-command-end))) | |
262 (let ((cmd (get texinfo-command-name 'texinfo-format))) | |
263 (if cmd (funcall cmd) | |
264 (texinfo-unsupported))))) | |
265 (cond (texinfo-stack | |
266 (goto-char (nth 2 (car texinfo-stack))) | |
267 (error "Unterminated @%s" (car (car texinfo-stack)))))) | |
268 | |
269 (put 'begin 'texinfo-format 'texinfo-format-begin) | |
270 (defun texinfo-format-begin () | |
271 (texinfo-format-begin-end 'texinfo-format)) | |
272 | |
273 (put 'end 'texinfo-format 'texinfo-format-end) | |
274 (defun texinfo-format-end () | |
275 (texinfo-format-begin-end 'texinfo-end)) | |
276 | |
277 (defun texinfo-format-begin-end (prop) | |
278 (setq texinfo-command-name (intern (texinfo-parse-line-arg))) | |
279 (setq cmd (get texinfo-command-name prop)) | |
280 (if cmd (funcall cmd) | |
281 (texinfo-unsupported))) | |
282 | |
283 (defun texinfo-parse-line-arg () | |
284 (goto-char texinfo-command-end) | |
285 (let ((start (point))) | |
286 (cond ((looking-at " ") | |
287 (skip-chars-forward " ") | |
288 (setq start (point)) | |
289 (end-of-line) | |
290 (skip-chars-backward " ") | |
291 (setq texinfo-command-end (1+ (point)))) | |
292 ((looking-at "{") | |
293 (setq start (1+ (point))) | |
294 (forward-list 1) | |
295 (setq texinfo-command-end (point)) | |
296 (forward-char -1)) | |
297 (t | |
298 (error "Invalid texinfo command arg format"))) | |
299 (prog1 (buffer-substring start (point)) | |
300 (if (eolp) (forward-char 1))))) | |
301 | |
302 (defun texinfo-parse-expanded-arg () | |
303 (goto-char texinfo-command-end) | |
304 (let ((start (point)) | |
305 marker) | |
306 (cond ((looking-at " ") | |
307 (skip-chars-forward " ") | |
308 (setq start (point)) | |
309 (end-of-line) | |
310 (setq texinfo-command-end (1+ (point)))) | |
311 ((looking-at "{") | |
312 (setq start (1+ (point))) | |
313 (forward-list 1) | |
314 (setq texinfo-command-end (point)) | |
315 (forward-char -1)) | |
316 (t | |
317 (error "Invalid texinfo command arg format"))) | |
318 (setq marker (move-marker (make-marker) texinfo-command-end)) | |
319 (texinfo-format-expand-region start (point)) | |
320 (setq texinfo-command-end (marker-position marker)) | |
321 (move-marker marker nil) | |
322 (prog1 (buffer-substring start (point)) | |
323 (if (eolp) (forward-char 1))))) | |
324 | |
325 (defun texinfo-format-expand-region (start end) | |
326 (save-restriction | |
327 (narrow-to-region start end) | |
328 (let (texinfo-command-start | |
329 texinfo-command-end | |
330 texinfo-command-name | |
331 texinfo-stack) | |
332 (texinfo-format-scan)) | |
333 (goto-char (point-max)))) | |
334 | |
335 (defun texinfo-parse-arg-discard () | |
336 (prog1 (texinfo-parse-line-arg) | |
337 (texinfo-discard-command))) | |
338 | |
339 (defun texinfo-discard-command () | |
340 (delete-region texinfo-command-start texinfo-command-end)) | |
341 | |
342 (defun texinfo-optional-braces-discard () | |
343 "Discard braces following command, if any." | |
344 (goto-char texinfo-command-end) | |
345 (let ((start (point))) | |
346 (cond ((looking-at "[ \t]*\n")) ; do nothing | |
347 ((looking-at "{") ; remove braces, if any | |
348 (forward-list 1) | |
349 (setq texinfo-command-end (point))) | |
350 (t | |
351 (error | |
352 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)"))) | |
353 (delete-region texinfo-command-start texinfo-command-end))) | |
354 | |
355 (defun texinfo-format-parse-line-args () | |
356 (let ((start (1- (point))) | |
357 next beg end | |
358 args) | |
359 (skip-chars-forward " ") | |
360 (while (not (eolp)) | |
361 (setq beg (point)) | |
362 (re-search-forward "[\n,]") | |
363 (setq next (point)) | |
364 (if (bolp) (setq next (1- next))) | |
365 (forward-char -1) | |
366 (skip-chars-backward " ") | |
367 (setq end (point)) | |
368 (setq args (cons (if (> end beg) (buffer-substring beg end)) | |
369 args)) | |
370 (goto-char next) | |
371 (skip-chars-forward " ")) | |
372 (if (eolp) (forward-char 1)) | |
373 (setq texinfo-command-end (point)) | |
374 (nreverse args))) | |
375 | |
376 (defun texinfo-format-parse-args () | |
377 (let ((start (1- (point))) | |
378 next beg end | |
379 args) | |
380 (search-forward "{") | |
381 (save-excursion | |
382 (texinfo-format-expand-region | |
383 (point) | |
384 (save-excursion (up-list 1) (1- (point))))) | |
385 (while (/= (preceding-char) ?\}) | |
386 (skip-chars-forward " \t\n") | |
387 (setq beg (point)) | |
388 (re-search-forward "[},]") | |
389 (setq next (point)) | |
390 (forward-char -1) | |
391 (skip-chars-backward " \t\n") | |
392 (setq end (point)) | |
393 (cond ((< beg end) | |
394 (goto-char beg) | |
395 (while (search-forward "\n" end t) | |
396 (replace-match " ")))) | |
397 (setq args (cons (if (> end beg) (buffer-substring beg end)) | |
398 args)) | |
399 (goto-char next)) | |
400 (if (eolp) (forward-char 1)) | |
401 (setq texinfo-command-end (point)) | |
402 (nreverse args))) | |
403 | |
404 (defun texinfo-format-parse-defun-args () | |
405 (goto-char texinfo-command-end) | |
406 (let ((start (point))) | |
407 (end-of-line) | |
408 (setq texinfo-command-end (1+ (point))) | |
409 (let ((marker (move-marker (make-marker) texinfo-command-end))) | |
410 (texinfo-format-expand-region start (point)) | |
411 (setq texinfo-command-end (marker-position marker)) | |
412 (move-marker marker nil)) | |
413 (goto-char start) | |
414 (let ((args '()) | |
415 beg end) | |
416 (skip-chars-forward " ") | |
417 (while (not (eolp)) | |
418 (cond ((looking-at "{") | |
419 (setq beg (1+ (point))) | |
420 (forward-list 1) | |
421 (setq end (1- (point)))) | |
422 (t | |
423 (setq beg (point)) | |
424 (re-search-forward "[\n ]") | |
425 (forward-char -1) | |
426 (setq end (point)))) | |
427 (setq args (cons (buffer-substring beg end) args)) | |
428 (skip-chars-forward " ")) | |
429 (forward-char 1) | |
430 (nreverse args)))) | |
431 | |
432 | |
433 ; 19 October 1990 | |
434 ; @setfilename modifed to work with include files; see @include | |
435 ; (defun texinfo-format-setfilename () | |
436 ; (let ((arg (texinfo-parse-arg-discard))) | |
437 ; (setq texinfo-format-filename | |
438 ; (file-name-nondirectory (expand-file-name arg))) | |
439 ; (insert "Info file: " | |
440 ; texinfo-format-filename ", -*-Text-*-\n" | |
441 ; "produced by texinfo-format-buffer\nfrom " | |
442 ; (if (buffer-file-name input-buffer) | |
443 ; (concat "file: " | |
444 ; (file-name-sans-versions | |
445 ; (file-name-nondirectory | |
446 ; (buffer-file-name input-buffer)))) | |
447 ; (concat "buffer " (buffer-name input-buffer))) | |
448 ; "\n\n"))) | |
449 | |
450 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename) | |
451 (defun texinfo-format-setfilename () | |
452 (let ((arg (texinfo-parse-arg-discard))) | |
453 (if (eq input-buffer last-input-buffer) | |
454 nil ; only use first setfilename in buffer | |
455 (message "Formatting Info file: %s" arg) | |
456 (setq texinfo-format-filename | |
457 (file-name-nondirectory (expand-file-name arg))) | |
458 (insert "Info file: " | |
459 texinfo-format-filename ", -*-Text-*-\n" | |
460 "produced by texinfo-format-buffer\nfrom " | |
461 (if (buffer-file-name input-buffer) | |
462 (concat "file: " | |
463 (file-name-sans-versions | |
464 (file-name-nondirectory | |
465 (buffer-file-name input-buffer)))) | |
466 (concat "buffer " (buffer-name input-buffer))) | |
467 "\n\n")))) | |
468 | |
469 (put 'node 'texinfo-format 'texinfo-format-node) | |
470 (defun texinfo-format-node () | |
471 (let* ((args (texinfo-format-parse-line-args)) | |
472 (name (nth 0 args)) | |
473 (next (nth 1 args)) | |
474 (prev (nth 2 args)) | |
475 (up (nth 3 args))) | |
476 (texinfo-discard-command) | |
477 (setq texinfo-last-node name) | |
478 (let ((tem (downcase name))) | |
479 (if (assoc tem texinfo-node-names) | |
480 (error "Duplicate node name: %s" name) | |
481 (setq texinfo-node-names (cons (list tem) texinfo-node-names)))) | |
482 (setq texinfo-footnote-number 0) | |
483 (or (bolp) | |
484 (insert ?\n)) | |
485 (insert "\^_\nFile: " texinfo-format-filename | |
486 " Node: " name) | |
487 (if prev | |
488 (insert ", Prev: " prev)) | |
489 (if up | |
490 (insert ", Up: " up)) | |
491 (if next | |
492 (insert ", Next: " next)) | |
493 (insert ?\n))) | |
494 | |
495 (put 'menu 'texinfo-format 'texinfo-format-menu) | |
496 (defun texinfo-format-menu () | |
497 (texinfo-discard-line) | |
498 (insert "* Menu:\n\n")) | |
499 | |
500 (put 'menu 'texinfo-end 'texinfo-discard-command) | |
501 (defun texinfo-discard-line () | |
502 (goto-char texinfo-command-end) | |
503 (skip-chars-forward " \t") | |
504 (or (eolp) | |
505 (error "Extraneous text at end of command line.")) | |
506 (goto-char texinfo-command-start) | |
507 (or (bolp) | |
508 (error "Extraneous text at beginning of command line.")) | |
509 (delete-region (point) (progn (forward-line 1) (point)))) | |
510 | |
511 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT} | |
512 ; -> *Note FNAME: (FILE)NODE | |
513 ; If FILE is missing, | |
514 ; *Note FNAME: NODE | |
515 ; If FNAME is empty and NAME is present | |
516 ; *Note NAME: Node | |
517 ; If both NAME and FNAME are missing | |
518 ; *Note NODE:: | |
519 ; texinfo ignores the DOCUMENT argument. | |
520 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE> | |
521 ; If FILE is specified, (FILE)NODE is used for xrefs. | |
522 ; If fifth argument DOCUMENT is specified, produces | |
523 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE> | |
524 ; of DOCUMENT | |
525 | |
526 ; @ref a reference that does not put `See' or `see' in | |
527 ; the hardcopy and is the same as @xref in Info | |
528 (put 'ref 'texinfo-format 'texinfo-format-xref) | |
529 | |
530 (put 'xref 'texinfo-format 'texinfo-format-xref) | |
531 (defun texinfo-format-xref () | |
532 (let ((args (texinfo-format-parse-args))) | |
533 (texinfo-discard-command) | |
534 (insert "*Note ") | |
535 (let ((fname (or (nth 1 args) (nth 2 args)))) | |
536 (if (null (or fname (nth 3 args))) | |
537 (insert (car args) "::") | |
538 (insert (or fname (car args)) ": ") | |
539 (if (nth 3 args) | |
540 (insert "(" (nth 3 args) ")")) | |
541 (insert (car args)))))) | |
542 | |
543 (put 'pxref 'texinfo-format 'texinfo-format-pxref) | |
544 (defun texinfo-format-pxref () | |
545 (texinfo-format-xref) | |
546 (or (save-excursion | |
547 (forward-char -2) | |
548 (looking-at "::")) | |
549 (insert "."))) | |
550 | |
551 ;@inforef{NODE, FNAME, FILE} | |
552 ;Like @xref{NODE, FNAME,,FILE} in texinfo. | |
553 ;In Tex, generates "See Info file FILE, node NODE" | |
554 (put 'inforef 'texinfo-format 'texinfo-format-inforef) | |
555 (defun texinfo-format-inforef () | |
556 (let ((args (texinfo-format-parse-args))) | |
557 (texinfo-discard-command) | |
558 (if (nth 1 args) | |
559 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args)) | |
560 (insert "*Note " "(" (nth 2 args) ")" (car args) "::")))) | |
561 | |
562 (put 'chapheading 'texinfo-format 'texinfo-format-chapter) | |
563 (put 'ichapter 'texinfo-format 'texinfo-format-chapter) | |
564 (put 'chapter 'texinfo-format 'texinfo-format-chapter) | |
565 (put 'iappendix 'texinfo-format 'texinfo-format-chapter) | |
566 (put 'appendix 'texinfo-format 'texinfo-format-chapter) | |
567 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter) | |
568 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter) | |
569 (defun texinfo-format-chapter () | |
570 (texinfo-format-chapter-1 ?*)) | |
571 | |
572 (put 'heading 'texinfo-format 'texinfo-format-section) | |
573 (put 'isection 'texinfo-format 'texinfo-format-section) | |
574 (put 'section 'texinfo-format 'texinfo-format-section) | |
575 (put 'iappendixsection 'texinfo-format 'texinfo-format-section) | |
576 (put 'appendixsection 'texinfo-format 'texinfo-format-section) | |
577 (put 'iappendixsec 'texinfo-format 'texinfo-format-section) | |
578 (put 'appendixsec 'texinfo-format 'texinfo-format-section) | |
579 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section) | |
580 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section) | |
581 (defun texinfo-format-section () | |
582 (texinfo-format-chapter-1 ?=)) | |
583 | |
584 (put 'subheading 'texinfo-format 'texinfo-format-subsection) | |
585 (put 'isubsection 'texinfo-format 'texinfo-format-subsection) | |
586 (put 'subsection 'texinfo-format 'texinfo-format-subsection) | |
587 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection) | |
588 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection) | |
589 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection) | |
590 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection) | |
591 (defun texinfo-format-subsection () | |
592 (texinfo-format-chapter-1 ?-)) | |
593 | |
594 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection) | |
595 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection) | |
596 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection) | |
597 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
598 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
599 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
600 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
601 (defun texinfo-format-subsubsection () | |
602 (texinfo-format-chapter-1 ?.)) | |
603 | |
604 (defun texinfo-format-chapter-1 (belowchar) | |
605 (let ((arg (texinfo-parse-arg-discard))) | |
606 (message "Formatting: %s ... " arg) ; So we can see where we are. | |
607 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n) | |
608 (forward-line -2))) | |
609 | |
610 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad) | |
611 (defun texinfo-format-sectionpad () | |
612 (let ((str (texinfo-parse-arg-discard))) | |
613 (forward-char -1) | |
614 (let ((column (current-column))) | |
615 (forward-char 1) | |
616 (while (> column 0) | |
617 (insert str) | |
618 (setq column (1- column)))) | |
619 (insert ?\n))) | |
620 | |
621 (put '\. 'texinfo-format 'texinfo-format-\.) | |
622 (defun texinfo-format-\. () | |
623 (texinfo-discard-command) | |
624 (insert ".")) | |
625 | |
626 (put '\: 'texinfo-format 'texinfo-format-\:) | |
627 (defun texinfo-format-\: () | |
628 (texinfo-discard-command)) | |
629 | |
630 (put 'center 'texinfo-format 'texinfo-format-center) | |
631 (defun texinfo-format-center () | |
632 (texinfo-discard-command) | |
633 (let ((indent-tabs-mode nil)) | |
634 (center-line))) | |
635 | |
636 (put 'sp 'texinfo-format 'texinfo-format-sp) | |
637 (defun texinfo-format-sp () | |
638 (let* ((arg (texinfo-parse-arg-discard)) | |
639 (num (read arg))) | |
640 (insert-char ?\n num))) | |
641 | |
642 (put 'br 'texinfo-format 'texinfo-format-paragraph-break) | |
643 (defun texinfo-format-paragraph-break () | |
644 "Force a paragraph break. | |
645 If used within a line, follow `@br' with braces." | |
646 (texinfo-optional-braces-discard) | |
647 ;; insert one return if at end of line; | |
648 ;; else insert two returns, to generate a blank line. | |
649 (if (= (following-char) ?\n) | |
650 (insert ?\n) | |
651 (insert-char ?\n 2))) | |
652 | |
653 | |
654 ;;; @footnote | |
655 | |
656 ; In Texinfo, footnotes are created with the `@footnote' command. | |
657 ; This command is followed immediately by a left brace, then by the text of | |
658 ; the footnote, and then by a terminating right brace. The | |
659 ; template for a footnote is: | |
660 ; | |
661 ; @footnote{TEXT} | |
662 ; | |
663 ; Info has two footnote styles: | |
664 ; | |
665 ; `End Node' | |
666 ; In the "End Node" style, all the footnotes for a single node | |
667 ; are placed at the end of that node. The footnotes are | |
668 ; separated from the rest of the node by a line of dashes with | |
669 ; the word `Footnotes' within it. | |
670 ; | |
671 ; `Make Node' | |
672 ; In the "Make Node" style, all the footnotes for a single node are | |
673 ; placed in an automatically constructed node of their own. | |
674 | |
675 (put 'footnote 'texinfo-format 'texinfo-format-footnote) | |
676 | |
677 (defvar texinfo-footnote-style 'MN "\ | |
678 *Footnote style, either EN for end node or MN for make node.") | |
679 | |
680 (defvar texinfo-footnote-number) | |
681 | |
682 (defun texinfo-format-footnote () | |
683 "Format a footnote in either `end node' or `make node' style. | |
1576 | 684 The `texinfo-footnote-style' variable controls which style is used." |
189 | 685 (setq texinfo-footnote-number (1+ texinfo-footnote-number)) |
686 (cond ((eq texinfo-footnote-style 'EN) (texinfo-format-end-node)) | |
687 ((eq texinfo-footnote-style 'MN) (texinfo-format-make-node)))) | |
688 | |
689 (defun texinfo-format-make-node () | |
690 "Format footnote in `MN', Make Node, style with notes in own node. | |
691 The node is constructed automatically." | |
692 (let* (start | |
693 (arg (texinfo-parse-expanded-arg)) | |
694 (node-name-beginning | |
695 (save-excursion | |
696 (re-search-backward | |
697 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\)*[ \t]+Node:") | |
698 (match-end 0))) | |
699 (node-name | |
700 (save-excursion | |
701 (buffer-substring | |
702 (progn (goto-char node-name-beginning) ; skip over node command | |
703 (skip-chars-forward " \t") ; and over spaces | |
704 (point)) | |
705 (if (search-forward | |
706 "," | |
707 (save-excursion (end-of-line) (point)) t) ; bound search | |
708 (1- (point)) | |
709 (end-of-line) (point)))))) | |
710 (texinfo-discard-command) | |
711 (insert (format "(%d) (*note %s-Footnotes::)" | |
712 texinfo-footnote-number node-name)) | |
713 (fill-paragraph nil) | |
714 (save-excursion | |
715 (if (re-search-forward "^@node" nil 'move) | |
716 (forward-line -1)) | |
717 | |
718 ;; two cases: for the first footnote, we must insert a node header; | |
719 ;; for the second and subsequent footnotes, we need only insert | |
720 ;; the text of the footnote. | |
721 | |
722 (if (save-excursion | |
723 (re-search-backward | |
724 (concat node-name "-Footnotes, Up: ") | |
725 node-name-beginning | |
726 t)) | |
727 (progn ; already at least one footnote | |
728 (setq start (point)) | |
729 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
730 (fill-region start (point))) | |
731 ;; else not yet a footnote | |
732 (insert "\n\^_\nFile: " texinfo-format-filename | |
733 " Node: " node-name "-Footnotes, Up: " node-name "\n") | |
734 (setq start (point)) | |
735 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
736 (fill-region start (point)))))) | |
737 | |
738 (defun texinfo-format-end-node () | |
739 "Format footnote in `EN', End Node, style with notes at end of node." | |
740 (let (start | |
741 (arg (texinfo-parse-expanded-arg))) | |
742 (texinfo-discard-command) | |
743 (insert (format "(%d) " texinfo-footnote-number)) | |
744 (fill-paragraph nil) | |
745 (save-excursion | |
746 (if (search-forward "\n--------- Footnotes ---------\n" nil t) | |
747 (progn ; already have footnote, put new one before end of node | |
748 (if (re-search-forward "^@node" nil 'move) | |
749 (forward-line -1)) | |
750 (setq start (point)) | |
751 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
752 (fill-region start (point))) | |
753 ;; else no prior footnote | |
754 (if (re-search-forward "^@node" nil 'move) | |
755 (forward-line -1)) | |
756 (insert "\n--------- Footnotes ---------\n") | |
757 (setq start (point)) | |
758 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
759 (fill-region start (point)))))) | |
760 | |
761 | |
762 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack. | |
763 ;; @enumerate pushes (enumerate 0 STARTPOS). | |
764 ;; @item dispatches to the texinfo-item prop of the first elt of the list. | |
765 ;; For itemize, this puts in and rescans the COMMANDS. | |
766 ;; For enumerate, this increments the number and puts it in. | |
767 ;; In either case, it puts a Backspace at the front of the line | |
768 ;; which marks it not to be indented later. | |
769 ;; All other lines get indented by 5 when the @end is reached. | |
770 | |
771 (defun texinfo-push-stack (check arg) | |
772 (setq texinfo-stack | |
773 (cons (list check arg texinfo-command-start) | |
774 texinfo-stack))) | |
775 | |
776 (defun texinfo-pop-stack (check) | |
777 (if (null texinfo-stack) | |
778 (error "Unmatched @end %s" check)) | |
779 (if (not (eq (car (car texinfo-stack)) check)) | |
780 (error "@end %s matches @%s" | |
781 check (car (car texinfo-stack)))) | |
782 (prog1 (cdr (car texinfo-stack)) | |
783 (setq texinfo-stack (cdr texinfo-stack)))) | |
784 | |
785 (put 'itemize 'texinfo-format 'texinfo-itemize) | |
786 (defun texinfo-itemize () | |
787 (texinfo-push-stack 'itemize (texinfo-parse-arg-discard)) | |
788 (setq fill-column (- fill-column 5))) | |
789 | |
790 (put 'itemize 'texinfo-end 'texinfo-end-itemize) | |
791 (defun texinfo-end-itemize () | |
792 (setq fill-column (+ fill-column 5)) | |
793 (texinfo-discard-command) | |
794 (let ((stacktop | |
795 (texinfo-pop-stack 'itemize))) | |
796 (texinfo-do-itemize (nth 1 stacktop)))) | |
797 | |
798 (put 'enumerate 'texinfo-format 'texinfo-enumerate) | |
799 (defun texinfo-enumerate () | |
800 (texinfo-push-stack 'enumerate 0) | |
801 (setq fill-column (- fill-column 5)) | |
802 (texinfo-discard-line)) | |
803 | |
804 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate) | |
805 (defun texinfo-end-enumerate () | |
806 (setq fill-column (+ fill-column 5)) | |
807 (texinfo-discard-command) | |
808 (let ((stacktop | |
809 (texinfo-pop-stack 'enumerate))) | |
810 (texinfo-do-itemize (nth 1 stacktop)))) | |
811 | |
812 (put 'table 'texinfo-format 'texinfo-table) | |
813 (defun texinfo-table () | |
814 (texinfo-push-stack 'table (texinfo-parse-arg-discard)) | |
815 (setq fill-column (- fill-column 5))) | |
816 | |
817 (put 'ftable 'texinfo-format 'texinfo-ftable) | |
818 (defun texinfo-ftable () | |
819 (texinfo-push-stack 'table "@code") | |
820 (setq fill-column (- fill-column 5)) | |
821 (texinfo-discard-line)) | |
822 | |
823 (put 'description 'texinfo-format 'texinfo-description) | |
824 (defun texinfo-description () | |
825 (texinfo-push-stack 'table "@asis") | |
826 (setq fill-column (- fill-column 5)) | |
827 (texinfo-discard-line)) | |
828 | |
829 (put 'table 'texinfo-end 'texinfo-end-table) | |
830 (put 'ftable 'texinfo-end 'texinfo-end-table) | |
831 (put 'description 'texinfo-end 'texinfo-end-table) | |
832 (defun texinfo-end-table () | |
833 (setq fill-column (+ fill-column 5)) | |
834 (texinfo-discard-command) | |
835 (let ((stacktop | |
836 (texinfo-pop-stack 'table))) | |
837 (texinfo-do-itemize (nth 1 stacktop)))) | |
838 | |
839 ;; At the @end, indent all the lines within the construct | |
840 ;; except those marked with backspace. FROM says where | |
841 ;; construct started. | |
842 (defun texinfo-do-itemize (from) | |
843 (save-excursion | |
844 (while (progn (forward-line -1) | |
845 (>= (point) from)) | |
846 (if (= (following-char) ?\b) | |
847 (save-excursion | |
848 (delete-char 1) | |
849 (end-of-line) | |
850 (delete-char 6)) | |
851 (if (not (looking-at "[ \t]*$")) | |
852 (save-excursion (insert " "))))))) | |
853 | |
854 (put 'item 'texinfo-format 'texinfo-item) | |
855 (put 'itemx 'texinfo-format 'texinfo-item) | |
856 (defun texinfo-item () | |
857 (funcall (get (car (car texinfo-stack)) 'texinfo-item))) | |
858 | |
859 (put 'itemize 'texinfo-item 'texinfo-itemize-item) | |
860 (defun texinfo-itemize-item () | |
861 (texinfo-discard-line) | |
862 (insert "\b " (nth 1 (car texinfo-stack)) " \n") | |
863 (forward-line -1)) | |
864 | |
865 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item) | |
866 (defun texinfo-enumerate-item () | |
867 (texinfo-discard-line) | |
868 (let ((next (1+ (car (cdr (car texinfo-stack)))))) | |
869 (setcar (cdr (car texinfo-stack)) next) | |
870 (insert ?\b (format "%3d. " next) ?\n)) | |
871 (forward-line -1)) | |
872 | |
873 (put 'table 'texinfo-item 'texinfo-table-item) | |
874 (defun texinfo-table-item () | |
875 (let ((arg (texinfo-parse-arg-discard)) | |
876 (itemfont (car (cdr (car texinfo-stack))))) | |
877 (insert ?\b itemfont ?\{ arg "}\n \n")) | |
878 (forward-line -2)) | |
879 | |
880 | |
881 ; @ftable | |
882 | |
883 ; The `@ftable' command is like the `@table' command but it also | |
884 ; inserts each item in the first column into the function index. | |
885 | |
886 (put 'ftable 'texinfo-format 'texinfo-ftable) | |
887 | |
888 ; The following function presumes that the first column of the table | |
889 ; should be in `@code' font; but the texinfo.tex source does not | |
890 ; presume this. | |
891 ; (defun texinfo-ftable () | |
892 ; (texinfo-push-stack 'ftable "@code") | |
893 ; (setq fill-column (- fill-column 5)) | |
894 ; (texinfo-discard-line)) | |
895 | |
896 (defun texinfo-ftable () | |
897 (texinfo-push-stack 'ftable (texinfo-parse-arg-discard)) | |
898 (setq fill-column (- fill-column 5))) | |
899 | |
900 (put 'ftable 'texinfo-item 'texinfo-ftable-item) | |
901 (defun texinfo-ftable-item () | |
902 (let ((item (texinfo-parse-arg-discard)) | |
903 (itemfont (car (cdr (car texinfo-stack)))) | |
904 (indexvar 'texinfo-findex)) | |
905 (insert ?\b itemfont ?\{ item "}\n \n") | |
906 (set indexvar | |
907 (cons | |
908 (list item texinfo-last-node) | |
909 (symbol-value indexvar))) | |
910 (forward-line -2))) | |
911 | |
912 (put 'ftable 'texinfo-end 'texinfo-end-ftable) | |
913 (defun texinfo-end-ftable () | |
914 (setq fill-column (+ fill-column 5)) | |
915 (texinfo-discard-command) | |
916 (let ((stacktop | |
917 (texinfo-pop-stack 'ftable))) | |
918 (texinfo-do-itemize (nth 1 stacktop)))) | |
919 | |
920 | |
921 (put 'ifinfo 'texinfo-format 'texinfo-discard-line) | |
922 (put 'ifinfo 'texinfo-end 'texinfo-discard-command) | |
923 | |
924 (put 'iftex 'texinfo-format 'texinfo-format-iftex) | |
925 (defun texinfo-format-iftex () | |
926 (delete-region texinfo-command-start | |
927 (progn (re-search-forward "@end iftex\n") | |
928 (point)))) | |
929 | |
930 (put 'tex 'texinfo-format 'texinfo-format-tex) | |
931 (defun texinfo-format-tex () | |
932 (delete-region texinfo-command-start | |
933 (progn (re-search-forward "@end tex\n") | |
934 (point)))) | |
935 | |
936 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage) | |
937 (defun texinfo-format-titlepage () | |
938 (delete-region texinfo-command-start | |
939 (progn (search-forward "@end titlepage\n") | |
940 (point)))) | |
941 | |
942 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line) | |
943 | |
944 ; @titlespec an alternative titling command; ignored by Info | |
945 | |
946 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec) | |
947 (defun texinfo-format-titlespec () | |
948 (delete-region texinfo-command-start | |
949 (progn (search-forward "@end titlespec\n") | |
950 (point)))) | |
951 | |
952 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line) | |
953 | |
954 ; @today{} | |
955 | |
956 (put 'today 'texinfo-format 'texinfo-format-today) | |
957 | |
958 ; Produces Day Month Year style of output. eg `1 Jan 1900' | |
959 ; The `@today{}' command requires a pair of braces, like `@dots{}'. | |
960 (defun texinfo-format-today () | |
961 (texinfo-parse-arg-discard) | |
962 (insert (format "%s %s %s" | |
963 (substring (current-time-string) 8 10) | |
964 (substring (current-time-string) 4 7) | |
965 (substring (current-time-string) -4)))) | |
966 | |
967 | |
968 (put 'ignore 'texinfo-format 'texinfo-format-ignore) | |
969 (defun texinfo-format-ignore () | |
970 (delete-region texinfo-command-start | |
971 (progn (search-forward "@end ignore\n") | |
972 (point)))) | |
973 | |
974 (put 'endignore 'texinfo-format 'texinfo-discard-line) | |
975 | |
976 (put 'var 'texinfo-format 'texinfo-format-var) | |
977 ; @sc a small caps font for TeX; formatted as `var' in Info | |
978 (put 'sc 'texinfo-format 'texinfo-format-var) | |
979 (defun texinfo-format-var () | |
980 (insert (upcase (texinfo-parse-arg-discard))) | |
981 (goto-char texinfo-command-start)) | |
982 | |
983 ; various noops | |
984 | |
985 (put 'asis 'texinfo-format 'texinfo-format-noop) | |
986 (put 'b 'texinfo-format 'texinfo-format-noop) | |
987 (put 't 'texinfo-format 'texinfo-format-noop) | |
988 (put 'i 'texinfo-format 'texinfo-format-noop) | |
989 (put 'r 'texinfo-format 'texinfo-format-noop) | |
990 (put 'titlefont 'texinfo-format 'texinfo-format-noop) | |
991 (put 'key 'texinfo-format 'texinfo-format-noop) | |
992 (put 'w 'texinfo-format 'texinfo-format-noop) | |
993 (defun texinfo-format-noop () | |
994 (insert (texinfo-parse-arg-discard)) | |
995 (goto-char texinfo-command-start)) | |
996 | |
997 (put 'code 'texinfo-format 'texinfo-format-code) | |
998 (put 'samp 'texinfo-format 'texinfo-format-code) | |
999 (put 'file 'texinfo-format 'texinfo-format-code) | |
1000 (put 'kbd 'texinfo-format 'texinfo-format-code) | |
1001 (put 'cite 'texinfo-format 'texinfo-format-code) | |
1002 (defun texinfo-format-code () | |
1003 (insert "`" (texinfo-parse-arg-discard) "'") | |
1004 (goto-char texinfo-command-start)) | |
1005 | |
1006 (put 'emph 'texinfo-format 'texinfo-format-emph) | |
1007 (put 'strong 'texinfo-format 'texinfo-format-emph) | |
1008 (defun texinfo-format-emph () | |
1009 (insert "*" (texinfo-parse-arg-discard) "*") | |
1010 (goto-char texinfo-command-start)) | |
1011 | |
1012 (put 'defn 'texinfo-format 'texinfo-format-defn) | |
1013 (put 'dfn 'texinfo-format 'texinfo-format-defn) | |
1014 (defun texinfo-format-defn () | |
1015 (insert "\"" (texinfo-parse-arg-discard) "\"") | |
1016 (goto-char texinfo-command-start)) | |
1017 | |
1018 (put 'bullet 'texinfo-format 'texinfo-format-bullet) | |
1019 (defun texinfo-format-bullet () | |
1020 "Insert an asterisk. | |
1021 If used within a line, follow `@bullet' with braces." | |
1022 (texinfo-optional-braces-discard) | |
1023 (insert "*")) | |
1024 | |
1025 (put 'smallexample 'texinfo-format 'texinfo-format-example) | |
1026 (put 'smalllisp 'texinfo-format 'texinfo-format-example) | |
1027 (put 'example 'texinfo-format 'texinfo-format-example) | |
1028 (put 'quotation 'texinfo-format 'texinfo-format-example) | |
1029 (put 'lisp 'texinfo-format 'texinfo-format-example) | |
1030 (put 'display 'texinfo-format 'texinfo-format-example) | |
1031 (put 'format 'texinfo-format 'texinfo-format-example) | |
1032 (put 'flushleft 'texinfo-format 'texinfo-format-example) | |
1033 (defun texinfo-format-example () | |
1034 (texinfo-push-stack 'example nil) | |
1035 (setq fill-column (- fill-column 5)) | |
1036 (texinfo-discard-line)) | |
1037 | |
1038 (put 'smallexample 'texinfo-end 'texinfo-end-example) | |
1039 (put 'example 'texinfo-end 'texinfo-end-example) | |
1040 (put 'quotation 'texinfo-end 'texinfo-end-example) | |
1041 (put 'lisp 'texinfo-end 'texinfo-end-example) | |
1042 (put 'display 'texinfo-end 'texinfo-end-example) | |
1043 (put 'format 'texinfo-end 'texinfo-end-example) | |
1044 (put 'flushleft 'texinfo-end 'texinfo-end-example) | |
1045 (defun texinfo-end-example () | |
1046 (setq fill-column (+ fill-column 5)) | |
1047 (texinfo-discard-command) | |
1048 (let ((stacktop | |
1049 (texinfo-pop-stack 'example))) | |
1050 (texinfo-do-itemize (nth 1 stacktop)))) | |
1051 | |
1052 (put 'exdent 'texinfo-format 'texinfo-format-exdent) | |
1053 (defun texinfo-format-exdent () | |
1054 (texinfo-discard-command) | |
1055 (delete-region (point) | |
1056 (progn | |
1057 (skip-chars-forward " ") | |
1058 (point))) | |
1059 (insert ?\b) | |
1060 ;; Cancel out the deletion that texinfo-do-itemize | |
1061 ;; is going to do at the end of this line. | |
1062 (save-excursion | |
1063 (end-of-line) | |
1064 (insert "\n "))) | |
1065 | |
1066 | |
1067 ;; @flushright ... @end flushright | |
1068 | |
1069 ; The @flushright command right justifies every line but leaves the | |
1070 ; left end ragged. | |
1071 | |
1072 (put 'flushright 'texinfo-format 'texinfo-format-flushright) | |
1073 (defun texinfo-format-flushright () | |
1074 (texinfo-push-stack 'flushright nil) | |
1075 (texinfo-discard-line)) | |
1076 | |
1077 (put 'flushright 'texinfo-end 'texinfo-end-flushright) | |
1078 (defun texinfo-end-flushright () | |
1079 (texinfo-discard-command) | |
1080 | |
1081 (let ((stacktop | |
1082 (texinfo-pop-stack 'flushright))) | |
1083 | |
1084 (texinfo-do-flushright (nth 1 stacktop)))) | |
1085 | |
1086 (defun texinfo-do-flushright (from) | |
1087 (save-excursion | |
1088 (while (progn (forward-line -1) | |
1089 (>= (point) from)) | |
1090 | |
1091 (beginning-of-line) | |
1092 (insert | |
1093 (make-string | |
1094 (- fill-column | |
1095 (save-excursion | |
1096 (end-of-line) | |
1097 (current-column))) | |
1098 ? ))))) | |
1099 | |
1100 | |
1101 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl) | |
1102 (defun texinfo-format-ctrl () | |
1103 (let ((str (texinfo-parse-arg-discard))) | |
1104 (insert (logand 31 (aref str 0))))) | |
1105 | |
1106 (put 'TeX 'texinfo-format 'texinfo-format-TeX) | |
1107 (defun texinfo-format-TeX () | |
1108 (texinfo-parse-arg-discard) | |
1109 (insert "TeX")) | |
1110 | |
1111 (put 'copyright 'texinfo-format 'texinfo-format-copyright) | |
1112 (defun texinfo-format-copyright () | |
1113 (texinfo-parse-arg-discard) | |
1114 (insert "(C)")) | |
1115 | |
1116 (put 'minus 'texinfo-format 'texinfo-format-minus) | |
1117 (defun texinfo-format-minus () | |
1118 "Insert a minus sign. | |
1119 If used within a line, follow `@minus' with braces." | |
1120 (texinfo-optional-braces-discard) | |
1121 (insert "-")) | |
1122 | |
1123 (put 'dots 'texinfo-format 'texinfo-format-dots) | |
1124 (defun texinfo-format-dots () | |
1125 (texinfo-parse-arg-discard) | |
1126 (insert "...")) | |
1127 | |
1128 (put 'refill 'texinfo-format 'texinfo-format-refill) | |
1129 (defun texinfo-format-refill () | |
1130 (texinfo-discard-command) | |
1131 (fill-paragraph nil)) | |
1132 | |
1133 | |
1134 ;;; Index generation | |
1135 | |
1136 (put 'vindex 'texinfo-format 'texinfo-format-vindex) | |
1137 (defun texinfo-format-vindex () | |
1138 (texinfo-index 'texinfo-vindex)) | |
1139 | |
1140 (put 'cindex 'texinfo-format 'texinfo-format-cindex) | |
1141 (defun texinfo-format-cindex () | |
1142 (texinfo-index 'texinfo-cindex)) | |
1143 | |
1144 (put 'findex 'texinfo-format 'texinfo-format-findex) | |
1145 (defun texinfo-format-findex () | |
1146 (texinfo-index 'texinfo-findex)) | |
1147 | |
1148 (put 'pindex 'texinfo-format 'texinfo-format-pindex) | |
1149 (defun texinfo-format-pindex () | |
1150 (texinfo-index 'texinfo-pindex)) | |
1151 | |
1152 (put 'tindex 'texinfo-format 'texinfo-format-tindex) | |
1153 (defun texinfo-format-tindex () | |
1154 (texinfo-index 'texinfo-tindex)) | |
1155 | |
1156 (put 'kindex 'texinfo-format 'texinfo-format-kindex) | |
1157 (defun texinfo-format-kindex () | |
1158 (texinfo-index 'texinfo-kindex)) | |
1159 | |
1160 (defun texinfo-index (indexvar) | |
1161 (let ((arg (texinfo-parse-expanded-arg))) | |
1162 (texinfo-discard-command) | |
1163 (set indexvar | |
1164 (cons (list arg texinfo-last-node) | |
1165 (symbol-value indexvar))))) | |
1166 | |
1167 (defconst texinfo-indexvar-alist | |
1168 '(("cp" . texinfo-cindex) | |
1169 ("fn" . texinfo-findex) | |
1170 ("vr" . texinfo-vindex) | |
1171 ("tp" . texinfo-tindex) | |
1172 ("pg" . texinfo-pindex) | |
1173 ("ky" . texinfo-kindex))) | |
1174 | |
1175 | |
1176 ;;; @defindex @defcodeindex | |
1177 (put 'defindex 'texinfo-format 'texinfo-format-defindex) | |
1178 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex) | |
1179 | |
1180 (defun texinfo-format-defindex () | |
1181 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa' | |
1182 (indexing-command (intern (concat index-name "index"))) | |
1183 (index-formatting-command ; eg: `texinfo-format-aaindex' | |
1184 (intern (concat "texinfo-format-" index-name "index"))) | |
1185 (index-alist-name ; eg: `texinfo-aaindex' | |
1186 (intern (concat "texinfo-" index-name "index")))) | |
1187 | |
1188 (set index-alist-name nil) | |
1189 | |
1190 (put indexing-command ; eg, aaindex | |
1191 'texinfo-format | |
1192 index-formatting-command) ; eg, texinfo-format-aaindex | |
1193 | |
1194 ;; eg: "aa" . texinfo-aaindex | |
1195 (or (assoc index-name texinfo-indexvar-alist) | |
1196 (setq texinfo-indexvar-alist | |
1197 (cons | |
1198 (cons index-name | |
1199 index-alist-name) | |
1200 texinfo-indexvar-alist))) | |
1201 | |
1202 (fset index-formatting-command | |
1203 (list 'lambda 'nil | |
1204 (list 'texinfo-index | |
1205 (list 'quote index-alist-name)))))) | |
1206 | |
1207 | |
1208 ;;; @synindex @syncodeindex | |
1209 | |
1210 (put 'synindex 'texinfo-format 'texinfo-format-synindex) | |
1211 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex) | |
1212 | |
1213 (defun texinfo-format-synindex () | |
1214 (let* ((args (texinfo-parse-arg-discard)) | |
1215 (second (cdr (read-from-string args))) | |
1216 (joiner (symbol-name (car (read-from-string args)))) | |
1217 (joined (symbol-name (car (read-from-string args second))))) | |
1218 | |
1219 (if (assoc joiner texinfo-short-index-cmds-alist) | |
1220 (put | |
1221 (cdr (assoc joiner texinfo-short-index-cmds-alist)) | |
1222 'texinfo-format | |
1223 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist)) | |
1224 (intern (concat "texinfo-format-" joined "index")))) | |
1225 (put | |
1226 (intern (concat joiner "index")) | |
1227 'texinfo-format | |
1228 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist)) | |
1229 (intern (concat "texinfo-format-" joined "index"))))))) | |
1230 | |
1231 (defconst texinfo-short-index-cmds-alist | |
1232 '(("cp" . cindex) | |
1233 ("fn" . findex) | |
1234 ("vr" . vindex) | |
1235 ("tp" . tindex) | |
1236 ("pg" . pindex) | |
1237 ("ky" . kindex))) | |
1238 | |
1239 (defconst texinfo-short-index-format-cmds-alist | |
1240 '(("cp" . texinfo-format-cindex) | |
1241 ("fn" . texinfo-format-findex) | |
1242 ("vr" . texinfo-format-vindex) | |
1243 ("tp" . texinfo-format-tindex) | |
1244 ("pg" . texinfo-format-pindex) | |
1245 ("ky" . texinfo-format-kindex))) | |
1246 | |
1247 | |
1248 ;;; @printindex | |
1249 | |
1250 (put 'printindex 'texinfo-format 'texinfo-format-printindex) | |
1251 | |
1252 (defun texinfo-format-printindex () | |
1253 (let ((indexelts (symbol-value | |
1254 (cdr (assoc (texinfo-parse-arg-discard) | |
1255 texinfo-indexvar-alist)))) | |
1256 opoint) | |
1257 (insert "\n* Menu:\n\n") | |
1258 (setq opoint (point)) | |
1259 (texinfo-print-index nil indexelts) | |
1260 | |
1261 (if (eq system-type 'vax-vms) | |
1262 (texinfo-sort-region opoint (point)) | |
1263 (shell-command-on-region opoint (point) "sort -fd" 1)))) | |
1264 | |
1265 (defun texinfo-print-index (file indexelts) | |
1266 (while indexelts | |
1267 (if (stringp (car (car indexelts))) | |
1268 (insert "* " (car (car indexelts)) | |
1269 ": " (if file (concat "(" file ")") "") | |
1270 (nth 1 (car indexelts)) ".\n") | |
1271 ;; index entries from @include'd file | |
1272 (texinfo-print-index (nth 1 (car indexelts)) | |
1273 (nth 2 (car indexelts)))) | |
1274 (setq indexelts (cdr indexelts)))) | |
1275 | |
1276 | |
1277 ;;; NOTATIONS: @equiv, @error, etc | |
1278 | |
1279 ;; @equiv to show that two expressions are equivalent | |
1280 ;; @error to show an error message | |
1281 ;; @expansion to show what a macro expands to | |
1282 ;; @point to show the location of point in an example | |
1283 ;; @print to show what an evaluated expression prints | |
1284 ;; @result to indicate the value returned by an expression | |
1285 | |
1286 (put 'equiv 'texinfo-format 'texinfo-format-equiv) | |
1287 (defun texinfo-format-equiv () | |
1288 (texinfo-parse-arg-discard) | |
1289 (insert "==")) | |
1290 | |
1291 (put 'error 'texinfo-format 'texinfo-format-error) | |
1292 (defun texinfo-format-error () | |
1293 (texinfo-parse-arg-discard) | |
1294 (insert "error-->")) | |
1295 | |
1296 (put 'expansion 'texinfo-format 'texinfo-format-expansion) | |
1297 (defun texinfo-format-expansion () | |
1298 (texinfo-parse-arg-discard) | |
1299 (insert "==>")) | |
1300 | |
1301 (put 'point 'texinfo-format 'texinfo-format-point) | |
1302 (defun texinfo-format-point () | |
1303 (texinfo-parse-arg-discard) | |
1304 (insert "-!-")) | |
1305 | |
1306 (put 'print 'texinfo-format 'texinfo-format-print) | |
1307 (defun texinfo-format-print () | |
1308 (texinfo-parse-arg-discard) | |
1309 (insert "-|")) | |
1310 | |
1311 (put 'result 'texinfo-format 'texinfo-format-result) | |
1312 (defun texinfo-format-result () | |
1313 (texinfo-parse-arg-discard) | |
1314 (insert "=>")) | |
1315 | |
1316 | |
1317 ;;;; Description formatting: @deffn, @defun, etc | |
1318 | |
1319 (defun texinfo-format-defun () | |
1320 (texinfo-push-stack 'defun nil) | |
1321 (setq fill-column (- fill-column 5)) | |
1322 (texinfo-format-defun-1 t)) | |
1323 | |
1324 (defun texinfo-format-defunx () | |
1325 (texinfo-format-defun-1 nil)) | |
1326 | |
1327 (defun texinfo-format-defun-1 (first-p) | |
1328 (let ((args (texinfo-format-parse-defun-args)) | |
1329 (command-type (get texinfo-command-name 'texinfo-defun-type)) | |
1330 (class "") | |
1331 (name "") | |
1332 (classification "") | |
1333 (data-type "")) | |
1334 (texinfo-discard-command) | |
1335 | |
1336 (cond | |
1337 ;; Generalized object oriented entity: `category class name [args...]' | |
1338 ;; In Info, `Category on class: name ARG' | |
1339 ((eq (eval (car command-type)) 'defop-type) | |
1340 (setq category (car args)) | |
1341 (setq class (car (cdr args))) | |
1342 (setq name (car args)) | |
1343 (setq args (cdr (cdr args)))) | |
1344 | |
1345 ;; Specialized object oriented entity: @defmethod, @defivar | |
1346 ;; "Instance Variable" `class name [args...]' | |
1347 ;; In Info, `Instance variable of class: name' | |
1348 ((eq (eval (car command-type)) 'defmethod-type) | |
1349 (setq category (car (cdr command-type))) | |
1350 (setq class (car args)) | |
1351 (setq name (car args)) | |
1352 (setq args (cdr args))) | |
1353 | |
1354 ;; Generalized function-like or variable-like entity: | |
1355 ;; `category name [args...]' | |
1356 ;; In Info, `Category: name ARGS' | |
1357 ((or (eq (eval (car command-type)) 'deffn-type) | |
1358 (eq (eval (car command-type)) 'deftp-type)) | |
1359 (setq category (car args)) | |
1360 (setq args (cdr args)) | |
1361 (setq name (car args))) | |
1362 | |
1363 ;; Specialized function-like or variable-like entity: | |
1364 ;; "Macro" `name [args...]' | |
1365 ;; In Info, `Macro: Name ARGS' | |
1366 ((eq (eval (car command-type)) 'defun-type) | |
1367 (setq category (car (cdr command-type))) | |
1368 (setq name (car args))) | |
1369 | |
1370 ;; Generalized typed-function-like or typed-variable-like entity: | |
1371 ;; `Classification data-type name [args...]' | |
1372 ;; In Info, `Classification: data-type name ARGS' | |
1373 ((or (eq (eval (car command-type)) 'deftypefn-type) | |
1374 (eq (eval (car command-type)) 'deftypevr-type)) | |
1375 (setq classification (car args)) | |
1376 (setq data-type (car (cdr args))) | |
1377 (setq name (car (cdr (cdr args)))) | |
1378 (setq args (cdr (cdr (cdr args))))) | |
1379 | |
1380 ;; Specialized typed-function-like or typed-variable-like entity: | |
1381 ;; `data-type name [args...]' | |
1382 ;; In Info, `Function: data-type name ARGS' | |
1383 ;; or, `Variable: data-type name' | |
1384 ((or (eq (eval (car command-type)) 'deftypefun-type) | |
1385 (eq (eval (car command-type)) 'deftypevar-type)) | |
1386 (setq classification (car (cdr command-type))) | |
1387 (setq data-type (car args)) | |
1388 (setq name (car (cdr args))) | |
1389 (setq args (cdr (cdr args))))) | |
1390 | |
1391 ;; Delete extra newline inserted after previous header line. | |
1392 (if (not first-p) | |
1393 (delete-char -1)) | |
1394 | |
1395 (let ((formatter (get texinfo-command-name 'texinfo-defun-format-type))) | |
1396 (cond | |
1397 ;; if typed function or variable | |
1398 ((eq formatter 'texinfo-format-deftypefn-type) | |
1399 (insert "* " classification ": " data-type " " name) | |
1400 (let ((args args)) | |
1401 (while args | |
1402 (insert " " (car args)) | |
1403 (setq args (cdr args))))) | |
1404 (t | |
1405 ;; and if object oriented, set category | |
1406 (if (or (eq formatter 'texinfo-format-defop-type) | |
1407 (eq formatter 'texinfo-format-defcv-type)) | |
1408 (setq category (funcall formatter category class))) | |
1409 (insert "* " category ": " name) | |
1410 (let ((args (cdr args))) | |
1411 (while args | |
1412 (insert " " | |
1413 (if (or (= ?& (aref (car args) 0)) | |
1414 (eq (eval (car command-type)) 'deftp-type)) | |
1415 (car args) | |
1416 (upcase (car args)))) | |
1417 (setq args (cdr args))))))) | |
1418 | |
1419 ;; Insert extra newline so that paragraph filling does not mess | |
1420 ;; with header line. | |
1421 (insert "\n\n") | |
1422 (rplaca (cdr (cdr (car texinfo-stack))) (point)) | |
1423 | |
1424 (let ((indexvar (get texinfo-command-name 'texinfo-defun-index)) | |
1425 (index-formatter | |
1426 (get texinfo-command-name 'texinfo-defun-format-index))) | |
1427 (set indexvar | |
1428 (cons (list | |
1429 (cond | |
1430 ;; if object oriented | |
1431 ((or (eq index-formatter 'texinfo-format-defop-index) | |
1432 (eq index-formatter 'texinfo-format-defcv-index)) | |
1433 (funcall index-formatter name class)) | |
1434 ((eq index-formatter 'texinfo-format-deftypefn-index) | |
1435 (funcall index-formatter name data-type)) | |
1436 (t (car args))) | |
1437 texinfo-last-node) | |
1438 (symbol-value indexvar)))))) | |
1439 | |
1440 (defun texinfo-end-defun () | |
1441 (setq fill-column (+ fill-column 5)) | |
1442 (texinfo-discard-command) | |
1443 (let ((start (nth 1 (texinfo-pop-stack 'defun)))) | |
1444 (texinfo-do-itemize start) | |
1445 ;; Delete extra newline inserted after header. | |
1446 (save-excursion | |
1447 (goto-char start) | |
1448 (delete-char -1)))) | |
1449 | |
1450 (defun texinfo-format-defop-type (category class) | |
1451 (format "%s on %s" category class)) | |
1452 | |
1453 (defun texinfo-format-defop-index (name class) | |
1454 (format "%s on %s" name class)) | |
1455 | |
1456 (defun texinfo-format-defcv-type (category class) | |
1457 (format "%s of %s" category class)) | |
1458 | |
1459 (defun texinfo-format-defcv-index (name class) | |
1460 (format "%s of %s" name class)) | |
1461 | |
1462 (put 'deffn 'texinfo-format 'texinfo-format-defun) | |
1463 (put 'deffnx 'texinfo-format 'texinfo-format-defunx) | |
1464 (put 'deffn 'texinfo-end 'texinfo-end-defun) | |
1465 (put 'deffn 'texinfo-defun-type '('deffn-type nil)) | |
1466 (put 'deffnx 'texinfo-defun-type '('deffn-type nil)) | |
1467 (put 'deffn 'texinfo-defun-index 'texinfo-findex) | |
1468 (put 'deffnx 'texinfo-defun-index 'texinfo-findex) | |
1469 | |
1470 (put 'defun 'texinfo-format 'texinfo-format-defun) | |
1471 (put 'defunx 'texinfo-format 'texinfo-format-defunx) | |
1472 (put 'defun 'texinfo-end 'texinfo-end-defun) | |
1473 (put 'defun 'texinfo-defun-type '('defun-type "Function")) | |
1474 (put 'defunx 'texinfo-defun-type '('defun-type "Function")) | |
1475 (put 'defun 'texinfo-defun-index 'texinfo-findex) | |
1476 (put 'defunx 'texinfo-defun-index 'texinfo-findex) | |
1477 | |
1478 (put 'defmac 'texinfo-format 'texinfo-format-defun) | |
1479 (put 'defmacx 'texinfo-format 'texinfo-format-defunx) | |
1480 (put 'defmac 'texinfo-end 'texinfo-end-defun) | |
1481 (put 'defmac 'texinfo-defun-type '('defun-type "Macro")) | |
1482 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro")) | |
1483 (put 'defmac 'texinfo-defun-index 'texinfo-findex) | |
1484 (put 'defmacx 'texinfo-defun-index 'texinfo-findex) | |
1485 | |
1486 (put 'defspec 'texinfo-format 'texinfo-format-defun) | |
1487 (put 'defspecx 'texinfo-format 'texinfo-format-defunx) | |
1488 (put 'defspec 'texinfo-end 'texinfo-end-defun) | |
1489 (put 'defspec 'texinfo-defun-type '('defun-type "Special form")) | |
1490 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form")) | |
1491 (put 'defspec 'texinfo-defun-index 'texinfo-findex) | |
1492 (put 'defspecx 'texinfo-defun-index 'texinfo-findex) | |
1493 | |
1494 (put 'defvr 'texinfo-format 'texinfo-format-defun) | |
1495 (put 'defvrx 'texinfo-format 'texinfo-format-defunx) | |
1496 (put 'defvr 'texinfo-end 'texinfo-end-defun) | |
1497 (put 'defvr 'texinfo-defun-type '('deffn-type nil)) | |
1498 (put 'defvrx 'texinfo-defun-type '('deffn-type nil)) | |
1499 (put 'defvr 'texinfo-defun-index 'texinfo-vindex) | |
1500 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex) | |
1501 | |
1502 (put 'defvar 'texinfo-format 'texinfo-format-defun) | |
1503 (put 'defvarx 'texinfo-format 'texinfo-format-defunx) | |
1504 (put 'defvar 'texinfo-end 'texinfo-end-defun) | |
1505 (put 'defvar 'texinfo-defun-type '('defun-type "Variable")) | |
1506 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable")) | |
1507 (put 'defvar 'texinfo-defun-index 'texinfo-vindex) | |
1508 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex) | |
1509 | |
1510 (put 'defconst 'texinfo-format 'texinfo-format-defun) | |
1511 (put 'defconstx 'texinfo-format 'texinfo-format-defunx) | |
1512 (put 'defconst 'texinfo-end 'texinfo-end-defun) | |
1513 (put 'defconst 'texinfo-defun-type '('defun-type "Constant")) | |
1514 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant")) | |
1515 (put 'defconst 'texinfo-defun-index 'texinfo-vindex) | |
1516 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex) | |
1517 | |
1518 (put 'defcmd 'texinfo-format 'texinfo-format-defun) | |
1519 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx) | |
1520 (put 'defcmd 'texinfo-end 'texinfo-end-defun) | |
1521 (put 'defcmd 'texinfo-defun-type '('defun-type "Command")) | |
1522 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command")) | |
1523 (put 'defcmd 'texinfo-defun-index 'texinfo-findex) | |
1524 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex) | |
1525 | |
1526 (put 'defopt 'texinfo-format 'texinfo-format-defun) | |
1527 (put 'defoptx 'texinfo-format 'texinfo-format-defunx) | |
1528 (put 'defopt 'texinfo-end 'texinfo-end-defun) | |
1529 (put 'defopt 'texinfo-defun-type '('defun-type "User Option")) | |
1530 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option")) | |
1531 (put 'defopt 'texinfo-defun-index 'texinfo-vindex) | |
1532 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex) | |
1533 | |
1534 (put 'deftp 'texinfo-format 'texinfo-format-defun) | |
1535 (put 'deftpx 'texinfo-format 'texinfo-format-defunx) | |
1536 (put 'deftp 'texinfo-end 'texinfo-end-defun) | |
1537 (put 'deftp 'texinfo-defun-type '('deftp-type nil)) | |
1538 (put 'deftpx 'texinfo-defun-type '('deftp-type nil)) | |
1539 (put 'deftp 'texinfo-defun-index 'texinfo-tindex) | |
1540 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex) | |
1541 | |
1542 ;;; Object-oriented stuff is a little hairier. | |
1543 | |
1544 (put 'defop 'texinfo-format 'texinfo-format-defun) | |
1545 (put 'defopx 'texinfo-format 'texinfo-format-defunx) | |
1546 (put 'defop 'texinfo-end 'texinfo-end-defun) | |
1547 (put 'defop 'texinfo-defun-type '('defop-type nil)) | |
1548 (put 'defopx 'texinfo-defun-type '('defop-type nil)) | |
1549 (put 'defop 'texinfo-defun-format-type 'texinfo-format-defop-type) | |
1550 (put 'defopx 'texinfo-defun-format-type 'texinfo-format-defop-type) | |
1551 (put 'defop 'texinfo-defun-index 'texinfo-findex) | |
1552 (put 'defopx 'texinfo-defun-index 'texinfo-findex) | |
1553 (put 'defop 'texinfo-defun-format-index 'texinfo-format-defop-index) | |
1554 (put 'defopx 'texinfo-defun-format-index 'texinfo-format-defop-index) | |
1555 | |
1556 (put 'defmethod 'texinfo-format 'texinfo-format-defun) | |
1557 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx) | |
1558 (put 'defmethod 'texinfo-end 'texinfo-end-defun) | |
1559 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Operation")) | |
1560 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Operation")) | |
1561 (put 'defmethod 'texinfo-defun-format-type 'texinfo-format-defop-type) | |
1562 (put 'defmethodx 'texinfo-defun-format-type 'texinfo-format-defop-type) | |
1563 (put 'defmethod 'texinfo-defun-index 'texinfo-findex) | |
1564 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex) | |
1565 (put 'defmethod 'texinfo-defun-format-index 'texinfo-format-defop-index) | |
1566 (put 'defmethodx 'texinfo-defun-format-index 'texinfo-format-defop-index) | |
1567 | |
1568 (put 'defcv 'texinfo-format 'texinfo-format-defun) | |
1569 (put 'defcvx 'texinfo-format 'texinfo-format-defunx) | |
1570 (put 'defcv 'texinfo-end 'texinfo-end-defun) | |
1571 (put 'defcv 'texinfo-defun-type '('defop-type nil)) | |
1572 (put 'defcvx 'texinfo-defun-type '('defop-type nil)) | |
1573 (put 'defcv 'texinfo-defun-format-type 'texinfo-format-defcv-type) | |
1574 (put 'defcvx 'texinfo-defun-format-type 'texinfo-format-defcv-type) | |
1575 (put 'defcv 'texinfo-defun-index 'texinfo-vindex) | |
1576 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex) | |
1577 (put 'defcv 'texinfo-defun-format-index 'texinfo-format-defcv-index) | |
1578 (put 'defcvx 'texinfo-defun-format-index 'texinfo-format-defcv-index) | |
1579 | |
1580 (put 'defivar 'texinfo-format 'texinfo-format-defun) | |
1581 (put 'defivarx 'texinfo-format 'texinfo-format-defunx) | |
1582 (put 'defivar 'texinfo-end 'texinfo-end-defun) | |
1583 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable")) | |
1584 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable")) | |
1585 (put 'defivar 'texinfo-defun-format-type 'texinfo-format-defcv-type) | |
1586 (put 'defivarx 'texinfo-defun-format-type 'texinfo-format-defcv-type) | |
1587 (put 'defivar 'texinfo-defun-index 'texinfo-vindex) | |
1588 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex) | |
1589 (put 'defivar 'texinfo-defun-format-index 'texinfo-format-defcv-index) | |
1590 (put 'defivarx 'texinfo-defun-format-index 'texinfo-format-defcv-index) | |
1591 | |
1592 ;;; Typed functions and variables | |
1593 | |
1594 (defun texinfo-format-deftypefn-type (classification data-type) | |
1595 (format "%s" classification data-type)) | |
1596 | |
1597 (defun texinfo-format-deftypefn-index (name data-type) | |
1598 (format "%s of type %s" name data-type)) | |
1599 | |
1600 | |
1601 (put 'deftypefn 'texinfo-format 'texinfo-format-defun) | |
1602 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx) | |
1603 (put 'deftypefn 'texinfo-end 'texinfo-end-defun) | |
1604 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil)) | |
1605 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil)) | |
1606 (put 'deftypefn 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1607 (put 'deftypefnx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1608 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex) | |
1609 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex) | |
1610 (put 'deftypefn 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1611 (put 'deftypefnx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1612 | |
1613 (put 'deftypefun 'texinfo-format 'texinfo-format-defun) | |
1614 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx) | |
1615 (put 'deftypefun 'texinfo-end 'texinfo-end-defun) | |
1616 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function")) | |
1617 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function")) | |
1618 (put 'deftypefun 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1619 (put 'deftypefunx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1620 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex) | |
1621 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex) | |
1622 (put 'deftypefun 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1623 (put 'deftypefunx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1624 | |
1625 (put 'deftypevr 'texinfo-format 'texinfo-format-defun) | |
1626 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx) | |
1627 (put 'deftypevr 'texinfo-end 'texinfo-end-defun) | |
1628 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil)) | |
1629 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil)) | |
1630 (put 'deftypevr 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1631 (put 'deftypevrx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1632 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex) | |
1633 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex) | |
1634 (put 'deftypevr 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1635 (put 'deftypevrx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1636 | |
1637 (put 'deftypevar 'texinfo-format 'texinfo-format-defun) | |
1638 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx) | |
1639 (put 'deftypevar 'texinfo-end 'texinfo-end-defun) | |
1640 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable")) | |
1641 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable")) | |
1642 (put 'deftypevar 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1643 (put 'deftypevarx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type) | |
1644 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex) | |
1645 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex) | |
1646 (put 'deftypevar 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1647 (put 'deftypevarx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index) | |
1648 | |
1649 | |
1650 ;; process included files: `@include' command | |
1651 | |
1652 ;; Updated 19 October 1990 | |
1653 ;; In the original version, include files were ignored by Info but | |
1654 ;; incorporated in to the printed manual. To make references to the | |
1655 ;; included file, the Texinfo source file has to refer to the included | |
1656 ;; files using the `(filename)nodename' format for refering to other | |
1657 ;; Info files. Also, the included files had to be formatted on their | |
1658 ;; own. It was just like they were another file. | |
1659 | |
1660 ;; Currently, include files are inserted into the buffer that is | |
1661 ;; formatted for Info. If large, the resulting info file is split and | |
1662 ;; tagified. For current include files to work, the master menu must | |
1663 ;; refer to all the nodes, and the highest level nodes in the include | |
1664 ;; files must have the correct next, prev, and up pointers. | |
1665 | |
1666 ;; The included file may have an @setfilename and even an @settitle, | |
1667 ;; but not an /input texinfo | |
1668 | |
1669 ; Original definition: | |
1670 ; (defun texinfo-format-include () | |
1671 ; (let ((filename (texinfo-parse-arg-discard)) | |
1672 ; (default-directory input-directory) | |
1673 ; subindex) | |
1674 ; (setq subindex | |
1675 ; (save-excursion | |
1676 ; (progn (find-file | |
1677 ; (cond ((file-readable-p (concat filename ".texinfo")) | |
1678 ; (concat filename ".texinfo")) | |
1679 ; ((file-readable-p (concat filename ".texi")) | |
1680 ; (concat filename ".texi")) | |
1681 ; ((file-readable-p (concat filename ".tex")) | |
1682 ; (concat filename ".tex")) | |
1683 ; ((file-readable-p filename) | |
1684 ; filename) | |
1685 ; (t (error "@include'd file %s not found" | |
1686 ; filename)))) | |
1687 ; (texinfo-format-buffer-1)))) | |
1688 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex)) | |
1689 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex)) | |
1690 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex)) | |
1691 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex)) | |
1692 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex)) | |
1693 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex)))) | |
1694 | |
1695 (defun texinfo-subindex (indexvar file content) | |
1696 (set indexvar (cons (list 'recurse file content) | |
1697 (symbol-value indexvar)))) | |
1698 | |
1699 (put 'include 'texinfo-format 'texinfo-format-include) | |
1700 (defun texinfo-format-include () | |
1701 (let ((filename (concat input-directory | |
1702 (texinfo-parse-arg-discard))) | |
1703 (default-directory input-directory)) | |
1704 (message "Reading: %s" filename) | |
1705 (save-excursion | |
1706 (insert-file-contents filename))) | |
1707 (setq last-input-buffer input-buffer) ; to bypass setfilename | |
1708 ) | |
1709 | |
1710 | |
1711 | |
1712 ;; Lots of bolio constructs do nothing in texinfo. | |
1713 | |
1714 (put 'page 'texinfo-format 'texinfo-discard-line-with-args) | |
1715 (put 'c 'texinfo-format 'texinfo-discard-line-with-args) | |
1716 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args) | |
1717 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args) | |
1718 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args) | |
1719 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args) | |
1720 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args) | |
1721 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args) | |
1722 (put 'noindent 'texinfo-format 'texinfo-discard-line-with-args) | |
1723 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args) | |
1724 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args) | |
1725 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args) | |
1726 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args) | |
1727 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args) | |
1728 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args) | |
1729 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args) | |
1730 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args) | |
1731 (put 'group 'texinfo-format 'texinfo-discard-line-with-args) | |
1732 (put 'group 'texinfo-end 'texinfo-discard-line-with-args) | |
1733 (put 'need 'texinfo-format 'texinfo-discard-line-with-args) | |
1734 (put 'bye 'texinfo-format 'texinfo-discard-line) | |
1735 (put 'smallbook 'texinfo-format 'texinfo-discard-line) | |
1736 | |
1737 (defun texinfo-discard-line-with-args () | |
1738 (goto-char texinfo-command-start) | |
1739 (delete-region (point) (progn (forward-line 1) (point)))) | |
1740 | |
1741 ;; Sort an index which is in the current buffer between START and END. | |
1742 ;; Used on VMS, where the `sort' utility is not available. | |
1743 (defun texinfo-sort-region (start end) | |
1744 (require 'sort) | |
1745 (save-restriction | |
1746 (narrow-to-region start end) | |
1747 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun))) | |
1748 | |
1749 ;; Subroutine for sorting an index. | |
1750 ;; At start of a line, return a string to sort the line under. | |
1751 (defun texinfo-sort-startkeyfun () | |
1752 (let ((line | |
1753 (buffer-substring (point) (save-excursion (end-of-line) (point))))) | |
1754 ;; Canonicalize whitespace and eliminate funny chars. | |
1755 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line) | |
1756 (setq line (concat (substring line 0 (match-beginning 0)) | |
1757 " " | |
1758 (substring line (match-end 0) (length line))))) | |
1759 line)) | |
1760 | |
1761 ;; Some cannot be handled | |
1762 | |
1763 (defun texinfo-unsupported () | |
1764 (error "%s is not handled by texinfo" | |
1765 (buffer-substring texinfo-command-start texinfo-command-end))) | |
1766 | |
258 | 1767 ;;;###autoload |
189 | 1768 (defun batch-texinfo-format () |
1576 | 1769 "Runs `texinfo-format-buffer' on the files remaining on the command line. |
189 | 1770 Must be used only with -batch, and kills emacs on completion. |
1771 Each file will be processed even if an error occurred previously. | |
1772 For example, invoke | |
1773 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"." | |
1774 (if (not noninteractive) | |
1775 (error "batch-texinfo-format may only be used -batch.")) | |
1776 (let ((version-control t) | |
1777 (auto-save-default nil) | |
1778 (find-file-run-dired nil) | |
1779 (kept-old-versions 259259) | |
1780 (kept-new-versions 259259)) | |
1781 (let ((error 0) | |
1782 file | |
1783 (files ())) | |
1784 (while command-line-args-left | |
1785 (setq file (expand-file-name (car command-line-args-left))) | |
1786 (cond ((not (file-exists-p file)) | |
1787 (message ">> %s does not exist!" file) | |
1788 (setq error 1 | |
1789 command-line-args-left (cdr command-line-args-left))) | |
1790 ((file-directory-p file) | |
1791 (setq command-line-args-left | |
1792 (nconc (directory-files file) | |
1793 (cdr command-line-args-left)))) | |
1794 (t | |
1795 (setq files (cons file files) | |
1796 command-line-args-left (cdr command-line-args-left))))) | |
1797 (while files | |
1798 (setq file (car files) | |
1799 files (cdr files)) | |
1800 (condition-case err | |
1801 (progn | |
1802 (if buffer-file-name (kill-buffer (current-buffer))) | |
1803 (find-file file) | |
1804 (buffer-disable-undo (current-buffer)) | |
1805 (set-buffer-modified-p nil) | |
1806 (texinfo-mode) | |
1807 (message "texinfo formatting %s..." file) | |
1808 (texinfo-format-buffer nil) | |
1809 (if (buffer-modified-p) | |
1810 (progn (message "Saving modified %s" (buffer-file-name)) | |
1811 (save-buffer)))) | |
1812 (error | |
1813 (message ">> Error: %s" (prin1-to-string err)) | |
1814 (message ">> point at") | |
1815 (let ((s (buffer-substring (point) | |
1816 (min (+ (point) 100) | |
1817 (point-max)))) | |
1818 (tem 0)) | |
1819 (while (setq tem (string-match "\n+" s tem)) | |
1820 (setq s (concat (substring s 0 (match-beginning 0)) | |
1821 "\n>> " | |
1822 (substring s (match-end 0))) | |
1823 tem (1+ tem))) | |
1824 (message ">> %s" s)) | |
1825 (setq error 1)))) | |
1826 (kill-emacs error)))) | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1827 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1828 ;;; texinfmt.el ends here |