Mercurial > hg > xemacs-beta
comparison lisp/packages/texinfmt.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;;; texinfmt.el | |
2 ;;; Copyright (C) 1985, 1986, 1988, 1990, 1991, | |
3 ;;; 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu> | |
6 | |
7 ;;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Synched up with: FSF 19.30. | |
24 | |
25 ;;; Code: | |
26 | |
27 ;;; Emacs lisp functions to convert Texinfo files to Info files. | |
28 | |
29 (defvar texinfmt-version "2.34 of 7 June 1995") | |
30 | |
31 ;;; Variable definitions | |
32 | |
33 (require 'texinfo) ; So `texinfo-footnote-style' is defined. | |
34 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined. | |
35 | |
36 (defvar texinfo-format-syntax-table nil) | |
37 | |
38 (defvar texinfo-vindex) | |
39 (defvar texinfo-findex) | |
40 (defvar texinfo-cindex) | |
41 (defvar texinfo-pindex) | |
42 (defvar texinfo-tindex) | |
43 (defvar texinfo-kindex) | |
44 (defvar texinfo-last-node) | |
45 (defvar texinfo-node-names) | |
46 (defvar texinfo-enclosure-list) | |
47 (defvar texinfo-alias-list) | |
48 | |
49 (defvar texinfo-command-start) | |
50 (defvar texinfo-command-end) | |
51 (defvar texinfo-command-name) | |
52 (defvar texinfo-defun-type) | |
53 (defvar texinfo-last-node-pos) | |
54 (defvar texinfo-stack) | |
55 (defvar texinfo-short-index-cmds-alist) | |
56 (defvar texinfo-short-index-format-cmds-alist) | |
57 (defvar texinfo-format-filename) | |
58 (defvar texinfo-footnote-number) | |
59 (defvar texinfo-start-of-header) | |
60 (defvar texinfo-end-of-header) | |
61 (defvar texinfo-raisesections-alist) | |
62 (defvar texinfo-lowersections-alist) | |
63 | |
64 ;;; Syntax table | |
65 | |
66 (if texinfo-format-syntax-table | |
67 nil | |
68 (setq texinfo-format-syntax-table (make-syntax-table)) | |
69 (modify-syntax-entry ?\" " " texinfo-format-syntax-table) | |
70 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table) | |
71 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table) | |
72 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table) | |
73 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table) | |
74 (modify-syntax-entry ?\] "." texinfo-format-syntax-table) | |
75 (modify-syntax-entry ?\( "." texinfo-format-syntax-table) | |
76 (modify-syntax-entry ?\) "." texinfo-format-syntax-table) | |
77 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table) | |
78 (modify-syntax-entry ?} "){" texinfo-format-syntax-table) | |
79 (modify-syntax-entry ?\' "." texinfo-format-syntax-table)) | |
80 | |
81 | |
82 ;;; Top level buffer and region formatting functions | |
83 | |
84 ;;;###autoload | |
85 (defun texinfo-format-buffer (&optional notagify) | |
86 "Process the current buffer as texinfo code, into an Info file. | |
87 The Info file output is generated in a buffer visiting the Info file | |
88 names specified in the @setfilename command. | |
89 | |
90 Non-nil argument (prefix, if interactive) means don't make tag table | |
91 and don't split the file if large. You can use Info-tagify and | |
92 Info-split to do these manually." | |
93 (interactive "P") | |
94 (let ((lastmessage "Formatting Info file...")) | |
95 (message lastmessage) | |
96 (texinfo-format-buffer-1) | |
97 (if notagify | |
98 nil | |
99 (if (> (buffer-size) 30000) | |
100 (progn | |
101 (message (setq lastmessage "Making tags table for Info file...")) | |
102 (Info-tagify))) | |
103 (if (> (buffer-size) 100000) | |
104 (progn | |
105 (message (setq lastmessage "Splitting Info file...")) | |
106 (Info-split)))) | |
107 (message (concat lastmessage | |
108 (if (interactive-p) "done. Now save it." "done."))))) | |
109 | |
110 (defvar texinfo-region-buffer-name "*Info Region*" | |
111 "*Name of the temporary buffer used by \\[texinfo-format-region].") | |
112 | |
113 ;;;###autoload | |
114 (defun texinfo-format-region (region-beginning region-end) | |
115 "Convert the current region of the Texinfo file to Info format. | |
116 This lets you see what that part of the file will look like in Info. | |
117 The command is bound to \\[texinfo-format-region]. The text that is | |
118 converted to Info is stored in a temporary buffer." | |
119 (interactive "r") | |
120 (message "Converting region to Info format...") | |
121 (let (texinfo-command-start | |
122 texinfo-command-end | |
123 texinfo-command-name | |
124 texinfo-vindex | |
125 texinfo-findex | |
126 texinfo-cindex | |
127 texinfo-pindex | |
128 texinfo-tindex | |
129 texinfo-kindex | |
130 texinfo-stack | |
131 (texinfo-format-filename "") | |
132 texinfo-example-start | |
133 texinfo-last-node-pos | |
134 texinfo-last-node | |
135 texinfo-node-names | |
136 (texinfo-footnote-number 0) | |
137 last-input-buffer | |
138 (fill-column-for-info fill-column) | |
139 (input-buffer (current-buffer)) | |
140 (input-directory default-directory) | |
141 (header-text "") | |
142 (header-beginning 1) | |
143 (header-end 1)) | |
144 | |
145 ;;; Copy lines between beginning and end of header lines, | |
146 ;;; if any, or else copy the `@setfilename' line, if any. | |
147 (save-excursion | |
148 (save-restriction | |
149 (widen) | |
150 (goto-char (point-min)) | |
151 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
152 (if (or | |
153 ;; Either copy header text. | |
154 (and | |
155 (prog1 | |
156 (search-forward tex-start-of-header search-end t) | |
157 (forward-line 1) | |
158 ;; Mark beginning of header. | |
159 (setq header-beginning (point))) | |
160 (prog1 | |
161 (search-forward tex-end-of-header nil t) | |
162 (beginning-of-line) | |
163 ;; Mark end of header | |
164 (setq header-end (point)))) | |
165 ;; Or copy @filename line. | |
166 (prog2 | |
167 (goto-char (point-min)) | |
168 (search-forward "@setfilename" search-end t) | |
169 (beginning-of-line) | |
170 (setq header-beginning (point)) | |
171 (forward-line 1) | |
172 (setq header-end (point)))) | |
173 | |
174 ;; Copy header | |
175 (setq header-text | |
176 (buffer-substring | |
177 (min header-beginning region-beginning) | |
178 header-end)))))) | |
179 | |
180 ;;; Find a buffer to use. | |
181 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) | |
182 (erase-buffer) | |
183 ;; Insert the header into the buffer. | |
184 (insert header-text) | |
185 ;; Insert the region into the buffer. | |
186 (insert-buffer-substring | |
187 input-buffer | |
188 (max region-beginning header-end) | |
189 region-end) | |
190 ;; Make sure region ends in a newline. | |
191 (or (= (preceding-char) ?\n) | |
192 (insert "\n")) | |
193 | |
194 (goto-char (point-min)) | |
195 (texinfo-mode) | |
196 (message "Converting region to Info format...") | |
197 (setq fill-column fill-column-for-info) | |
198 ;; Install a syntax table useful for scanning command operands. | |
199 (set-syntax-table texinfo-format-syntax-table) | |
200 | |
201 ;; Insert @include files so `texinfo-raise-lower-sections' can | |
202 ;; work on them without losing track of multiple | |
203 ;; @raise/@lowersections commands. | |
204 (while (re-search-forward "^@include" nil t) | |
205 (setq texinfo-command-end (point)) | |
206 (let ((filename (concat input-directory | |
207 (texinfo-parse-line-arg)))) | |
208 (re-search-backward "^@include") | |
209 (delete-region (point) (save-excursion (forward-line 1) (point))) | |
210 (message "Reading included file: %s" filename) | |
211 (save-excursion | |
212 (save-restriction | |
213 (narrow-to-region | |
214 (point) | |
215 (+ (point) (car (cdr (insert-file-contents filename))))) | |
216 (goto-char (point-min)) | |
217 ;; Remove `@setfilename' line from included file, if any, | |
218 ;; so @setfilename command not duplicated. | |
219 (if (re-search-forward | |
220 "^@setfilename" (save-excursion (forward-line 100) (point)) t) | |
221 (progn | |
222 (beginning-of-line) | |
223 (delete-region | |
224 (point) (save-excursion (forward-line 1) (point))))))))) | |
225 | |
226 ;; Raise or lower level of each section, if necessary. | |
227 (goto-char (point-min)) | |
228 (texinfo-raise-lower-sections) | |
229 ;; Append @refill to appropriate paragraphs for filling. | |
230 (goto-char (point-min)) | |
231 (texinfo-append-refill) | |
232 ;; If the region includes the effective end of the data, | |
233 ;; discard everything after that. | |
234 (goto-char (point-max)) | |
235 (if (re-search-backward "^@bye" nil t) | |
236 (delete-region (point) (point-max))) | |
237 ;; Make sure buffer ends in a newline. | |
238 (or (= (preceding-char) ?\n) | |
239 (insert "\n")) | |
240 ;; Don't use a previous value of texinfo-enclosure-list. | |
241 (setq texinfo-enclosure-list nil) | |
242 (setq texinfo-alias-list nil) | |
243 | |
244 (goto-char (point-min)) | |
245 (if (looking-at "\\\\input[ \t]+texinfo") | |
246 (delete-region (point) (save-excursion (forward-line 1) (point)))) | |
247 | |
248 ;; Insert Info region title text. | |
249 (goto-char (point-min)) | |
250 (if (search-forward | |
251 "@setfilename" (save-excursion (forward-line 100) (point)) t) | |
252 (progn | |
253 (setq texinfo-command-end (point)) | |
254 (beginning-of-line) | |
255 (setq texinfo-command-start (point)) | |
256 (let ((arg (texinfo-parse-arg-discard))) | |
257 (insert " " | |
258 texinfo-region-buffer-name | |
259 " buffer for: `") | |
260 (insert (file-name-nondirectory (expand-file-name arg))) | |
261 (insert "', -*-Text-*-\n"))) | |
262 ;; Else no `@setfilename' line | |
263 (insert " " | |
264 texinfo-region-buffer-name | |
265 " buffer -*-Text-*-\n")) | |
266 (insert "produced by `texinfo-format-region'\n" | |
267 "from a region in: " | |
268 (if (buffer-file-name input-buffer) | |
269 (concat "`" | |
270 (file-name-sans-versions | |
271 (file-name-nondirectory | |
272 (buffer-file-name input-buffer))) | |
273 "'") | |
274 (concat "buffer `" (buffer-name input-buffer) "'")) | |
275 "\nusing `texinfmt.el' version " | |
276 texinfmt-version | |
277 ".\n\n") | |
278 | |
279 ;; Now convert for real. | |
280 (goto-char (point-min)) | |
281 (texinfo-format-scan) | |
282 (goto-char (point-min)) | |
283 | |
284 (message "Done."))) | |
285 | |
286 | |
287 ;;; Primary internal formatting function for the whole buffer. | |
288 | |
289 (defun texinfo-format-buffer-1 () | |
290 (let (texinfo-format-filename | |
291 texinfo-example-start | |
292 texinfo-command-start | |
293 texinfo-command-end | |
294 texinfo-command-name | |
295 texinfo-last-node | |
296 texinfo-last-node-pos | |
297 texinfo-vindex | |
298 texinfo-findex | |
299 texinfo-cindex | |
300 texinfo-pindex | |
301 texinfo-tindex | |
302 texinfo-kindex | |
303 texinfo-stack | |
304 texinfo-node-names | |
305 (texinfo-footnote-number 0) | |
306 last-input-buffer | |
307 outfile | |
308 (fill-column-for-info fill-column) | |
309 (input-buffer (current-buffer)) | |
310 (input-directory default-directory)) | |
311 (setq texinfo-enclosure-list nil) | |
312 (setq texinfo-alias-list nil) | |
313 (save-excursion | |
314 (goto-char (point-min)) | |
315 (or (search-forward "@setfilename" nil t) | |
316 (error "Texinfo file needs an `@setfilename FILENAME' line.")) | |
317 (setq texinfo-command-end (point)) | |
318 (setq outfile (texinfo-parse-line-arg))) | |
319 (find-file outfile) | |
320 (texinfo-mode) | |
321 (setq fill-column fill-column-for-info) | |
322 (set-syntax-table texinfo-format-syntax-table) | |
323 (erase-buffer) | |
324 (insert-buffer-substring input-buffer) | |
325 (message "Converting %s to Info format..." (buffer-name input-buffer)) | |
326 | |
327 ;; Insert @include files so `texinfo-raise-lower-sections' can | |
328 ;; work on them without losing track of multiple | |
329 ;; @raise/@lowersections commands. | |
330 (goto-char (point-min)) | |
331 (while (re-search-forward "^@include" nil t) | |
332 (setq texinfo-command-end (point)) | |
333 (let ((filename (concat input-directory | |
334 (texinfo-parse-line-arg)))) | |
335 (re-search-backward "^@include") | |
336 (delete-region (point) (save-excursion (forward-line 1) (point))) | |
337 (message "Reading included file: %s" filename) | |
338 (save-excursion | |
339 (save-restriction | |
340 (narrow-to-region | |
341 (point) | |
342 (+ (point) (car (cdr (insert-file-contents filename))))) | |
343 (goto-char (point-min)) | |
344 ;; Remove `@setfilename' line from included file, if any, | |
345 ;; so @setfilename command not duplicated. | |
346 (if (re-search-forward | |
347 "^@setfilename" | |
348 (save-excursion (forward-line 100) (point)) t) | |
349 (progn | |
350 (beginning-of-line) | |
351 (delete-region | |
352 (point) (save-excursion (forward-line 1) (point))))))))) | |
353 ;; Raise or lower level of each section, if necessary. | |
354 (goto-char (point-min)) | |
355 (texinfo-raise-lower-sections) | |
356 ;; Append @refill to appropriate paragraphs | |
357 (goto-char (point-min)) | |
358 (texinfo-append-refill) | |
359 (goto-char (point-min)) | |
360 (search-forward "@setfilename") | |
361 (beginning-of-line) | |
362 (delete-region (point-min) (point)) | |
363 ;; Remove @bye at end of file, if it is there. | |
364 (goto-char (point-max)) | |
365 (if (search-backward "@bye" nil t) | |
366 (delete-region (point) (point-max))) | |
367 ;; Make sure buffer ends in a newline. | |
368 (or (= (preceding-char) ?\n) | |
369 (insert "\n")) | |
370 ;; Scan the whole buffer, converting to Info format. | |
371 (texinfo-format-scan) | |
372 ;; Return data for indices. | |
373 (goto-char (point-min)) | |
374 (list outfile | |
375 texinfo-vindex texinfo-findex texinfo-cindex | |
376 texinfo-pindex texinfo-tindex texinfo-kindex))) | |
377 | |
378 | |
379 ;;; Perform non-@-command file conversions: quotes and hyphens | |
380 | |
381 (defun texinfo-format-convert (min max) | |
382 ;; Convert left and right quotes to typewriter font quotes. | |
383 (goto-char min) | |
384 (while (search-forward "``" max t) | |
385 (replace-match "\"")) | |
386 (goto-char min) | |
387 (while (search-forward "''" max t) | |
388 (replace-match "\"")) | |
389 ;; Convert three hyphens in a row to two. | |
390 (goto-char min) | |
391 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t) | |
392 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning | |
393 2))))) | |
394 | |
395 | |
396 ;;; Handle paragraph filling | |
397 | |
398 (defvar texinfo-no-refill-regexp | |
399 "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|ifhtml\\|tex\\|html\\)" | |
400 "Regexp specifying environments in which paragraphs are not filled.") | |
401 | |
402 (defvar texinfo-part-of-para-regexp | |
403 "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)" | |
404 "Regexp specifying @-commands found within paragraphs.") | |
405 | |
406 (defun texinfo-append-refill () | |
407 "Append @refill at end of each paragraph that should be filled. | |
408 Do not append @refill to paragraphs within @example and similar environments. | |
409 Do not append @refill to paragraphs containing @w{TEXT} or @*." | |
410 | |
411 ;; It is necessary to append @refill before other processing because | |
412 ;; the other processing removes information that tells Texinfo | |
413 ;; whether the text should or should not be filled. | |
414 | |
415 (while (< (point) (point-max)) | |
416 (let ((refill-blank-lines "^[ \t\n]*$") | |
417 (case-fold-search nil)) ; Don't confuse @TeX and @tex.... | |
418 (beginning-of-line) | |
419 ;; 1. Skip over blank lines; | |
420 ;; skip over lines beginning with @-commands, | |
421 ;; but do not skip over lines | |
422 ;; that are no-refill environments such as @example or | |
423 ;; that begin with within-paragraph @-commands such as @code. | |
424 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines)) | |
425 (not (looking-at | |
426 (concat | |
427 "\\(" | |
428 texinfo-no-refill-regexp | |
429 "\\|" | |
430 texinfo-part-of-para-regexp | |
431 "\\)"))) | |
432 (< (point) (point-max))) | |
433 (forward-line 1)) | |
434 ;; 2. Skip over @example and similar no-refill environments. | |
435 (if (looking-at texinfo-no-refill-regexp) | |
436 (let ((environment | |
437 (buffer-substring (match-beginning 1) (match-end 1)))) | |
438 (progn (re-search-forward (concat "^@end " environment) nil t) | |
439 (forward-line 1))) | |
440 ;; 3. Do not refill a paragraph containing @w or @* | |
441 (if (or | |
442 (>= (point) (point-max)) | |
443 (re-search-forward | |
444 "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t)) | |
445 ;; Go to end of paragraph and do nothing. | |
446 (forward-paragraph) | |
447 ;; 4. Else go to end of paragraph and insert @refill | |
448 (forward-paragraph) | |
449 (forward-line -1) | |
450 (end-of-line) | |
451 (delete-region | |
452 (point) | |
453 (save-excursion (skip-chars-backward " \t") (point))) | |
454 ;; `looking-at-backward' not available in v. 18.57 | |
455 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;) | |
456 (if (not (re-search-backward | |
457 "@refill\\|@bye" | |
458 (save-excursion (beginning-of-line) (point)) | |
459 t)) | |
460 (insert "@refill")) | |
461 (forward-line 1)))))) | |
462 | |
463 | |
464 ;;; Handle `@raisesections' and `@lowersections' commands | |
465 | |
466 ;; These commands change the hierarchical level of chapter structuring | |
467 ;; commands. | |
468 ;; | |
469 ;; @raisesections changes @subsection to @section, | |
470 ;; @section to @chapter, | |
471 ;; etc. | |
472 ;; | |
473 ;; @lowersections changes @chapter to @section | |
474 ;; @subsection to @subsubsection, | |
475 ;; etc. | |
476 ;; | |
477 ;; An @raisesections/@lowersections command changes only those | |
478 ;; structuring commands that follow the @raisesections/@lowersections | |
479 ;; command. | |
480 ;; | |
481 ;; Repeated @raisesections/@lowersections continue to raise or lower | |
482 ;; the heading level. | |
483 ;; | |
484 ;; An @lowersections command cancels an @raisesections command, and | |
485 ;; vice versa. | |
486 ;; | |
487 ;; You cannot raise or lower "beyond" chapters or subsubsections, but | |
488 ;; trying to do so does not elicit an error---you just get more | |
489 ;; headings that mean the same thing as you keep raising or lowering | |
490 ;; (for example, after a single @raisesections, both @chapter and | |
491 ;; @section produce chapter headings). | |
492 | |
493 (defun texinfo-raise-lower-sections () | |
494 "Raise or lower the hierarchical level of chapters, sections, etc. | |
495 | |
496 This function acts according to `@raisesections' and `@lowersections' | |
497 commands in the Texinfo file. | |
498 | |
499 For example, an `@lowersections' command is useful if you wish to | |
500 include what is written as an outer or standalone Texinfo file in | |
501 another Texinfo file as an inner, included file. The `@lowersections' | |
502 command changes chapters to sections, sections to subsections and so | |
503 on. | |
504 | |
505 @raisesections changes @subsection to @section, | |
506 @section to @chapter, | |
507 @heading to @chapheading, | |
508 etc. | |
509 | |
510 @lowersections changes @chapter to @section, | |
511 @subsection to @subsubsection, | |
512 @heading to @subheading, | |
513 etc. | |
514 | |
515 An `@raisesections' or `@lowersections' command changes only those | |
516 structuring commands that follow the `@raisesections' or | |
517 `@lowersections' command. | |
518 | |
519 An `@lowersections' command cancels an `@raisesections' command, and | |
520 vice versa. | |
521 | |
522 Repeated use of the commands continue to raise or lower the hierarchical | |
523 level a step at a time. | |
524 | |
525 An attempt to raise above `chapters' reproduces chapter commands; an | |
526 attempt to lower below subsubsections reproduces subsubsection | |
527 commands." | |
528 | |
529 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el'; | |
530 ;; it is a regexp matching chapter, section, other headings | |
531 ;; (but not the top node). | |
532 | |
533 (let (type (level 0)) | |
534 (while | |
535 (re-search-forward | |
536 (concat | |
537 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\(" | |
538 texinfo-section-types-regexp | |
539 "\\)\\)") | |
540 nil t) | |
541 (beginning-of-line) | |
542 (save-excursion (setq type (read (current-buffer)))) | |
543 (cond | |
544 | |
545 ;; 1. Increment level | |
546 ((eq type '@raisesections) | |
547 (setq level (1+ level)) | |
548 (delete-region | |
549 (point) (save-excursion (forward-line 1) (point)))) | |
550 | |
551 ;; 2. Decrement level | |
552 ((eq type '@lowersections) | |
553 (setq level (1- level)) | |
554 (delete-region | |
555 (point) (save-excursion (forward-line 1) (point)))) | |
556 | |
557 ;; Now handle structuring commands | |
558 ((cond | |
559 | |
560 ;; 3. Raise level when positive | |
561 ((> level 0) | |
562 (let ((count level) | |
563 (new-level type)) | |
564 (while (> count 0) | |
565 (setq new-level | |
566 (cdr (assq new-level texinfo-raisesections-alist))) | |
567 (setq count (1- count))) | |
568 (kill-word 1) | |
569 (insert (symbol-name new-level)))) | |
570 | |
571 ;; 4. Do nothing except move point when level is zero | |
572 ((= level 0) (forward-line 1)) | |
573 | |
574 ;; 5. Lower level when positive | |
575 ((< level 0) | |
576 (let ((count level) | |
577 (new-level type)) | |
578 (while (< count 0) | |
579 (setq new-level | |
580 (cdr (assq new-level texinfo-lowersections-alist))) | |
581 (setq count (1+ count))) | |
582 (kill-word 1) | |
583 (insert (symbol-name new-level)))))))))) | |
584 | |
585 (defvar texinfo-raisesections-alist | |
586 '((@chapter . @chapter) ; Cannot go higher | |
587 (@unnumbered . @unnumbered) | |
588 | |
589 (@majorheading . @majorheading) | |
590 (@chapheading . @chapheading) | |
591 (@appendix . @appendix) | |
592 | |
593 (@section . @chapter) | |
594 (@unnumberedsec . @unnumbered) | |
595 (@heading . @chapheading) | |
596 (@appendixsec . @appendix) | |
597 | |
598 (@subsection . @section) | |
599 (@unnumberedsubsec . @unnumberedsec) | |
600 (@subheading . @heading) | |
601 (@appendixsubsec . @appendixsec) | |
602 | |
603 (@subsubsection . @subsection) | |
604 (@unnumberedsubsubsec . @unnumberedsubsec) | |
605 (@subsubheading . @subheading) | |
606 (@appendixsubsubsec . @appendixsubsec)) | |
607 "*An alist of next higher levels for chapters, sections. etc. | |
608 For example, section to chapter, subsection to section. | |
609 Used by `texinfo-raise-lower-sections'. | |
610 The keys specify types of section; the values correspond to the next | |
611 higher types.") | |
612 | |
613 (defvar texinfo-lowersections-alist | |
614 '((@chapter . @section) | |
615 (@unnumbered . @unnumberedsec) | |
616 (@majorheading . @heading) | |
617 (@chapheading . @heading) | |
618 (@appendix . @appendixsec) | |
619 | |
620 (@section . @subsection) | |
621 (@unnumberedsec . @unnumberedsubsec) | |
622 (@heading . @subheading) | |
623 (@appendixsec . @appendixsubsec) | |
624 | |
625 (@subsection . @subsubsection) | |
626 (@unnumberedsubsec . @unnumberedsubsubsec) | |
627 (@subheading . @subsubheading) | |
628 (@appendixsubsec . @appendixsubsubsec) | |
629 | |
630 (@subsubsection . @subsubsection) ; Cannot go lower. | |
631 (@unnumberedsubsubsec . @unnumberedsubsubsec) | |
632 (@subsubheading . @subsubheading) | |
633 (@appendixsubsubsec . @appendixsubsubsec)) | |
634 "*An alist of next lower levels for chapters, sections. etc. | |
635 For example, chapter to section, section to subsection. | |
636 Used by `texinfo-raise-lower-sections'. | |
637 The keys specify types of section; the values correspond to the next | |
638 lower types.") | |
639 | |
640 | |
641 ;;; Perform those texinfo-to-info conversions that apply to the whole input | |
642 ;;; uniformly. | |
643 | |
644 (defun texinfo-format-scan () | |
645 (texinfo-format-convert (point-min) (point-max)) | |
646 ;; Scan for @-commands. | |
647 (goto-char (point-min)) | |
648 (while (search-forward "@" nil t) | |
649 (if (looking-at "[@{}^'` *\"?!]") | |
650 ;; Handle a few special @-followed-by-one-char commands. | |
651 (if (= (following-char) ?*) | |
652 (progn | |
653 ;; remove command | |
654 (delete-region (1- (point)) (1+ (point))) | |
655 ;; insert return if not at end of line; | |
656 ;; else line is already broken. | |
657 (if (not (= (following-char) ?\n)) | |
658 (insert ?\n))) | |
659 ;; The other characters are simply quoted. Delete the @. | |
660 (delete-char -1) | |
661 (forward-char 1)) | |
662 ;; @ is followed by a command-word; find the end of the word. | |
663 (setq texinfo-command-start (1- (point))) | |
664 (if (= (char-syntax (following-char)) ?w) | |
665 (forward-word 1) | |
666 (forward-char 1)) | |
667 (setq texinfo-command-end (point)) | |
668 ;; Handle let aliasing | |
669 (setq texinfo-command-name | |
670 (let (trial | |
671 (cmdname | |
672 (buffer-substring | |
673 (1+ texinfo-command-start) texinfo-command-end))) | |
674 (while (setq trial (assoc cmdname texinfo-alias-list)) | |
675 (setq cmdname (cdr trial))) | |
676 (intern cmdname))) | |
677 ;; Call the handler for this command. | |
678 (let ((enclosure-type | |
679 (assoc | |
680 (symbol-name texinfo-command-name) | |
681 texinfo-enclosure-list))) | |
682 (if enclosure-type | |
683 (progn | |
684 (insert | |
685 (car (car (cdr enclosure-type))) | |
686 (texinfo-parse-arg-discard) | |
687 (car (cdr (car (cdr enclosure-type))))) | |
688 (goto-char texinfo-command-start)) | |
689 (let ((cmd (get texinfo-command-name 'texinfo-format))) | |
690 (if cmd (funcall cmd) (texinfo-unsupported))))))) | |
691 | |
692 (cond (texinfo-stack | |
693 (goto-char (nth 2 (car texinfo-stack))) | |
694 (error "Unterminated @%s" (car (car texinfo-stack)))))) | |
695 | |
696 (put 'begin 'texinfo-format 'texinfo-format-begin) | |
697 (defun texinfo-format-begin () | |
698 (texinfo-format-begin-end 'texinfo-format)) | |
699 | |
700 (put 'end 'texinfo-format 'texinfo-format-end) | |
701 (defun texinfo-format-end () | |
702 (texinfo-format-begin-end 'texinfo-end)) | |
703 | |
704 (defun texinfo-format-begin-end (prop) | |
705 (setq texinfo-command-name (intern (texinfo-parse-line-arg))) | |
706 (let ((cmd (get texinfo-command-name prop))) | |
707 (if cmd (funcall cmd) | |
708 (texinfo-unsupported)))) | |
709 | |
710 ;;; Parsing functions | |
711 | |
712 (defun texinfo-parse-line-arg () | |
713 (goto-char texinfo-command-end) | |
714 (let ((start (point))) | |
715 (cond ((looking-at " ") | |
716 (skip-chars-forward " ") | |
717 (setq start (point)) | |
718 (end-of-line) | |
719 (skip-chars-backward " ") | |
720 (delete-region (point) (progn (end-of-line) (point))) | |
721 (setq texinfo-command-end (1+ (point)))) | |
722 ((looking-at "{") | |
723 (setq start (1+ (point))) | |
724 (forward-list 1) | |
725 (setq texinfo-command-end (point)) | |
726 (forward-char -1)) | |
727 (t | |
728 (error "Invalid texinfo command arg format"))) | |
729 (prog1 (buffer-substring start (point)) | |
730 (if (eolp) (forward-char 1))))) | |
731 | |
732 (defun texinfo-parse-expanded-arg () | |
733 (goto-char texinfo-command-end) | |
734 (let ((start (point)) | |
735 marker) | |
736 (cond ((looking-at " ") | |
737 (skip-chars-forward " ") | |
738 (setq start (point)) | |
739 (end-of-line) | |
740 (setq texinfo-command-end (1+ (point)))) | |
741 ((looking-at "{") | |
742 (setq start (1+ (point))) | |
743 (forward-list 1) | |
744 (setq texinfo-command-end (point)) | |
745 (forward-char -1)) | |
746 (t | |
747 (error "Invalid texinfo command arg format"))) | |
748 (setq marker (move-marker (make-marker) texinfo-command-end)) | |
749 (texinfo-format-expand-region start (point)) | |
750 (setq texinfo-command-end (marker-position marker)) | |
751 (move-marker marker nil) | |
752 (prog1 (buffer-substring start (point)) | |
753 (if (eolp) (forward-char 1))))) | |
754 | |
755 (defun texinfo-format-expand-region (start end) | |
756 (save-restriction | |
757 (narrow-to-region start end) | |
758 (let (texinfo-command-start | |
759 texinfo-command-end | |
760 texinfo-command-name | |
761 texinfo-stack) | |
762 (texinfo-format-scan)) | |
763 (goto-char (point-max)))) | |
764 | |
765 (defun texinfo-parse-arg-discard () | |
766 (prog1 (texinfo-parse-line-arg) | |
767 (texinfo-discard-command))) | |
768 | |
769 (defun texinfo-discard-command () | |
770 (delete-region texinfo-command-start texinfo-command-end)) | |
771 | |
772 (defun texinfo-optional-braces-discard () | |
773 "Discard braces following command, if any." | |
774 (goto-char texinfo-command-end) | |
775 (let ((start (point))) | |
776 (cond ((looking-at "[ \t]*\n")) ; do nothing | |
777 ((looking-at "{") ; remove braces, if any | |
778 (forward-list 1) | |
779 (setq texinfo-command-end (point))) | |
780 (t | |
781 (error | |
782 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)"))) | |
783 (delete-region texinfo-command-start texinfo-command-end))) | |
784 | |
785 (defun texinfo-format-parse-line-args () | |
786 (let ((start (1- (point))) | |
787 next beg end | |
788 args) | |
789 (skip-chars-forward " ") | |
790 (while (not (eolp)) | |
791 (setq beg (point)) | |
792 (re-search-forward "[\n,]") | |
793 (setq next (point)) | |
794 (if (bolp) (setq next (1- next))) | |
795 (forward-char -1) | |
796 (skip-chars-backward " ") | |
797 (setq end (point)) | |
798 (setq args (cons (if (> end beg) (buffer-substring beg end)) | |
799 args)) | |
800 (goto-char next) | |
801 (skip-chars-forward " ")) | |
802 (if (eolp) (forward-char 1)) | |
803 (setq texinfo-command-end (point)) | |
804 (nreverse args))) | |
805 | |
806 (defun texinfo-format-parse-args () | |
807 (let ((start (1- (point))) | |
808 next beg end | |
809 args) | |
810 (search-forward "{") | |
811 (save-excursion | |
812 (texinfo-format-expand-region | |
813 (point) | |
814 (save-excursion (up-list 1) (1- (point))))) | |
815 ;; The following does not handle cross references of the form: | |
816 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the | |
817 ;; re-search-forward finds the first right brace after the second | |
818 ;; comma. | |
819 (while (/= (preceding-char) ?\}) | |
820 (skip-chars-forward " \t\n") | |
821 (setq beg (point)) | |
822 (re-search-forward "[},]") | |
823 (setq next (point)) | |
824 (forward-char -1) | |
825 (skip-chars-backward " \t\n") | |
826 (setq end (point)) | |
827 (cond ((< beg end) | |
828 (goto-char beg) | |
829 (while (search-forward "\n" end t) | |
830 (replace-match " ")))) | |
831 (setq args (cons (if (> end beg) (buffer-substring beg end)) | |
832 args)) | |
833 (goto-char next)) | |
834 (if (eolp) (forward-char 1)) | |
835 (setq texinfo-command-end (point)) | |
836 (nreverse args))) | |
837 | |
838 (defun texinfo-format-parse-defun-args () | |
839 (goto-char texinfo-command-end) | |
840 (let ((start (point))) | |
841 (end-of-line) | |
842 (setq texinfo-command-end (1+ (point))) | |
843 (let ((marker (move-marker (make-marker) texinfo-command-end))) | |
844 (texinfo-format-expand-region start (point)) | |
845 (setq texinfo-command-end (marker-position marker)) | |
846 (move-marker marker nil)) | |
847 (goto-char start) | |
848 (let ((args '()) | |
849 beg end) | |
850 (skip-chars-forward " ") | |
851 (while (not (eolp)) | |
852 (cond ((looking-at "{") | |
853 (setq beg (1+ (point))) | |
854 (forward-list 1) | |
855 (setq end (1- (point)))) | |
856 (t | |
857 (setq beg (point)) | |
858 (re-search-forward "[\n ]") | |
859 (forward-char -1) | |
860 (setq end (point)))) | |
861 (setq args (cons (buffer-substring beg end) args)) | |
862 (skip-chars-forward " ")) | |
863 (forward-char 1) | |
864 (nreverse args)))) | |
865 | |
866 (defun texinfo-discard-line () | |
867 (goto-char texinfo-command-end) | |
868 (skip-chars-forward " \t") | |
869 (or (eolp) | |
870 (error "Extraneous text at end of command line.")) | |
871 (goto-char texinfo-command-start) | |
872 (or (bolp) | |
873 (error "Extraneous text at beginning of command line.")) | |
874 (delete-region (point) (progn (forward-line 1) (point)))) | |
875 | |
876 (defun texinfo-discard-line-with-args () | |
877 (goto-char texinfo-command-start) | |
878 (delete-region (point) (progn (forward-line 1) (point)))) | |
879 | |
880 | |
881 ;;; @setfilename | |
882 | |
883 ;; Only `texinfo-format-buffer' handles @setfilename with this | |
884 ;; definition; `texinfo-format-region' handles @setfilename, if any, | |
885 ;; specially. | |
886 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename) | |
887 (defun texinfo-format-setfilename () | |
888 (let ((arg (texinfo-parse-arg-discard))) | |
889 (message "Formatting Info file: %s" arg) | |
890 (setq texinfo-format-filename | |
891 (file-name-nondirectory (expand-file-name arg))) | |
892 (insert "Info file: " | |
893 texinfo-format-filename ", -*-Text-*-\n" | |
894 ;; Date string removed so that regression testing is easier. | |
895 ;; "produced on " | |
896 ;; (substring (current-time-string) 8 10) " " | |
897 ;; (substring (current-time-string) 4 7) " " | |
898 ;; (substring (current-time-string) -4) " " | |
899 "produced by `texinfo-format-buffer'\n" | |
900 "from file" | |
901 (if (buffer-file-name input-buffer) | |
902 (concat " `" | |
903 (file-name-sans-versions | |
904 (file-name-nondirectory | |
905 (buffer-file-name input-buffer))) | |
906 "'") | |
907 (concat "buffer `" (buffer-name input-buffer) "'")) | |
908 "\nusing `texinfmt.el' version " | |
909 texinfmt-version | |
910 ".\n\n"))) | |
911 | |
912 ;;; @node, @menu | |
913 | |
914 (put 'node 'texinfo-format 'texinfo-format-node) | |
915 (put 'nwnode 'texinfo-format 'texinfo-format-node) | |
916 (defun texinfo-format-node () | |
917 (let* ((args (texinfo-format-parse-line-args)) | |
918 (name (nth 0 args)) | |
919 (next (nth 1 args)) | |
920 (prev (nth 2 args)) | |
921 (up (nth 3 args))) | |
922 (texinfo-discard-command) | |
923 (setq texinfo-last-node name) | |
924 (let ((tem (downcase name))) | |
925 (if (assoc tem texinfo-node-names) | |
926 (error "Duplicate node name: %s" name) | |
927 (setq texinfo-node-names (cons (list tem) texinfo-node-names)))) | |
928 (setq texinfo-footnote-number 0) | |
929 ;; insert "\n\^_" unconditionally since this is what info is looking for | |
930 (insert "\n\^_\nFile: " texinfo-format-filename | |
931 ", Node: " name) | |
932 (if next | |
933 (insert ", Next: " next)) | |
934 (if prev | |
935 (insert ", Prev: " prev)) | |
936 (if up | |
937 (insert ", Up: " up)) | |
938 (insert ?\n) | |
939 (setq texinfo-last-node-pos (point)))) | |
940 | |
941 (put 'menu 'texinfo-format 'texinfo-format-menu) | |
942 (defun texinfo-format-menu () | |
943 (texinfo-discard-line) | |
944 (insert "* Menu:\n\n")) | |
945 | |
946 (put 'menu 'texinfo-end 'texinfo-discard-command) | |
947 | |
948 | |
949 ;;; Cross references | |
950 | |
951 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT} | |
952 ; -> *Note FNAME: (FILE)NODE | |
953 ; If FILE is missing, | |
954 ; *Note FNAME: NODE | |
955 ; If FNAME is empty and NAME is present | |
956 ; *Note NAME: Node | |
957 ; If both NAME and FNAME are missing | |
958 ; *Note NODE:: | |
959 ; texinfo ignores the DOCUMENT argument. | |
960 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE> | |
961 ; If FILE is specified, (FILE)NODE is used for xrefs. | |
962 ; If fifth argument DOCUMENT is specified, produces | |
963 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE> | |
964 ; of DOCUMENT | |
965 | |
966 ; @ref a reference that does not put `See' or `see' in | |
967 ; the hardcopy and is the same as @xref in Info | |
968 (put 'ref 'texinfo-format 'texinfo-format-xref) | |
969 | |
970 (put 'xref 'texinfo-format 'texinfo-format-xref) | |
971 (defun texinfo-format-xref () | |
972 (let ((args (texinfo-format-parse-args))) | |
973 (texinfo-discard-command) | |
974 (insert "*Note ") | |
975 (let ((fname (or (nth 1 args) (nth 2 args)))) | |
976 (if (null (or fname (nth 3 args))) | |
977 (insert (car args) "::") | |
978 (insert (or fname (car args)) ": ") | |
979 (if (nth 3 args) | |
980 (insert "(" (nth 3 args) ")")) | |
981 (insert (car args)))))) | |
982 | |
983 (put 'pxref 'texinfo-format 'texinfo-format-pxref) | |
984 (defun texinfo-format-pxref () | |
985 (texinfo-format-xref) | |
986 (or (save-excursion | |
987 (forward-char -2) | |
988 (looking-at "::")) | |
989 (insert "."))) | |
990 | |
991 ;@inforef{NODE, FNAME, FILE} | |
992 ;Like @xref{NODE, FNAME,,FILE} in texinfo. | |
993 ;In Tex, generates "See Info file FILE, node NODE" | |
994 (put 'inforef 'texinfo-format 'texinfo-format-inforef) | |
995 (defun texinfo-format-inforef () | |
996 (let ((args (texinfo-format-parse-args))) | |
997 (texinfo-discard-command) | |
998 (if (nth 1 args) | |
999 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args)) | |
1000 (insert "*Note " "(" (nth 2 args) ")" (car args) "::")))) | |
1001 | |
1002 | |
1003 ;;; Section headings | |
1004 | |
1005 (put 'majorheading 'texinfo-format 'texinfo-format-chapter) | |
1006 (put 'chapheading 'texinfo-format 'texinfo-format-chapter) | |
1007 (put 'ichapter 'texinfo-format 'texinfo-format-chapter) | |
1008 (put 'chapter 'texinfo-format 'texinfo-format-chapter) | |
1009 (put 'iappendix 'texinfo-format 'texinfo-format-chapter) | |
1010 (put 'appendix 'texinfo-format 'texinfo-format-chapter) | |
1011 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter) | |
1012 (put 'top 'texinfo-format 'texinfo-format-chapter) | |
1013 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter) | |
1014 (defun texinfo-format-chapter () | |
1015 (texinfo-format-chapter-1 ?*)) | |
1016 | |
1017 (put 'heading 'texinfo-format 'texinfo-format-section) | |
1018 (put 'isection 'texinfo-format 'texinfo-format-section) | |
1019 (put 'section 'texinfo-format 'texinfo-format-section) | |
1020 (put 'iappendixsection 'texinfo-format 'texinfo-format-section) | |
1021 (put 'appendixsection 'texinfo-format 'texinfo-format-section) | |
1022 (put 'iappendixsec 'texinfo-format 'texinfo-format-section) | |
1023 (put 'appendixsec 'texinfo-format 'texinfo-format-section) | |
1024 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section) | |
1025 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section) | |
1026 (defun texinfo-format-section () | |
1027 (texinfo-format-chapter-1 ?=)) | |
1028 | |
1029 (put 'subheading 'texinfo-format 'texinfo-format-subsection) | |
1030 (put 'isubsection 'texinfo-format 'texinfo-format-subsection) | |
1031 (put 'subsection 'texinfo-format 'texinfo-format-subsection) | |
1032 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection) | |
1033 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection) | |
1034 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection) | |
1035 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection) | |
1036 (defun texinfo-format-subsection () | |
1037 (texinfo-format-chapter-1 ?-)) | |
1038 | |
1039 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection) | |
1040 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection) | |
1041 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection) | |
1042 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
1043 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
1044 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
1045 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) | |
1046 (defun texinfo-format-subsubsection () | |
1047 (texinfo-format-chapter-1 ?.)) | |
1048 | |
1049 (defun texinfo-format-chapter-1 (belowchar) | |
1050 (let ((arg (texinfo-parse-arg-discard))) | |
1051 (message "Formatting: %s ... " arg) ; So we can see where we are. | |
1052 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n) | |
1053 (forward-line -2))) | |
1054 | |
1055 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad) | |
1056 (defun texinfo-format-sectionpad () | |
1057 (let ((str (texinfo-parse-arg-discard))) | |
1058 (forward-char -1) | |
1059 (let ((column (current-column))) | |
1060 (forward-char 1) | |
1061 (while (> column 0) | |
1062 (insert str) | |
1063 (setq column (1- column)))) | |
1064 (insert ?\n))) | |
1065 | |
1066 | |
1067 ;;; Space controlling commands: @. and @:, and the soft hyphen. | |
1068 | |
1069 (put '\. 'texinfo-format 'texinfo-format-\.) | |
1070 (defun texinfo-format-\. () | |
1071 (texinfo-discard-command) | |
1072 (insert ".")) | |
1073 | |
1074 (put '\: 'texinfo-format 'texinfo-format-\:) | |
1075 (defun texinfo-format-\: () | |
1076 (texinfo-discard-command)) | |
1077 | |
1078 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen) | |
1079 (defun texinfo-format-soft-hyphen () | |
1080 (texinfo-discard-command)) | |
1081 | |
1082 | |
1083 ;;; @center, @sp, and @br | |
1084 | |
1085 (put 'center 'texinfo-format 'texinfo-format-center) | |
1086 (defun texinfo-format-center () | |
1087 (let ((arg (texinfo-parse-expanded-arg))) | |
1088 (texinfo-discard-command) | |
1089 (insert arg) | |
1090 (insert ?\n) | |
1091 (save-restriction | |
1092 (goto-char (1- (point))) | |
1093 (let ((indent-tabs-mode nil)) | |
1094 (center-line))))) | |
1095 | |
1096 (put 'sp 'texinfo-format 'texinfo-format-sp) | |
1097 (defun texinfo-format-sp () | |
1098 (let* ((arg (texinfo-parse-arg-discard)) | |
1099 (num (read arg))) | |
1100 (insert-char ?\n num))) | |
1101 | |
1102 (put 'br 'texinfo-format 'texinfo-format-paragraph-break) | |
1103 (defun texinfo-format-paragraph-break () | |
1104 "Force a paragraph break. | |
1105 If used within a line, follow `@br' with braces." | |
1106 (texinfo-optional-braces-discard) | |
1107 ;; insert one return if at end of line; | |
1108 ;; else insert two returns, to generate a blank line. | |
1109 (if (= (following-char) ?\n) | |
1110 (insert ?\n) | |
1111 (insert-char ?\n 2))) | |
1112 | |
1113 | |
1114 ;;; @footnote and @footnotestyle | |
1115 | |
1116 ; In Texinfo, footnotes are created with the `@footnote' command. | |
1117 ; This command is followed immediately by a left brace, then by the text of | |
1118 ; the footnote, and then by a terminating right brace. The | |
1119 ; template for a footnote is: | |
1120 ; | |
1121 ; @footnote{TEXT} | |
1122 ; | |
1123 ; Info has two footnote styles: | |
1124 ; | |
1125 ; * In the End of node style, all the footnotes for a single node | |
1126 ; are placed at the end of that node. The footnotes are | |
1127 ; separated from the rest of the node by a line of dashes with | |
1128 ; the word `Footnotes' within it. | |
1129 ; | |
1130 ; * In the Separate node style, all the footnotes for a single node | |
1131 ; are placed in an automatically constructed node of their own. | |
1132 | |
1133 ; Footnote style is specified by the @footnotestyle command, either | |
1134 ; @footnotestyle separate | |
1135 ; or | |
1136 ; @footnotestyle end | |
1137 ; | |
1138 ; The default is separate | |
1139 | |
1140 (defvar texinfo-footnote-style "separate" | |
1141 "Footnote style, either separate or end.") | |
1142 | |
1143 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle) | |
1144 (defun texinfo-footnotestyle () | |
1145 "Specify whether footnotes are at end of node or in separate nodes. | |
1146 Argument is either end or separate." | |
1147 (setq texinfo-footnote-style (texinfo-parse-arg-discard))) | |
1148 | |
1149 (defvar texinfo-footnote-number) | |
1150 | |
1151 (put 'footnote 'texinfo-format 'texinfo-format-footnote) | |
1152 (defun texinfo-format-footnote () | |
1153 "Format a footnote in either end of node or separate node style. | |
1154 The texinfo-footnote-style variable controls which style is used." | |
1155 (setq texinfo-footnote-number (1+ texinfo-footnote-number)) | |
1156 (cond ((string= texinfo-footnote-style "end") | |
1157 (texinfo-format-end-node)) | |
1158 ((string= texinfo-footnote-style "separate") | |
1159 (texinfo-format-separate-node)))) | |
1160 | |
1161 (defun texinfo-format-separate-node () | |
1162 "Format footnote in Separate node style, with notes in own node. | |
1163 The node is constructed automatically." | |
1164 (let* (start | |
1165 (arg (texinfo-parse-line-arg)) | |
1166 (node-name-beginning | |
1167 (save-excursion | |
1168 (re-search-backward | |
1169 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:") | |
1170 (match-end 0))) | |
1171 (node-name | |
1172 (save-excursion | |
1173 (buffer-substring | |
1174 (progn (goto-char node-name-beginning) ; skip over node command | |
1175 (skip-chars-forward " \t") ; and over spaces | |
1176 (point)) | |
1177 (if (search-forward | |
1178 "," | |
1179 (save-excursion (end-of-line) (point)) t) ; bound search | |
1180 (1- (point)) | |
1181 (end-of-line) (point)))))) | |
1182 (texinfo-discard-command) ; remove or insert whitespace, as needed | |
1183 (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) | |
1184 (point)) | |
1185 (insert (format " (%d) (*Note %s-Footnotes::)" | |
1186 texinfo-footnote-number node-name)) | |
1187 (fill-paragraph nil) | |
1188 (save-excursion | |
1189 (if (re-search-forward "^@node" nil 'move) | |
1190 (forward-line -1)) | |
1191 | |
1192 ;; two cases: for the first footnote, we must insert a node header; | |
1193 ;; for the second and subsequent footnotes, we need only insert | |
1194 ;; the text of the footnote. | |
1195 | |
1196 (if (save-excursion | |
1197 (re-search-backward | |
1198 (concat node-name "-Footnotes, Up: ") | |
1199 node-name-beginning | |
1200 t)) | |
1201 (progn ; already at least one footnote | |
1202 (setq start (point)) | |
1203 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
1204 (fill-region start (point))) | |
1205 ;; else not yet a footnote | |
1206 (insert "\n\^_\nFile: " texinfo-format-filename | |
1207 " Node: " node-name "-Footnotes, Up: " node-name "\n") | |
1208 (setq start (point)) | |
1209 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
1210 (fill-region start (point)))))) | |
1211 | |
1212 (defun texinfo-format-end-node () | |
1213 "Format footnote in the End of node style, with notes at end of node." | |
1214 (let (start | |
1215 (arg (texinfo-parse-line-arg))) | |
1216 (texinfo-discard-command) ; remove or insert whitespace, as needed | |
1217 (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) | |
1218 (point)) | |
1219 (insert (format " (%d) " texinfo-footnote-number)) | |
1220 (fill-paragraph nil) | |
1221 (save-excursion | |
1222 (if (search-forward "\n--------- Footnotes ---------\n" nil t) | |
1223 (progn ; already have footnote, put new one before end of node | |
1224 (if (re-search-forward "^@node" nil 'move) | |
1225 (forward-line -1)) | |
1226 (setq start (point)) | |
1227 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) | |
1228 (fill-region start (point))) | |
1229 ;; else no prior footnote | |
1230 (if (re-search-forward "^@node" nil 'move) | |
1231 (forward-line -1)) | |
1232 (insert "\n--------- Footnotes ---------\n") | |
1233 (setq start (point)) | |
1234 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)))))) | |
1235 | |
1236 | |
1237 ;;; @itemize, @enumerate, and similar commands | |
1238 | |
1239 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack. | |
1240 ;; @enumerate pushes (enumerate 0 STARTPOS). | |
1241 ;; @item dispatches to the texinfo-item prop of the first elt of the list. | |
1242 ;; For itemize, this puts in and rescans the COMMANDS. | |
1243 ;; For enumerate, this increments the number and puts it in. | |
1244 ;; In either case, it puts a Backspace at the front of the line | |
1245 ;; which marks it not to be indented later. | |
1246 ;; All other lines get indented by 5 when the @end is reached. | |
1247 | |
1248 (defvar texinfo-stack-depth 0 | |
1249 "Count of number of unpopped texinfo-push-stack calls. | |
1250 Used by @refill indenting command to avoid indenting within lists, etc.") | |
1251 | |
1252 (defun texinfo-push-stack (check arg) | |
1253 (setq texinfo-stack-depth (1+ texinfo-stack-depth)) | |
1254 (setq texinfo-stack | |
1255 (cons (list check arg texinfo-command-start) | |
1256 texinfo-stack))) | |
1257 | |
1258 (defun texinfo-pop-stack (check) | |
1259 (setq texinfo-stack-depth (1- texinfo-stack-depth)) | |
1260 (if (null texinfo-stack) | |
1261 (error "Unmatched @end %s" check)) | |
1262 (if (not (eq (car (car texinfo-stack)) check)) | |
1263 (error "@end %s matches @%s" | |
1264 check (car (car texinfo-stack)))) | |
1265 (prog1 (cdr (car texinfo-stack)) | |
1266 (setq texinfo-stack (cdr texinfo-stack)))) | |
1267 | |
1268 (put 'itemize 'texinfo-format 'texinfo-itemize) | |
1269 (defun texinfo-itemize () | |
1270 (texinfo-push-stack | |
1271 'itemize | |
1272 (progn (skip-chars-forward " \t") | |
1273 (if (eolp) | |
1274 "@bullet" | |
1275 (texinfo-parse-line-arg)))) | |
1276 (texinfo-discard-line-with-args) | |
1277 (setq fill-column (- fill-column 5))) | |
1278 | |
1279 (put 'itemize 'texinfo-end 'texinfo-end-itemize) | |
1280 (defun texinfo-end-itemize () | |
1281 (setq fill-column (+ fill-column 5)) | |
1282 (texinfo-discard-command) | |
1283 (let ((stacktop | |
1284 (texinfo-pop-stack 'itemize))) | |
1285 (texinfo-do-itemize (nth 1 stacktop)))) | |
1286 | |
1287 (put 'enumerate 'texinfo-format 'texinfo-enumerate) | |
1288 (defun texinfo-enumerate () | |
1289 (texinfo-push-stack | |
1290 'enumerate | |
1291 (progn (skip-chars-forward " \t") | |
1292 (if (eolp) | |
1293 1 | |
1294 (read (current-buffer))))) | |
1295 (if (and (symbolp (car (cdr (car texinfo-stack)))) | |
1296 (> 1 (length (symbol-name (car (cdr (car texinfo-stack))))))) | |
1297 (error | |
1298 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." )) | |
1299 (texinfo-discard-line-with-args) | |
1300 (setq fill-column (- fill-column 5))) | |
1301 | |
1302 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate) | |
1303 (defun texinfo-end-enumerate () | |
1304 (setq fill-column (+ fill-column 5)) | |
1305 (texinfo-discard-command) | |
1306 (let ((stacktop | |
1307 (texinfo-pop-stack 'enumerate))) | |
1308 (texinfo-do-itemize (nth 1 stacktop)))) | |
1309 | |
1310 ;; @alphaenumerate never became a standard part of Texinfo | |
1311 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate) | |
1312 (defun texinfo-alphaenumerate () | |
1313 (texinfo-push-stack 'alphaenumerate (1- ?a)) | |
1314 (setq fill-column (- fill-column 5)) | |
1315 (texinfo-discard-line)) | |
1316 | |
1317 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate) | |
1318 (defun texinfo-end-alphaenumerate () | |
1319 (setq fill-column (+ fill-column 5)) | |
1320 (texinfo-discard-command) | |
1321 (let ((stacktop | |
1322 (texinfo-pop-stack 'alphaenumerate))) | |
1323 (texinfo-do-itemize (nth 1 stacktop)))) | |
1324 | |
1325 ;; @capsenumerate never became a standard part of Texinfo | |
1326 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate) | |
1327 (defun texinfo-capsenumerate () | |
1328 (texinfo-push-stack 'capsenumerate (1- ?A)) | |
1329 (setq fill-column (- fill-column 5)) | |
1330 (texinfo-discard-line)) | |
1331 | |
1332 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate) | |
1333 (defun texinfo-end-capsenumerate () | |
1334 (setq fill-column (+ fill-column 5)) | |
1335 (texinfo-discard-command) | |
1336 (let ((stacktop | |
1337 (texinfo-pop-stack 'capsenumerate))) | |
1338 (texinfo-do-itemize (nth 1 stacktop)))) | |
1339 | |
1340 ;; At the @end, indent all the lines within the construct | |
1341 ;; except those marked with backspace. FROM says where | |
1342 ;; construct started. | |
1343 (defun texinfo-do-itemize (from) | |
1344 (save-excursion | |
1345 (while (progn (forward-line -1) | |
1346 (>= (point) from)) | |
1347 (if (= (following-char) ?\b) | |
1348 (save-excursion | |
1349 (delete-char 1) | |
1350 (end-of-line) | |
1351 (delete-char 6)) | |
1352 (if (not (looking-at "[ \t]*$")) | |
1353 (save-excursion (insert " "))))))) | |
1354 | |
1355 (put 'item 'texinfo-format 'texinfo-item) | |
1356 (put 'itemx 'texinfo-format 'texinfo-item) | |
1357 (defun texinfo-item () | |
1358 (funcall (get (car (car texinfo-stack)) 'texinfo-item))) | |
1359 | |
1360 (put 'itemize 'texinfo-item 'texinfo-itemize-item) | |
1361 (defun texinfo-itemize-item () | |
1362 ;; (texinfo-discard-line) ; Did not handle text on same line as @item. | |
1363 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point))) | |
1364 (if (looking-at "[ \t]*[^ \t\n]+") | |
1365 ;; Text on same line as @item command. | |
1366 (insert "\b " (nth 1 (car texinfo-stack)) " \n") | |
1367 ;; Else text on next line. | |
1368 (insert "\b " (nth 1 (car texinfo-stack)) " ")) | |
1369 (forward-line -1)) | |
1370 | |
1371 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item) | |
1372 (defun texinfo-enumerate-item () | |
1373 (texinfo-discard-line) | |
1374 (let (enumerating-symbol) | |
1375 (cond ((integerp (car (cdr (car texinfo-stack)))) | |
1376 (setq enumerating-symbol (car (cdr (car texinfo-stack)))) | |
1377 (insert ?\b (format "%3d. " enumerating-symbol) ?\n) | |
1378 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol))) | |
1379 ((symbolp (car (cdr (car texinfo-stack)))) | |
1380 (setq enumerating-symbol | |
1381 (symbol-name (car (cdr (car texinfo-stack))))) | |
1382 (if (or (equal ?\[ (string-to-char enumerating-symbol)) | |
1383 (equal ?\{ (string-to-char enumerating-symbol))) | |
1384 (error | |
1385 "Too many items in enumerated list; alphabet ends at Z.")) | |
1386 (insert ?\b (format "%3s. " enumerating-symbol) ?\n) | |
1387 (setcar (cdr (car texinfo-stack)) | |
1388 (make-symbol | |
1389 (char-to-string | |
1390 (1+ | |
1391 (string-to-char enumerating-symbol)))))) | |
1392 (t | |
1393 (error | |
1394 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." ))) | |
1395 (forward-line -1))) | |
1396 | |
1397 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item) | |
1398 (defun texinfo-alphaenumerate-item () | |
1399 (texinfo-discard-line) | |
1400 (let ((next (1+ (car (cdr (car texinfo-stack)))))) | |
1401 (if (> next ?z) | |
1402 (error "More than 26 items in @alphaenumerate; get a bigger alphabet.")) | |
1403 (setcar (cdr (car texinfo-stack)) next) | |
1404 (insert "\b " next ". \n")) | |
1405 (forward-line -1)) | |
1406 | |
1407 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item) | |
1408 (defun texinfo-capsenumerate-item () | |
1409 (texinfo-discard-line) | |
1410 (let ((next (1+ (car (cdr (car texinfo-stack)))))) | |
1411 (if (> next ?Z) | |
1412 (error "More than 26 items in @capsenumerate; get a bigger alphabet.")) | |
1413 (setcar (cdr (car texinfo-stack)) next) | |
1414 (insert "\b " next ". \n")) | |
1415 (forward-line -1)) | |
1416 | |
1417 | |
1418 ;;; @table | |
1419 | |
1420 ; The `@table' command produces two-column tables. | |
1421 | |
1422 (put 'table 'texinfo-format 'texinfo-table) | |
1423 (defun texinfo-table () | |
1424 (texinfo-push-stack | |
1425 'table | |
1426 (progn (skip-chars-forward " \t") | |
1427 (if (eolp) | |
1428 "@asis" | |
1429 (texinfo-parse-line-arg)))) | |
1430 (texinfo-discard-line-with-args) | |
1431 (setq fill-column (- fill-column 5))) | |
1432 | |
1433 (put 'table 'texinfo-item 'texinfo-table-item) | |
1434 (defun texinfo-table-item () | |
1435 (let ((arg (texinfo-parse-arg-discard)) | |
1436 (itemfont (car (cdr (car texinfo-stack))))) | |
1437 (insert ?\b itemfont ?\{ arg "}\n \n")) | |
1438 (forward-line -2)) | |
1439 | |
1440 (put 'table 'texinfo-end 'texinfo-end-table) | |
1441 (defun texinfo-end-table () | |
1442 (setq fill-column (+ fill-column 5)) | |
1443 (texinfo-discard-command) | |
1444 (let ((stacktop | |
1445 (texinfo-pop-stack 'table))) | |
1446 (texinfo-do-itemize (nth 1 stacktop)))) | |
1447 | |
1448 ;; @description appears to be an undocumented variant on @table that | |
1449 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not | |
1450 ;; part of makeinfo.c The command appears to be a relic of the past. | |
1451 (put 'description 'texinfo-end 'texinfo-end-table) | |
1452 (put 'description 'texinfo-format 'texinfo-description) | |
1453 (defun texinfo-description () | |
1454 (texinfo-push-stack 'table "@asis") | |
1455 (setq fill-column (- fill-column 5)) | |
1456 (texinfo-discard-line)) | |
1457 | |
1458 | |
1459 ;;; @ftable, @vtable | |
1460 | |
1461 ; The `@ftable' and `@vtable' commands are like the `@table' command | |
1462 ; but they also insert each entry in the first column of the table | |
1463 ; into the function or variable index. | |
1464 | |
1465 ;; Handle the @ftable and @vtable commands: | |
1466 | |
1467 (put 'ftable 'texinfo-format 'texinfo-ftable) | |
1468 (put 'vtable 'texinfo-format 'texinfo-vtable) | |
1469 | |
1470 (defun texinfo-ftable () (texinfo-indextable 'ftable)) | |
1471 (defun texinfo-vtable () (texinfo-indextable 'vtable)) | |
1472 | |
1473 (defun texinfo-indextable (table-type) | |
1474 (texinfo-push-stack table-type (texinfo-parse-arg-discard)) | |
1475 (setq fill-column (- fill-column 5))) | |
1476 | |
1477 ;; Handle the @item commands within ftable and vtable: | |
1478 | |
1479 (put 'ftable 'texinfo-item 'texinfo-ftable-item) | |
1480 (put 'vtable 'texinfo-item 'texinfo-vtable-item) | |
1481 | |
1482 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex)) | |
1483 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex)) | |
1484 | |
1485 (defun texinfo-indextable-item (index-type) | |
1486 (let ((item (texinfo-parse-arg-discard)) | |
1487 (itemfont (car (cdr (car texinfo-stack)))) | |
1488 (indexvar index-type)) | |
1489 (insert ?\b itemfont ?\{ item "}\n \n") | |
1490 (set indexvar | |
1491 (cons | |
1492 (list item texinfo-last-node) | |
1493 (symbol-value indexvar))) | |
1494 (forward-line -2))) | |
1495 | |
1496 ;; Handle @end ftable, @end vtable | |
1497 | |
1498 (put 'ftable 'texinfo-end 'texinfo-end-ftable) | |
1499 (put 'vtable 'texinfo-end 'texinfo-end-vtable) | |
1500 | |
1501 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable)) | |
1502 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable)) | |
1503 | |
1504 (defun texinfo-end-indextable (table-type) | |
1505 (setq fill-column (+ fill-column 5)) | |
1506 (texinfo-discard-command) | |
1507 (let ((stacktop | |
1508 (texinfo-pop-stack table-type))) | |
1509 (texinfo-do-itemize (nth 1 stacktop)))) | |
1510 | |
1511 | |
1512 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html | |
1513 | |
1514 (put 'ifinfo 'texinfo-format 'texinfo-discard-line) | |
1515 (put 'ifinfo 'texinfo-end 'texinfo-discard-command) | |
1516 | |
1517 (put 'iftex 'texinfo-format 'texinfo-format-iftex) | |
1518 (defun texinfo-format-iftex () | |
1519 (delete-region texinfo-command-start | |
1520 (progn (re-search-forward "@end iftex[ \t]*\n") | |
1521 (point)))) | |
1522 | |
1523 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml) | |
1524 (defun texinfo-format-ifhtml () | |
1525 (delete-region texinfo-command-start | |
1526 (progn (re-search-forward "@end ifhtml[ \t]*\n") | |
1527 (point)))) | |
1528 | |
1529 (put 'tex 'texinfo-format 'texinfo-format-tex) | |
1530 (defun texinfo-format-tex () | |
1531 (delete-region texinfo-command-start | |
1532 (progn (re-search-forward "@end tex[ \t]*\n") | |
1533 (point)))) | |
1534 | |
1535 (put 'html 'texinfo-format 'texinfo-format-html) | |
1536 (defun texinfo-format-html () | |
1537 (delete-region texinfo-command-start | |
1538 (progn (re-search-forward "@end html[ \t]*\n") | |
1539 (point)))) | |
1540 | |
1541 | |
1542 ;;; @titlepage | |
1543 | |
1544 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage) | |
1545 (defun texinfo-format-titlepage () | |
1546 (delete-region texinfo-command-start | |
1547 (progn (re-search-forward "@end titlepage[ \t]*\n") | |
1548 (point)))) | |
1549 | |
1550 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line) | |
1551 | |
1552 ; @titlespec an alternative titling command; ignored by Info | |
1553 | |
1554 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec) | |
1555 (defun texinfo-format-titlespec () | |
1556 (delete-region texinfo-command-start | |
1557 (progn (re-search-forward "@end titlespec[ \t]*\n") | |
1558 (point)))) | |
1559 | |
1560 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line) | |
1561 | |
1562 | |
1563 ;;; @today | |
1564 | |
1565 (put 'today 'texinfo-format 'texinfo-format-today) | |
1566 | |
1567 ; Produces Day Month Year style of output. eg `1 Jan 1900' | |
1568 ; The `@today{}' command requires a pair of braces, like `@dots{}'. | |
1569 (defun texinfo-format-today () | |
1570 (texinfo-parse-arg-discard) | |
1571 (insert (format "%s %s %s" | |
1572 (substring (current-time-string) 8 10) | |
1573 (substring (current-time-string) 4 7) | |
1574 (substring (current-time-string) -4)))) | |
1575 | |
1576 | |
1577 ;;; @ignore | |
1578 | |
1579 (put 'ignore 'texinfo-format 'texinfo-format-ignore) | |
1580 (defun texinfo-format-ignore () | |
1581 (delete-region texinfo-command-start | |
1582 (progn (re-search-forward "@end ignore[ \t]*\n") | |
1583 (point)))) | |
1584 | |
1585 (put 'endignore 'texinfo-format 'texinfo-discard-line) | |
1586 | |
1587 | |
1588 ;;; Define the Info enclosure command: @definfoenclose | |
1589 | |
1590 ; A `@definfoenclose' command may be used to define a highlighting | |
1591 ; command for Info, but not for TeX. A command defined using | |
1592 ; `@definfoenclose' marks text by enclosing it in strings that precede | |
1593 ; and follow the text. | |
1594 ; | |
1595 ; Presumably, if you define a command with `@definfoenclose` for Info, | |
1596 ; you will also define the same command in the TeX definitions file, | |
1597 ; `texinfo.tex' in a manner appropriate for typesetting. | |
1598 ; | |
1599 ; Write a `@definfoenclose' command on a line and follow it with three | |
1600 ; arguments separated by commas (commas are used as separators in an | |
1601 ; `@node' line in the same way). The first argument to | |
1602 ; `@definfoenclose' is the @-command name \(without the `@'\); the | |
1603 ; second argument is the Info start delimiter string; and the third | |
1604 ; argument is the Info end delimiter string. The latter two arguments | |
1605 ; enclose the highlighted text in the Info file. A delimiter string | |
1606 ; may contain spaces. Neither the start nor end delimiter is | |
1607 ; required. However, if you do not provide a start delimiter, you | |
1608 ; must follow the command name with two commas in a row; otherwise, | |
1609 ; the Info formatting commands will misinterpret the end delimiter | |
1610 ; string as a start delimiter string. | |
1611 ; | |
1612 ; If you do a @definfoenclose{} on the name of a pre-defined macro (such | |
1613 ; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will | |
1614 ; override the built-in definition. | |
1615 ; | |
1616 ; An enclosure command defined this way takes one argument in braces. | |
1617 ; | |
1618 ; For example, you can write: | |
1619 ; | |
1620 ; @ifinfo | |
1621 ; @definfoenclose phoo, //, \\ | |
1622 ; @end ifinfo | |
1623 ; | |
1624 ; near the beginning of a Texinfo file at the beginning of the lines | |
1625 ; to define `@phoo' as an Info formatting command that inserts `//' | |
1626 ; before and `\\' after the argument to `@phoo'. You can then write | |
1627 ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info. | |
1628 ; | |
1629 ; Also, for TeX formatting, you could write | |
1630 ; | |
1631 ; @iftex | |
1632 ; @global@let@phoo=@i | |
1633 ; @end iftex | |
1634 ; | |
1635 ; to define `@phoo' as a command that causes TeX to typeset | |
1636 ; the argument to `@phoo' in italics. | |
1637 ; | |
1638 ; Note that each definition applies to its own formatter: one for TeX, | |
1639 ; the other for texinfo-format-buffer or texinfo-format-region. | |
1640 ; | |
1641 ; Here is another example: write | |
1642 ; | |
1643 ; @definfoenclose headword, , : | |
1644 ; | |
1645 ; near the beginning of the file, to define `@headword' as an Info | |
1646 ; formatting command that inserts nothing before and a colon after the | |
1647 ; argument to `@headword'. | |
1648 | |
1649 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure) | |
1650 (defun texinfo-define-info-enclosure () | |
1651 (let* ((args (texinfo-format-parse-line-args)) | |
1652 (command-name (nth 0 args)) | |
1653 (beginning-delimiter (or (nth 1 args) "")) | |
1654 (end-delimiter (or (nth 2 args) ""))) | |
1655 (texinfo-discard-command) | |
1656 (setq texinfo-enclosure-list | |
1657 (cons | |
1658 (list command-name | |
1659 (list | |
1660 beginning-delimiter | |
1661 end-delimiter)) | |
1662 texinfo-enclosure-list)))) | |
1663 | |
1664 | |
1665 ;;; @var, @code and the like | |
1666 | |
1667 (put 'var 'texinfo-format 'texinfo-format-var) | |
1668 ; @sc a small caps font for TeX; formatted as `var' in Info | |
1669 (put 'sc 'texinfo-format 'texinfo-format-var) | |
1670 (defun texinfo-format-var () | |
1671 (insert (upcase (texinfo-parse-arg-discard))) | |
1672 (goto-char texinfo-command-start)) | |
1673 | |
1674 ; various noops | |
1675 | |
1676 (put 'b 'texinfo-format 'texinfo-format-noop) | |
1677 (put 'i 'texinfo-format 'texinfo-format-noop) | |
1678 (put 'r 'texinfo-format 'texinfo-format-noop) | |
1679 (put 't 'texinfo-format 'texinfo-format-noop) | |
1680 (put 'w 'texinfo-format 'texinfo-format-noop) | |
1681 (put 'asis 'texinfo-format 'texinfo-format-noop) | |
1682 (put 'dmn 'texinfo-format 'texinfo-format-noop) | |
1683 (put 'key 'texinfo-format 'texinfo-format-noop) | |
1684 (put 'math 'texinfo-format 'texinfo-format-noop) | |
1685 (put 'titlefont 'texinfo-format 'texinfo-format-noop) | |
1686 (defun texinfo-format-noop () | |
1687 (insert (texinfo-parse-arg-discard)) | |
1688 (goto-char texinfo-command-start)) | |
1689 | |
1690 (put 'cite 'texinfo-format 'texinfo-format-code) | |
1691 (put 'code 'texinfo-format 'texinfo-format-code) | |
1692 (put 'file 'texinfo-format 'texinfo-format-code) | |
1693 (put 'kbd 'texinfo-format 'texinfo-format-code) | |
1694 (put 'samp 'texinfo-format 'texinfo-format-code) | |
1695 (defun texinfo-format-code () | |
1696 (insert "`" (texinfo-parse-arg-discard) "'") | |
1697 (goto-char texinfo-command-start)) | |
1698 | |
1699 (put 'emph 'texinfo-format 'texinfo-format-emph) | |
1700 (put 'strong 'texinfo-format 'texinfo-format-emph) | |
1701 (defun texinfo-format-emph () | |
1702 (insert "*" (texinfo-parse-arg-discard) "*") | |
1703 (goto-char texinfo-command-start)) | |
1704 | |
1705 (put 'dfn 'texinfo-format 'texinfo-format-defn) | |
1706 (put 'defn 'texinfo-format 'texinfo-format-defn) | |
1707 (defun texinfo-format-defn () | |
1708 (insert "\"" (texinfo-parse-arg-discard) "\"") | |
1709 (goto-char texinfo-command-start)) | |
1710 | |
1711 (put 'bullet 'texinfo-format 'texinfo-format-bullet) | |
1712 (defun texinfo-format-bullet () | |
1713 "Insert an asterisk. | |
1714 If used within a line, follow `@bullet' with braces." | |
1715 (texinfo-optional-braces-discard) | |
1716 (insert "*")) | |
1717 | |
1718 | |
1719 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample | |
1720 | |
1721 (put 'display 'texinfo-format 'texinfo-format-example) | |
1722 (put 'example 'texinfo-format 'texinfo-format-example) | |
1723 (put 'lisp 'texinfo-format 'texinfo-format-example) | |
1724 (put 'quotation 'texinfo-format 'texinfo-format-example) | |
1725 (put 'smallexample 'texinfo-format 'texinfo-format-example) | |
1726 (put 'smalllisp 'texinfo-format 'texinfo-format-example) | |
1727 (defun texinfo-format-example () | |
1728 (texinfo-push-stack 'example nil) | |
1729 (setq fill-column (- fill-column 5)) | |
1730 (texinfo-discard-line)) | |
1731 | |
1732 (put 'example 'texinfo-end 'texinfo-end-example) | |
1733 (put 'display 'texinfo-end 'texinfo-end-example) | |
1734 (put 'lisp 'texinfo-end 'texinfo-end-example) | |
1735 (put 'quotation 'texinfo-end 'texinfo-end-example) | |
1736 (put 'smallexample 'texinfo-end 'texinfo-end-example) | |
1737 (put 'smalllisp 'texinfo-end 'texinfo-end-example) | |
1738 (defun texinfo-end-example () | |
1739 (setq fill-column (+ fill-column 5)) | |
1740 (texinfo-discard-command) | |
1741 (let ((stacktop | |
1742 (texinfo-pop-stack 'example))) | |
1743 (texinfo-do-itemize (nth 1 stacktop)))) | |
1744 | |
1745 (put 'exdent 'texinfo-format 'texinfo-format-exdent) | |
1746 (defun texinfo-format-exdent () | |
1747 (texinfo-discard-command) | |
1748 (delete-region (point) | |
1749 (progn | |
1750 (skip-chars-forward " ") | |
1751 (point))) | |
1752 (insert ?\b) | |
1753 ;; Cancel out the deletion that texinfo-do-itemize | |
1754 ;; is going to do at the end of this line. | |
1755 (save-excursion | |
1756 (end-of-line) | |
1757 (insert "\n "))) | |
1758 | |
1759 | |
1760 ;;; @cartouche | |
1761 | |
1762 ; The @cartouche command is a noop in Info; in a printed manual, | |
1763 ; it makes a box with rounded corners. | |
1764 | |
1765 (put 'cartouche 'texinfo-format 'texinfo-discard-line) | |
1766 (put 'cartouche 'texinfo-end 'texinfo-discard-command) | |
1767 | |
1768 | |
1769 ;;; @flushleft and @format | |
1770 | |
1771 ; The @flushleft command left justifies every line but leaves the | |
1772 ; right end ragged. As far as Info is concerned, @flushleft is a | |
1773 ; `do-nothing' command | |
1774 | |
1775 ; The @format command is similar to @example except that it does not | |
1776 ; indent; this means that in Info, @format is similar to @flushleft. | |
1777 | |
1778 (put 'format 'texinfo-format 'texinfo-format-flushleft) | |
1779 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft) | |
1780 (defun texinfo-format-flushleft () | |
1781 (texinfo-discard-line)) | |
1782 | |
1783 (put 'format 'texinfo-end 'texinfo-end-flushleft) | |
1784 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft) | |
1785 (defun texinfo-end-flushleft () | |
1786 (texinfo-discard-command)) | |
1787 | |
1788 | |
1789 ;;; @flushright | |
1790 | |
1791 ; The @flushright command right justifies every line but leaves the | |
1792 ; left end ragged. Spaces and tabs at the right ends of lines are | |
1793 ; removed so that visible text lines up on the right side. | |
1794 | |
1795 (put 'flushright 'texinfo-format 'texinfo-format-flushright) | |
1796 (defun texinfo-format-flushright () | |
1797 (texinfo-push-stack 'flushright nil) | |
1798 (texinfo-discard-line)) | |
1799 | |
1800 (put 'flushright 'texinfo-end 'texinfo-end-flushright) | |
1801 (defun texinfo-end-flushright () | |
1802 (texinfo-discard-command) | |
1803 | |
1804 (let ((stacktop | |
1805 (texinfo-pop-stack 'flushright))) | |
1806 | |
1807 (texinfo-do-flushright (nth 1 stacktop)))) | |
1808 | |
1809 (defun texinfo-do-flushright (from) | |
1810 (save-excursion | |
1811 (while (progn (forward-line -1) | |
1812 (>= (point) from)) | |
1813 | |
1814 (beginning-of-line) | |
1815 (insert | |
1816 (make-string | |
1817 (- fill-column | |
1818 (save-excursion | |
1819 (end-of-line) | |
1820 (skip-chars-backward " \t") | |
1821 (delete-region (point) (progn (end-of-line) (point))) | |
1822 (current-column))) | |
1823 ? ))))) | |
1824 | |
1825 | |
1826 ;;; @ctrl, @TeX, @copyright, @minus, @dots | |
1827 | |
1828 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl) | |
1829 (defun texinfo-format-ctrl () | |
1830 (let ((str (texinfo-parse-arg-discard))) | |
1831 (insert (logand 31 (aref str 0))))) | |
1832 | |
1833 (put 'TeX 'texinfo-format 'texinfo-format-TeX) | |
1834 (defun texinfo-format-TeX () | |
1835 (texinfo-parse-arg-discard) | |
1836 (insert "TeX")) | |
1837 | |
1838 (put 'copyright 'texinfo-format 'texinfo-format-copyright) | |
1839 (defun texinfo-format-copyright () | |
1840 (texinfo-parse-arg-discard) | |
1841 (insert "(C)")) | |
1842 | |
1843 (put 'minus 'texinfo-format 'texinfo-format-minus) | |
1844 (defun texinfo-format-minus () | |
1845 "Insert a minus sign. | |
1846 If used within a line, follow `@minus' with braces." | |
1847 (texinfo-optional-braces-discard) | |
1848 (insert "-")) | |
1849 | |
1850 (put 'dots 'texinfo-format 'texinfo-format-dots) | |
1851 (defun texinfo-format-dots () | |
1852 (texinfo-parse-arg-discard) | |
1853 (insert "...")) | |
1854 | |
1855 (put 'enddots 'texinfo-format 'texinfo-format-enddots) | |
1856 (defun texinfo-format-enddots () | |
1857 (texinfo-parse-arg-discard) | |
1858 (insert "....")) | |
1859 | |
1860 | |
1861 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent | |
1862 | |
1863 ;;; Indent only those paragraphs that are refilled as a result of an | |
1864 ;;; @refill command. | |
1865 | |
1866 ; * If the value is `asis', do not change the existing indentation at | |
1867 ; the starts of paragraphs. | |
1868 | |
1869 ; * If the value zero, delete any existing indentation. | |
1870 | |
1871 ; * If the value is greater than zero, indent each paragraph by that | |
1872 ; number of spaces. | |
1873 | |
1874 ;;; But do not refill paragraphs with an @refill command that are | |
1875 ;;; preceded by @noindent or are part of a table, list, or deffn. | |
1876 | |
1877 (defvar texinfo-paragraph-indent "asis" | |
1878 "Number of spaces for @refill to indent a paragraph; else to leave as is.") | |
1879 | |
1880 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent) | |
1881 | |
1882 (defun texinfo-paragraphindent () | |
1883 "Specify the number of spaces for @refill to indent a paragraph. | |
1884 Default is to leave the number of spaces as is." | |
1885 (let ((arg (texinfo-parse-arg-discard))) | |
1886 (if (string= "asis" arg) | |
1887 (setq texinfo-paragraph-indent "asis") | |
1888 (setq texinfo-paragraph-indent (string-to-int arg))))) | |
1889 | |
1890 (put 'refill 'texinfo-format 'texinfo-format-refill) | |
1891 (defun texinfo-format-refill () | |
1892 "Refill paragraph. Also, indent first line as set by @paragraphindent. | |
1893 Default is to leave paragraph indentation as is." | |
1894 (texinfo-discard-command) | |
1895 (forward-paragraph -1) | |
1896 (if (looking-at "[ \t\n]*$") (forward-line 1)) | |
1897 ;; Do not indent if an entry in a list, table, or deffn, | |
1898 ;; or if paragraph is preceded by @noindent. | |
1899 ;; Otherwise, indent | |
1900 (cond | |
1901 ;; delete a @noindent line and do not indent paragraph | |
1902 ((save-excursion (forward-line -1) | |
1903 (looking-at "^@noindent")) | |
1904 (forward-line -1) | |
1905 (delete-region (point) (progn (forward-line 1) (point)))) | |
1906 ;; do nothing if "asis" | |
1907 ((equal texinfo-paragraph-indent "asis")) | |
1908 ;; do no indenting in list, etc. | |
1909 ((> texinfo-stack-depth 0)) | |
1910 ;; otherwise delete existing whitespace and indent | |
1911 (t | |
1912 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
1913 (insert (make-string texinfo-paragraph-indent ? )))) | |
1914 (forward-paragraph 1) | |
1915 (forward-line -1) | |
1916 (end-of-line) | |
1917 ;; Do not fill a section title line with asterisks, hyphens, etc. that | |
1918 ;; are used to underline it. This could occur if the line following | |
1919 ;; the underlining is not an index entry and has text within it. | |
1920 ;; XEmacs change: the standard 3.6 paragraph separators cause | |
1921 ;; texinfmt to fail on vm.texi so we continue to use the older version. | |
1922 (let* ((previous-paragraph-separate paragraph-separate) | |
1923 (paragraph-separate (concat paragraph-separate "\\|^[=*---.]+")) | |
1924 (previous-paragraph-start paragraph-start) | |
1925 (paragraph-start (concat paragraph-start "\\|^[=*---.]+"))) | |
1926 (unwind-protect | |
1927 (fill-paragraph nil) | |
1928 (setq paragraph-separate previous-paragraph-separate) | |
1929 (setq paragraph-start previous-paragraph-start)))) | |
1930 | |
1931 (put 'noindent 'texinfo-format 'texinfo-noindent) | |
1932 (defun texinfo-noindent () | |
1933 (save-excursion | |
1934 (forward-paragraph 1) | |
1935 (if (search-backward "@refill" | |
1936 (save-excursion (forward-line -1) (point)) t) | |
1937 () ; leave @noindent command so @refill command knows not to indent | |
1938 ;; else | |
1939 (texinfo-discard-line)))) | |
1940 | |
1941 | |
1942 ;;; Index generation | |
1943 | |
1944 (put 'vindex 'texinfo-format 'texinfo-format-vindex) | |
1945 (defun texinfo-format-vindex () | |
1946 (texinfo-index 'texinfo-vindex)) | |
1947 | |
1948 (put 'cindex 'texinfo-format 'texinfo-format-cindex) | |
1949 (defun texinfo-format-cindex () | |
1950 (texinfo-index 'texinfo-cindex)) | |
1951 | |
1952 (put 'findex 'texinfo-format 'texinfo-format-findex) | |
1953 (defun texinfo-format-findex () | |
1954 (texinfo-index 'texinfo-findex)) | |
1955 | |
1956 (put 'pindex 'texinfo-format 'texinfo-format-pindex) | |
1957 (defun texinfo-format-pindex () | |
1958 (texinfo-index 'texinfo-pindex)) | |
1959 | |
1960 (put 'tindex 'texinfo-format 'texinfo-format-tindex) | |
1961 (defun texinfo-format-tindex () | |
1962 (texinfo-index 'texinfo-tindex)) | |
1963 | |
1964 (put 'kindex 'texinfo-format 'texinfo-format-kindex) | |
1965 (defun texinfo-format-kindex () | |
1966 (texinfo-index 'texinfo-kindex)) | |
1967 | |
1968 (defun texinfo-index (indexvar) | |
1969 (let ((arg (texinfo-parse-expanded-arg))) | |
1970 (texinfo-discard-command) | |
1971 (set indexvar | |
1972 (cons (list arg | |
1973 texinfo-last-node | |
1974 ;; Region formatting may not provide last node position. | |
1975 (if texinfo-last-node-pos | |
1976 (1+ (count-lines texinfo-last-node-pos (point))) | |
1977 1)) | |
1978 (symbol-value indexvar))))) | |
1979 | |
1980 (defconst texinfo-indexvar-alist | |
1981 '(("cp" . texinfo-cindex) | |
1982 ("fn" . texinfo-findex) | |
1983 ("vr" . texinfo-vindex) | |
1984 ("tp" . texinfo-tindex) | |
1985 ("pg" . texinfo-pindex) | |
1986 ("ky" . texinfo-kindex))) | |
1987 | |
1988 | |
1989 ;;; @defindex @defcodeindex | |
1990 (put 'defindex 'texinfo-format 'texinfo-format-defindex) | |
1991 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex) | |
1992 | |
1993 (defun texinfo-format-defindex () | |
1994 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa' | |
1995 (indexing-command (intern (concat index-name "index"))) | |
1996 (index-formatting-command ; eg: `texinfo-format-aaindex' | |
1997 (intern (concat "texinfo-format-" index-name "index"))) | |
1998 (index-alist-name ; eg: `texinfo-aaindex' | |
1999 (intern (concat "texinfo-" index-name "index")))) | |
2000 | |
2001 (set index-alist-name nil) | |
2002 | |
2003 (put indexing-command ; eg, aaindex | |
2004 'texinfo-format | |
2005 index-formatting-command) ; eg, texinfo-format-aaindex | |
2006 | |
2007 ;; eg: "aa" . texinfo-aaindex | |
2008 (or (assoc index-name texinfo-indexvar-alist) | |
2009 (setq texinfo-indexvar-alist | |
2010 (cons | |
2011 (cons index-name | |
2012 index-alist-name) | |
2013 texinfo-indexvar-alist))) | |
2014 | |
2015 (fset index-formatting-command | |
2016 (list 'lambda 'nil | |
2017 (list 'texinfo-index | |
2018 (list 'quote index-alist-name)))))) | |
2019 | |
2020 | |
2021 ;;; @synindex @syncodeindex | |
2022 | |
2023 (put 'synindex 'texinfo-format 'texinfo-format-synindex) | |
2024 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex) | |
2025 | |
2026 (defun texinfo-format-synindex () | |
2027 (let* ((args (texinfo-parse-arg-discard)) | |
2028 (second (cdr (read-from-string args))) | |
2029 (joiner (symbol-name (car (read-from-string args)))) | |
2030 (joined (symbol-name (car (read-from-string args second))))) | |
2031 | |
2032 (if (assoc joiner texinfo-short-index-cmds-alist) | |
2033 (put | |
2034 (cdr (assoc joiner texinfo-short-index-cmds-alist)) | |
2035 'texinfo-format | |
2036 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist)) | |
2037 (intern (concat "texinfo-format-" joined "index")))) | |
2038 (put | |
2039 (intern (concat joiner "index")) | |
2040 'texinfo-format | |
2041 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist)) | |
2042 (intern (concat "texinfo-format-" joined "index"))))))) | |
2043 | |
2044 (defconst texinfo-short-index-cmds-alist | |
2045 '(("cp" . cindex) | |
2046 ("fn" . findex) | |
2047 ("vr" . vindex) | |
2048 ("tp" . tindex) | |
2049 ("pg" . pindex) | |
2050 ("ky" . kindex))) | |
2051 | |
2052 (defconst texinfo-short-index-format-cmds-alist | |
2053 '(("cp" . texinfo-format-cindex) | |
2054 ("fn" . texinfo-format-findex) | |
2055 ("vr" . texinfo-format-vindex) | |
2056 ("tp" . texinfo-format-tindex) | |
2057 ("pg" . texinfo-format-pindex) | |
2058 ("ky" . texinfo-format-kindex))) | |
2059 | |
2060 | |
2061 ;;; Sort and index (for VMS) | |
2062 | |
2063 ;; Sort an index which is in the current buffer between START and END. | |
2064 ;; Used on VMS, where the `sort' utility is not available. | |
2065 (defun texinfo-sort-region (start end) | |
2066 (require 'sort) | |
2067 (save-restriction | |
2068 (narrow-to-region start end) | |
2069 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun))) | |
2070 | |
2071 ;; Subroutine for sorting an index. | |
2072 ;; At start of a line, return a string to sort the line under. | |
2073 (defun texinfo-sort-startkeyfun () | |
2074 (let ((line | |
2075 (buffer-substring (point) (save-excursion (end-of-line) (point))))) | |
2076 ;; Canonicalize whitespace and eliminate funny chars. | |
2077 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line) | |
2078 (setq line (concat (substring line 0 (match-beginning 0)) | |
2079 " " | |
2080 (substring line (match-end 0) (length line))))) | |
2081 line)) | |
2082 | |
2083 | |
2084 ;;; @printindex | |
2085 | |
2086 (put 'printindex 'texinfo-format 'texinfo-format-printindex) | |
2087 | |
2088 (defun texinfo-format-printindex () | |
2089 (let ((indexelts (symbol-value | |
2090 (cdr (assoc (texinfo-parse-arg-discard) | |
2091 texinfo-indexvar-alist)))) | |
2092 opoint) | |
2093 (insert "\n* Menu:\n\n") | |
2094 (setq opoint (point)) | |
2095 (texinfo-print-index nil indexelts) | |
2096 | |
2097 (if (eq system-type 'vax-vms) | |
2098 (texinfo-sort-region opoint (point)) | |
2099 (shell-command-on-region opoint (point) "sort -fd" 1)))) | |
2100 | |
2101 (defun texinfo-print-index (file indexelts) | |
2102 (while indexelts | |
2103 (if (stringp (car (car indexelts))) | |
2104 (progn | |
2105 (insert "* " (car (car indexelts)) ": " ) | |
2106 (indent-to 32) | |
2107 (insert | |
2108 (if file (concat "(" file ")") "") | |
2109 (nth 1 (car indexelts)) ".") | |
2110 (indent-to 54) | |
2111 (insert | |
2112 (if (nth 2 (car indexelts)) | |
2113 (format " %d." (nth 2 (car indexelts))) | |
2114 "") | |
2115 "\n")) | |
2116 ;; index entries from @include'd file | |
2117 (texinfo-print-index (nth 1 (car indexelts)) | |
2118 (nth 2 (car indexelts)))) | |
2119 (setq indexelts (cdr indexelts)))) | |
2120 | |
2121 | |
2122 ;;; Glyphs: @equiv, @error, etc | |
2123 | |
2124 ;; @equiv to show that two expressions are equivalent | |
2125 ;; @error to show an error message | |
2126 ;; @expansion to show what a macro expands to | |
2127 ;; @point to show the location of point in an example | |
2128 ;; @print to show what an evaluated expression prints | |
2129 ;; @result to indicate the value returned by an expression | |
2130 | |
2131 (put 'equiv 'texinfo-format 'texinfo-format-equiv) | |
2132 (defun texinfo-format-equiv () | |
2133 (texinfo-parse-arg-discard) | |
2134 (insert "==")) | |
2135 | |
2136 (put 'error 'texinfo-format 'texinfo-format-error) | |
2137 (defun texinfo-format-error () | |
2138 (texinfo-parse-arg-discard) | |
2139 (insert "error-->")) | |
2140 | |
2141 (put 'expansion 'texinfo-format 'texinfo-format-expansion) | |
2142 (defun texinfo-format-expansion () | |
2143 (texinfo-parse-arg-discard) | |
2144 (insert "==>")) | |
2145 | |
2146 (put 'point 'texinfo-format 'texinfo-format-point) | |
2147 (defun texinfo-format-point () | |
2148 (texinfo-parse-arg-discard) | |
2149 (insert "-!-")) | |
2150 | |
2151 (put 'print 'texinfo-format 'texinfo-format-print) | |
2152 (defun texinfo-format-print () | |
2153 (texinfo-parse-arg-discard) | |
2154 (insert "-|")) | |
2155 | |
2156 (put 'result 'texinfo-format 'texinfo-format-result) | |
2157 (defun texinfo-format-result () | |
2158 (texinfo-parse-arg-discard) | |
2159 (insert "=>")) | |
2160 | |
2161 | |
2162 ;;; Definition formatting: @deffn, @defun, etc | |
2163 | |
2164 ;; What definition formatting produces: | |
2165 ;; | |
2166 ;; @deffn category name args... | |
2167 ;; In Info, `Category: name ARGS' | |
2168 ;; In index: name: node. line#. | |
2169 ;; | |
2170 ;; @defvr category name | |
2171 ;; In Info, `Category: name' | |
2172 ;; In index: name: node. line#. | |
2173 ;; | |
2174 ;; @deftp category name attributes... | |
2175 ;; `category name attributes...' Note: @deftp args in lower case. | |
2176 ;; In index: name: node. line#. | |
2177 ;; | |
2178 ;; Specialized function-like or variable-like entity: | |
2179 ;; | |
2180 ;; @defun, @defmac, @defspec, @defvar, @defopt | |
2181 ;; | |
2182 ;; @defun name args In Info, `Function: name ARGS' | |
2183 ;; @defmac name args In Info, `Macro: name ARGS' | |
2184 ;; @defvar name In Info, `Variable: name' | |
2185 ;; etc. | |
2186 ;; In index: name: node. line#. | |
2187 ;; | |
2188 ;; Generalized typed-function-like or typed-variable-like entity: | |
2189 ;; @deftypefn category data-type name args... | |
2190 ;; In Info, `Category: data-type name args...' | |
2191 ;; @deftypevr category data-type name | |
2192 ;; In Info, `Category: data-type name' | |
2193 ;; In index: name: node. line#. | |
2194 ;; | |
2195 ;; Specialized typed-function-like or typed-variable-like entity: | |
2196 ;; @deftypefun data-type name args... | |
2197 ;; In Info, `Function: data-type name ARGS' | |
2198 ;; In index: name: node. line#. | |
2199 ;; | |
2200 ;; @deftypevar data-type name | |
2201 ;; In Info, `Variable: data-type name' | |
2202 ;; In index: name: node. line#. but include args after name!? | |
2203 ;; | |
2204 ;; Generalized object oriented entity: | |
2205 ;; @defop category class name args... | |
2206 ;; In Info, `Category on class: name ARG' | |
2207 ;; In index: name on class: node. line#. | |
2208 ;; | |
2209 ;; @defcv category class name | |
2210 ;; In Info, `Category of class: name' | |
2211 ;; In index: name of class: node. line#. | |
2212 ;; | |
2213 ;; Specialized object oriented entity: | |
2214 ;; @defmethod class name args... | |
2215 ;; In Info, `Method on class: name ARGS' | |
2216 ;; In index: name on class: node. line#. | |
2217 ;; | |
2218 ;; @defivar class name | |
2219 ;; In Info, `Instance variable of class: name' | |
2220 ;; In index: name of class: node. line#. | |
2221 | |
2222 | |
2223 ;;; The definition formatting functions | |
2224 | |
2225 (defun texinfo-format-defun () | |
2226 (texinfo-push-stack 'defun nil) | |
2227 (setq fill-column (- fill-column 5)) | |
2228 (texinfo-format-defun-1 t)) | |
2229 | |
2230 (defun texinfo-end-defun () | |
2231 (setq fill-column (+ fill-column 5)) | |
2232 (texinfo-discard-command) | |
2233 (let ((start (nth 1 (texinfo-pop-stack 'defun)))) | |
2234 (texinfo-do-itemize start) | |
2235 ;; Delete extra newline inserted after header. | |
2236 (save-excursion | |
2237 (goto-char start) | |
2238 (delete-char -1)))) | |
2239 | |
2240 (defun texinfo-format-defunx () | |
2241 (texinfo-format-defun-1 nil)) | |
2242 | |
2243 (defun texinfo-format-defun-1 (first-p) | |
2244 (let ((parse-args (texinfo-format-parse-defun-args)) | |
2245 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type))) | |
2246 (texinfo-discard-command) | |
2247 ;; Delete extra newline inserted after previous header line. | |
2248 (if (not first-p) | |
2249 (delete-char -1)) | |
2250 (funcall | |
2251 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args) | |
2252 ;; Insert extra newline so that paragraph filling does not mess | |
2253 ;; with header line. | |
2254 (insert "\n\n") | |
2255 (rplaca (cdr (cdr (car texinfo-stack))) (point)) | |
2256 (funcall | |
2257 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args))) | |
2258 | |
2259 ;;; Formatting the first line of a definition | |
2260 | |
2261 ;; @deffn, @defvr, @deftp | |
2262 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2263 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2264 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2265 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2266 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2267 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) | |
2268 (defun texinfo-format-deffn (parsed-args) | |
2269 ;; Generalized function-like, variable-like, or generic data-type entity: | |
2270 ;; @deffn category name args... | |
2271 ;; In Info, `Category: name ARGS' | |
2272 ;; @deftp category name attributes... | |
2273 ;; `category name attributes...' Note: @deftp args in lower case. | |
2274 (let ((category (car parsed-args)) | |
2275 (name (car (cdr parsed-args))) | |
2276 (args (cdr (cdr parsed-args)))) | |
2277 (insert " -- " category ": " name) | |
2278 (while args | |
2279 (insert " " | |
2280 (if (or (= ?& (aref (car args) 0)) | |
2281 (eq (eval (car texinfo-defun-type)) 'deftp-type)) | |
2282 (car args) | |
2283 (upcase (car args)))) | |
2284 (setq args (cdr args))))) | |
2285 | |
2286 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple | |
2287 (put 'defun 'texinfo-deffn-formatting-property | |
2288 'texinfo-format-specialized-defun) | |
2289 (put 'defunx 'texinfo-deffn-formatting-property | |
2290 'texinfo-format-specialized-defun) | |
2291 (put 'defmac 'texinfo-deffn-formatting-property | |
2292 'texinfo-format-specialized-defun) | |
2293 (put 'defmacx 'texinfo-deffn-formatting-property | |
2294 'texinfo-format-specialized-defun) | |
2295 (put 'defspec 'texinfo-deffn-formatting-property | |
2296 'texinfo-format-specialized-defun) | |
2297 (put 'defspecx 'texinfo-deffn-formatting-property | |
2298 'texinfo-format-specialized-defun) | |
2299 (put 'defvar 'texinfo-deffn-formatting-property | |
2300 'texinfo-format-specialized-defun) | |
2301 (put 'defvarx 'texinfo-deffn-formatting-property | |
2302 'texinfo-format-specialized-defun) | |
2303 (put 'defopt 'texinfo-deffn-formatting-property | |
2304 'texinfo-format-specialized-defun) | |
2305 (put 'defoptx 'texinfo-deffn-formatting-property | |
2306 'texinfo-format-specialized-defun) | |
2307 (defun texinfo-format-specialized-defun (parsed-args) | |
2308 ;; Specialized function-like or variable-like entity: | |
2309 ;; @defun name args In Info, `Function: Name ARGS' | |
2310 ;; @defmac name args In Info, `Macro: Name ARGS' | |
2311 ;; @defvar name In Info, `Variable: Name' | |
2312 ;; Use cdr of texinfo-defun-type to determine category: | |
2313 (let ((category (car (cdr texinfo-defun-type))) | |
2314 (name (car parsed-args)) | |
2315 (args (cdr parsed-args))) | |
2316 (insert " -- " category ": " name) | |
2317 (while args | |
2318 (insert " " | |
2319 (if (= ?& (aref (car args) 0)) | |
2320 (car args) | |
2321 (upcase (car args)))) | |
2322 (setq args (cdr args))))) | |
2323 | |
2324 ;; @deftypefn, @deftypevr: Generalized typed | |
2325 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) | |
2326 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) | |
2327 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) | |
2328 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) | |
2329 (defun texinfo-format-deftypefn (parsed-args) | |
2330 ;; Generalized typed-function-like or typed-variable-like entity: | |
2331 ;; @deftypefn category data-type name args... | |
2332 ;; In Info, `Category: data-type name args...' | |
2333 ;; @deftypevr category data-type name | |
2334 ;; In Info, `Category: data-type name' | |
2335 ;; Note: args in lower case, unless modified in command line. | |
2336 (let ((category (car parsed-args)) | |
2337 (data-type (car (cdr parsed-args))) | |
2338 (name (car (cdr (cdr parsed-args)))) | |
2339 (args (cdr (cdr (cdr parsed-args))))) | |
2340 (insert " -- " category ": " data-type " " name) | |
2341 (while args | |
2342 (insert " " (car args)) | |
2343 (setq args (cdr args))))) | |
2344 | |
2345 ;; @deftypefun, @deftypevar: Specialized typed | |
2346 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun) | |
2347 (put 'deftypefunx 'texinfo-deffn-formatting-property | |
2348 'texinfo-format-deftypefun) | |
2349 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun) | |
2350 (put 'deftypevarx 'texinfo-deffn-formatting-property | |
2351 'texinfo-format-deftypefun) | |
2352 (defun texinfo-format-deftypefun (parsed-args) | |
2353 ;; Specialized typed-function-like or typed-variable-like entity: | |
2354 ;; @deftypefun data-type name args... | |
2355 ;; In Info, `Function: data-type name ARGS' | |
2356 ;; @deftypevar data-type name | |
2357 ;; In Info, `Variable: data-type name' | |
2358 ;; Note: args in lower case, unless modified in command line. | |
2359 ;; Use cdr of texinfo-defun-type to determine category: | |
2360 (let ((category (car (cdr texinfo-defun-type))) | |
2361 (data-type (car parsed-args)) | |
2362 (name (car (cdr parsed-args))) | |
2363 (args (cdr (cdr parsed-args)))) | |
2364 (insert " -- " category ": " data-type " " name) | |
2365 (while args | |
2366 (insert " " (car args)) | |
2367 (setq args (cdr args))))) | |
2368 | |
2369 ;; @defop: Generalized object-oriented | |
2370 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop) | |
2371 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop) | |
2372 (defun texinfo-format-defop (parsed-args) | |
2373 ;; Generalized object oriented entity: | |
2374 ;; @defop category class name args... | |
2375 ;; In Info, `Category on class: name ARG' | |
2376 ;; Note: args in upper case; use of `on' | |
2377 (let ((category (car parsed-args)) | |
2378 (class (car (cdr parsed-args))) | |
2379 (name (car (cdr (cdr parsed-args)))) | |
2380 (args (cdr (cdr (cdr parsed-args))))) | |
2381 (insert " -- " category " on " class ": " name) | |
2382 (while args | |
2383 (insert " " (upcase (car args))) | |
2384 (setq args (cdr args))))) | |
2385 | |
2386 ;; @defcv: Generalized object-oriented | |
2387 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv) | |
2388 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv) | |
2389 (defun texinfo-format-defcv (parsed-args) | |
2390 ;; Generalized object oriented entity: | |
2391 ;; @defcv category class name | |
2392 ;; In Info, `Category of class: name' | |
2393 ;; Note: args in upper case; use of `of' | |
2394 (let ((category (car parsed-args)) | |
2395 (class (car (cdr parsed-args))) | |
2396 (name (car (cdr (cdr parsed-args)))) | |
2397 (args (cdr (cdr (cdr parsed-args))))) | |
2398 (insert " -- " category " of " class ": " name) | |
2399 (while args | |
2400 (insert " " (upcase (car args))) | |
2401 (setq args (cdr args))))) | |
2402 | |
2403 ;; @defmethod: Specialized object-oriented | |
2404 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod) | |
2405 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod) | |
2406 (defun texinfo-format-defmethod (parsed-args) | |
2407 ;; Specialized object oriented entity: | |
2408 ;; @defmethod class name args... | |
2409 ;; In Info, `Method on class: name ARGS' | |
2410 ;; Note: args in upper case; use of `on' | |
2411 ;; Use cdr of texinfo-defun-type to determine category: | |
2412 (let ((category (car (cdr texinfo-defun-type))) | |
2413 (class (car parsed-args)) | |
2414 (name (car (cdr parsed-args))) | |
2415 (args (cdr (cdr parsed-args)))) | |
2416 (insert " -- " category " on " class ": " name) | |
2417 (while args | |
2418 (insert " " (upcase (car args))) | |
2419 (setq args (cdr args))))) | |
2420 | |
2421 ;; @defivar: Specialized object-oriented | |
2422 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar) | |
2423 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar) | |
2424 (defun texinfo-format-defivar (parsed-args) | |
2425 ;; Specialized object oriented entity: | |
2426 ;; @defivar class name | |
2427 ;; In Info, `Instance variable of class: name' | |
2428 ;; Note: args in upper case; use of `of' | |
2429 ;; Use cdr of texinfo-defun-type to determine category: | |
2430 (let ((category (car (cdr texinfo-defun-type))) | |
2431 (class (car parsed-args)) | |
2432 (name (car (cdr parsed-args))) | |
2433 (args (cdr (cdr parsed-args)))) | |
2434 (insert " -- " category " of " class ": " name) | |
2435 (while args | |
2436 (insert " " (upcase (car args))) | |
2437 (setq args (cdr args))))) | |
2438 | |
2439 | |
2440 ;;; Indexing for definitions | |
2441 | |
2442 ;; An index entry has three parts: the `entry proper', the node name, and the | |
2443 ;; line number. Depending on the which command is used, the entry is | |
2444 ;; formatted differently: | |
2445 ;; | |
2446 ;; @defun, | |
2447 ;; @defmac, | |
2448 ;; @defspec, | |
2449 ;; @defvar, | |
2450 ;; @defopt all use their 1st argument as the entry-proper | |
2451 ;; | |
2452 ;; @deffn, | |
2453 ;; @defvr, | |
2454 ;; @deftp | |
2455 ;; @deftypefun | |
2456 ;; @deftypevar all use their 2nd argument as the entry-proper | |
2457 ;; | |
2458 ;; @deftypefn, | |
2459 ;; @deftypevr both use their 3rd argument as the entry-proper | |
2460 ;; | |
2461 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper | |
2462 ;; formatted: NAME on CLASS | |
2463 | |
2464 ;; @defop uses its 3rd and 2nd arguments as an entry-proper | |
2465 ;; formatted: NAME on CLASS | |
2466 ;; | |
2467 ;; @defivar uses its 2nd and 1st arguments as an entry-proper | |
2468 ;; formatted: NAME of CLASS | |
2469 ;; | |
2470 ;; @defcv uses its 3rd and 2nd argument as an entry-proper | |
2471 ;; formatted: NAME of CLASS | |
2472 | |
2473 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2474 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2475 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2476 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2477 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2478 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2479 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2480 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2481 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2482 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun) | |
2483 (defun texinfo-index-defun (parsed-args) | |
2484 ;; use 1st parsed-arg as entry-proper | |
2485 ;; `index-list' will be texinfo-findex or the like | |
2486 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2487 (set index-list | |
2488 (cons | |
2489 ;; Three elements: entry-proper, node-name, line-number | |
2490 (list | |
2491 (car parsed-args) | |
2492 texinfo-last-node | |
2493 ;; Region formatting may not provide last node position. | |
2494 (if texinfo-last-node-pos | |
2495 (1+ (count-lines texinfo-last-node-pos (point))) | |
2496 1)) | |
2497 (symbol-value index-list))))) | |
2498 | |
2499 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2500 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2501 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2502 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2503 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2504 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2505 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2506 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2507 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2508 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn) | |
2509 (defun texinfo-index-deffn (parsed-args) | |
2510 ;; use 2nd parsed-arg as entry-proper | |
2511 ;; `index-list' will be texinfo-findex or the like | |
2512 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2513 (set index-list | |
2514 (cons | |
2515 ;; Three elements: entry-proper, node-name, line-number | |
2516 (list | |
2517 (car (cdr parsed-args)) | |
2518 texinfo-last-node | |
2519 ;; Region formatting may not provide last node position. | |
2520 (if texinfo-last-node-pos | |
2521 (1+ (count-lines texinfo-last-node-pos (point))) | |
2522 1)) | |
2523 (symbol-value index-list))))) | |
2524 | |
2525 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) | |
2526 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) | |
2527 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) | |
2528 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) | |
2529 (defun texinfo-index-deftypefn (parsed-args) | |
2530 ;; use 3rd parsed-arg as entry-proper | |
2531 ;; `index-list' will be texinfo-findex or the like | |
2532 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2533 (set index-list | |
2534 (cons | |
2535 ;; Three elements: entry-proper, node-name, line-number | |
2536 (list | |
2537 (car (cdr (cdr parsed-args))) | |
2538 texinfo-last-node | |
2539 ;; Region formatting may not provide last node position. | |
2540 (if texinfo-last-node-pos | |
2541 (1+ (count-lines texinfo-last-node-pos (point))) | |
2542 1)) | |
2543 (symbol-value index-list))))) | |
2544 | |
2545 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod) | |
2546 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod) | |
2547 (defun texinfo-index-defmethod (parsed-args) | |
2548 ;; use 2nd on 1st parsed-arg as entry-proper | |
2549 ;; `index-list' will be texinfo-findex or the like | |
2550 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2551 (set index-list | |
2552 (cons | |
2553 ;; Three elements: entry-proper, node-name, line-number | |
2554 (list | |
2555 (format "%s on %s" | |
2556 (car (cdr parsed-args)) | |
2557 (car parsed-args)) | |
2558 texinfo-last-node | |
2559 ;; Region formatting may not provide last node position. | |
2560 (if texinfo-last-node-pos | |
2561 (1+ (count-lines texinfo-last-node-pos (point))) | |
2562 1)) | |
2563 (symbol-value index-list))))) | |
2564 | |
2565 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop) | |
2566 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop) | |
2567 (defun texinfo-index-defop (parsed-args) | |
2568 ;; use 3rd on 2nd parsed-arg as entry-proper | |
2569 ;; `index-list' will be texinfo-findex or the like | |
2570 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2571 (set index-list | |
2572 (cons | |
2573 ;; Three elements: entry-proper, node-name, line-number | |
2574 (list | |
2575 (format "%s on %s" | |
2576 (car (cdr (cdr parsed-args))) | |
2577 (car (cdr parsed-args))) | |
2578 texinfo-last-node | |
2579 ;; Region formatting may not provide last node position. | |
2580 (if texinfo-last-node-pos | |
2581 (1+ (count-lines texinfo-last-node-pos (point))) | |
2582 1)) | |
2583 (symbol-value index-list))))) | |
2584 | |
2585 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar) | |
2586 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar) | |
2587 (defun texinfo-index-defivar (parsed-args) | |
2588 ;; use 2nd of 1st parsed-arg as entry-proper | |
2589 ;; `index-list' will be texinfo-findex or the like | |
2590 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2591 (set index-list | |
2592 (cons | |
2593 ;; Three elements: entry-proper, node-name, line-number | |
2594 (list | |
2595 (format "%s of %s" | |
2596 (car (cdr parsed-args)) | |
2597 (car parsed-args)) | |
2598 texinfo-last-node | |
2599 ;; Region formatting may not provide last node position. | |
2600 (if texinfo-last-node-pos | |
2601 (1+ (count-lines texinfo-last-node-pos (point))) | |
2602 1)) | |
2603 (symbol-value index-list))))) | |
2604 | |
2605 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv) | |
2606 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv) | |
2607 (defun texinfo-index-defcv (parsed-args) | |
2608 ;; use 3rd of 2nd parsed-arg as entry-proper | |
2609 ;; `index-list' will be texinfo-findex or the like | |
2610 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) | |
2611 (set index-list | |
2612 (cons | |
2613 ;; Three elements: entry-proper, node-name, line-number | |
2614 (list | |
2615 (format "%s of %s" | |
2616 (car (cdr (cdr parsed-args))) | |
2617 (car (cdr parsed-args))) | |
2618 texinfo-last-node | |
2619 ;; Region formatting may not provide last node position. | |
2620 (if texinfo-last-node-pos | |
2621 (1+ (count-lines texinfo-last-node-pos (point))) | |
2622 1)) | |
2623 (symbol-value index-list))))) | |
2624 | |
2625 | |
2626 ;;; Properties for definitions | |
2627 | |
2628 ;; Each definition command has six properties: | |
2629 ;; | |
2630 ;; 1. texinfo-deffn-formatting-property to format definition line | |
2631 ;; 2. texinfo-defun-indexing-property to create index entry | |
2632 ;; 3. texinfo-format formatting command | |
2633 ;; 4. texinfo-end end formatting command | |
2634 ;; 5. texinfo-defun-type type of deffn to format | |
2635 ;; 6. texinfo-defun-index type of index to use | |
2636 ;; | |
2637 ;; The `x' forms of each definition command are used for the second | |
2638 ;; and subsequent header lines. | |
2639 | |
2640 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property | |
2641 ;; are listed just before the appropriate formatting and indexing commands. | |
2642 | |
2643 (put 'deffn 'texinfo-format 'texinfo-format-defun) | |
2644 (put 'deffnx 'texinfo-format 'texinfo-format-defunx) | |
2645 (put 'deffn 'texinfo-end 'texinfo-end-defun) | |
2646 (put 'deffn 'texinfo-defun-type '('deffn-type nil)) | |
2647 (put 'deffnx 'texinfo-defun-type '('deffn-type nil)) | |
2648 (put 'deffn 'texinfo-defun-index 'texinfo-findex) | |
2649 (put 'deffnx 'texinfo-defun-index 'texinfo-findex) | |
2650 | |
2651 (put 'defun 'texinfo-format 'texinfo-format-defun) | |
2652 (put 'defunx 'texinfo-format 'texinfo-format-defunx) | |
2653 (put 'defun 'texinfo-end 'texinfo-end-defun) | |
2654 (put 'defun 'texinfo-defun-type '('defun-type "Function")) | |
2655 (put 'defunx 'texinfo-defun-type '('defun-type "Function")) | |
2656 (put 'defun 'texinfo-defun-index 'texinfo-findex) | |
2657 (put 'defunx 'texinfo-defun-index 'texinfo-findex) | |
2658 | |
2659 (put 'defmac 'texinfo-format 'texinfo-format-defun) | |
2660 (put 'defmacx 'texinfo-format 'texinfo-format-defunx) | |
2661 (put 'defmac 'texinfo-end 'texinfo-end-defun) | |
2662 (put 'defmac 'texinfo-defun-type '('defun-type "Macro")) | |
2663 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro")) | |
2664 (put 'defmac 'texinfo-defun-index 'texinfo-findex) | |
2665 (put 'defmacx 'texinfo-defun-index 'texinfo-findex) | |
2666 | |
2667 (put 'defspec 'texinfo-format 'texinfo-format-defun) | |
2668 (put 'defspecx 'texinfo-format 'texinfo-format-defunx) | |
2669 (put 'defspec 'texinfo-end 'texinfo-end-defun) | |
2670 (put 'defspec 'texinfo-defun-type '('defun-type "Special form")) | |
2671 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form")) | |
2672 (put 'defspec 'texinfo-defun-index 'texinfo-findex) | |
2673 (put 'defspecx 'texinfo-defun-index 'texinfo-findex) | |
2674 | |
2675 (put 'defvr 'texinfo-format 'texinfo-format-defun) | |
2676 (put 'defvrx 'texinfo-format 'texinfo-format-defunx) | |
2677 (put 'defvr 'texinfo-end 'texinfo-end-defun) | |
2678 (put 'defvr 'texinfo-defun-type '('deffn-type nil)) | |
2679 (put 'defvrx 'texinfo-defun-type '('deffn-type nil)) | |
2680 (put 'defvr 'texinfo-defun-index 'texinfo-vindex) | |
2681 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex) | |
2682 | |
2683 (put 'defvar 'texinfo-format 'texinfo-format-defun) | |
2684 (put 'defvarx 'texinfo-format 'texinfo-format-defunx) | |
2685 (put 'defvar 'texinfo-end 'texinfo-end-defun) | |
2686 (put 'defvar 'texinfo-defun-type '('defun-type "Variable")) | |
2687 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable")) | |
2688 (put 'defvar 'texinfo-defun-index 'texinfo-vindex) | |
2689 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex) | |
2690 | |
2691 (put 'defconst 'texinfo-format 'texinfo-format-defun) | |
2692 (put 'defconstx 'texinfo-format 'texinfo-format-defunx) | |
2693 (put 'defconst 'texinfo-end 'texinfo-end-defun) | |
2694 (put 'defconst 'texinfo-defun-type '('defun-type "Constant")) | |
2695 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant")) | |
2696 (put 'defconst 'texinfo-defun-index 'texinfo-vindex) | |
2697 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex) | |
2698 | |
2699 (put 'defcmd 'texinfo-format 'texinfo-format-defun) | |
2700 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx) | |
2701 (put 'defcmd 'texinfo-end 'texinfo-end-defun) | |
2702 (put 'defcmd 'texinfo-defun-type '('defun-type "Command")) | |
2703 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command")) | |
2704 (put 'defcmd 'texinfo-defun-index 'texinfo-findex) | |
2705 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex) | |
2706 | |
2707 (put 'defopt 'texinfo-format 'texinfo-format-defun) | |
2708 (put 'defoptx 'texinfo-format 'texinfo-format-defunx) | |
2709 (put 'defopt 'texinfo-end 'texinfo-end-defun) | |
2710 (put 'defopt 'texinfo-defun-type '('defun-type "User Option")) | |
2711 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option")) | |
2712 (put 'defopt 'texinfo-defun-index 'texinfo-vindex) | |
2713 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex) | |
2714 | |
2715 (put 'deftp 'texinfo-format 'texinfo-format-defun) | |
2716 (put 'deftpx 'texinfo-format 'texinfo-format-defunx) | |
2717 (put 'deftp 'texinfo-end 'texinfo-end-defun) | |
2718 (put 'deftp 'texinfo-defun-type '('deftp-type nil)) | |
2719 (put 'deftpx 'texinfo-defun-type '('deftp-type nil)) | |
2720 (put 'deftp 'texinfo-defun-index 'texinfo-tindex) | |
2721 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex) | |
2722 | |
2723 ;;; Object-oriented stuff is a little hairier. | |
2724 | |
2725 (put 'defop 'texinfo-format 'texinfo-format-defun) | |
2726 (put 'defopx 'texinfo-format 'texinfo-format-defunx) | |
2727 (put 'defop 'texinfo-end 'texinfo-end-defun) | |
2728 (put 'defop 'texinfo-defun-type '('defop-type nil)) | |
2729 (put 'defopx 'texinfo-defun-type '('defop-type nil)) | |
2730 (put 'defop 'texinfo-defun-index 'texinfo-findex) | |
2731 (put 'defopx 'texinfo-defun-index 'texinfo-findex) | |
2732 | |
2733 (put 'defmethod 'texinfo-format 'texinfo-format-defun) | |
2734 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx) | |
2735 (put 'defmethod 'texinfo-end 'texinfo-end-defun) | |
2736 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method")) | |
2737 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method")) | |
2738 (put 'defmethod 'texinfo-defun-index 'texinfo-findex) | |
2739 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex) | |
2740 | |
2741 (put 'defcv 'texinfo-format 'texinfo-format-defun) | |
2742 (put 'defcvx 'texinfo-format 'texinfo-format-defunx) | |
2743 (put 'defcv 'texinfo-end 'texinfo-end-defun) | |
2744 (put 'defcv 'texinfo-defun-type '('defop-type nil)) | |
2745 (put 'defcvx 'texinfo-defun-type '('defop-type nil)) | |
2746 (put 'defcv 'texinfo-defun-index 'texinfo-vindex) | |
2747 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex) | |
2748 | |
2749 (put 'defivar 'texinfo-format 'texinfo-format-defun) | |
2750 (put 'defivarx 'texinfo-format 'texinfo-format-defunx) | |
2751 (put 'defivar 'texinfo-end 'texinfo-end-defun) | |
2752 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable")) | |
2753 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable")) | |
2754 (put 'defivar 'texinfo-defun-index 'texinfo-vindex) | |
2755 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex) | |
2756 | |
2757 ;;; Typed functions and variables | |
2758 | |
2759 (put 'deftypefn 'texinfo-format 'texinfo-format-defun) | |
2760 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx) | |
2761 (put 'deftypefn 'texinfo-end 'texinfo-end-defun) | |
2762 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil)) | |
2763 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil)) | |
2764 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex) | |
2765 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex) | |
2766 | |
2767 (put 'deftypefun 'texinfo-format 'texinfo-format-defun) | |
2768 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx) | |
2769 (put 'deftypefun 'texinfo-end 'texinfo-end-defun) | |
2770 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function")) | |
2771 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function")) | |
2772 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex) | |
2773 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex) | |
2774 | |
2775 (put 'deftypevr 'texinfo-format 'texinfo-format-defun) | |
2776 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx) | |
2777 (put 'deftypevr 'texinfo-end 'texinfo-end-defun) | |
2778 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil)) | |
2779 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil)) | |
2780 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex) | |
2781 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex) | |
2782 | |
2783 (put 'deftypevar 'texinfo-format 'texinfo-format-defun) | |
2784 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx) | |
2785 (put 'deftypevar 'texinfo-end 'texinfo-end-defun) | |
2786 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable")) | |
2787 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable")) | |
2788 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex) | |
2789 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex) | |
2790 | |
2791 | |
2792 ;;; @set, @clear, @ifset, @ifclear | |
2793 | |
2794 ;; If a flag is set with @set FLAG, then text between @ifset and @end | |
2795 ;; ifset is formatted normally, but if the flag is is cleared with | |
2796 ;; @clear FLAG, then the text is not formatted; it is ignored. | |
2797 | |
2798 ;; If a flag is cleared with @clear FLAG, then text between @ifclear | |
2799 ;; and @end ifclear is formatted normally, but if the flag is is set with | |
2800 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear | |
2801 ;; is the opposite of @ifset. | |
2802 | |
2803 ;; If a flag is set to a string with @set FLAG, | |
2804 ;; replace @value{FLAG} with the string. | |
2805 ;; If a flag with a value is cleared, | |
2806 ;; @value{FLAG} is invalid, | |
2807 ;; as if there had never been any @set FLAG previously. | |
2808 | |
2809 (put 'clear 'texinfo-format 'texinfo-clear) | |
2810 (defun texinfo-clear () | |
2811 "Clear the value of the flag." | |
2812 (let* ((arg (texinfo-parse-arg-discard)) | |
2813 (flag (car (read-from-string arg))) | |
2814 (value (substring arg (cdr (read-from-string arg))))) | |
2815 (put flag 'texinfo-whether-setp 'flag-cleared) | |
2816 (put flag 'texinfo-set-value ""))) | |
2817 | |
2818 (put 'set 'texinfo-format 'texinfo-set) | |
2819 (defun texinfo-set () | |
2820 "Set the value of the flag, optionally to a string. | |
2821 The command `@set foo This is a string.' | |
2822 sets flag foo to the value: `This is a string.' | |
2823 The command `@value{foo}' expands to the value." | |
2824 (let* ((arg (texinfo-parse-arg-discard)) | |
2825 (flag (car (read-from-string arg))) | |
2826 (value (substring arg (cdr (read-from-string arg))))) | |
2827 (put flag 'texinfo-whether-setp 'flag-set) | |
2828 (put flag 'texinfo-set-value value))) | |
2829 | |
2830 (put 'value 'texinfo-format 'texinfo-value) | |
2831 (defun texinfo-value () | |
2832 "Insert the string to which the flag is set. | |
2833 The command `@set foo This is a string.' | |
2834 sets flag foo to the value: `This is a string.' | |
2835 The command `@value{foo}' expands to the value." | |
2836 (let ((arg (texinfo-parse-arg-discard))) | |
2837 (cond ((and | |
2838 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2839 'flag-set) | |
2840 (get (car (read-from-string arg)) 'texinfo-set-value)) | |
2841 (insert (get (car (read-from-string arg)) 'texinfo-set-value))) | |
2842 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2843 'flag-cleared) | |
2844 (insert (format "{No value for \"%s\"}" arg))) | |
2845 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil) | |
2846 (insert (format "{No value for \"%s\"}" arg)))))) | |
2847 | |
2848 (put 'ifset 'texinfo-end 'texinfo-discard-command) | |
2849 (put 'ifset 'texinfo-format 'texinfo-if-set) | |
2850 (defun texinfo-if-set () | |
2851 "If set, continue formatting; else do not format region up to @end ifset" | |
2852 (let ((arg (texinfo-parse-arg-discard))) | |
2853 (cond | |
2854 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2855 'flag-set) | |
2856 ;; Format the text (i.e., do not remove it); do nothing here. | |
2857 ()) | |
2858 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2859 'flag-cleared) | |
2860 ;; Clear region (i.e., cause the text to be ignored). | |
2861 (delete-region texinfo-command-start | |
2862 (progn (re-search-forward "@end ifset[ \t]*\n") | |
2863 (point)))) | |
2864 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2865 nil) | |
2866 ;; In this case flag is neither set nor cleared. | |
2867 ;; Act as if set, i.e. do nothing. | |
2868 ())))) | |
2869 | |
2870 (put 'ifclear 'texinfo-end 'texinfo-discard-command) | |
2871 (put 'ifclear 'texinfo-format 'texinfo-if-clear) | |
2872 (defun texinfo-if-clear () | |
2873 "If clear, continue formatting; if set, do not format up to @end ifset" | |
2874 (let ((arg (texinfo-parse-arg-discard))) | |
2875 (cond | |
2876 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2877 'flag-set) | |
2878 ;; Clear region (i.e., cause the text to be ignored). | |
2879 (delete-region texinfo-command-start | |
2880 (progn (re-search-forward "@end ifclear[ \t]*\n") | |
2881 (point)))) | |
2882 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2883 'flag-cleared) | |
2884 ;; Format the text (i.e., do not remove it); do nothing here. | |
2885 ()) | |
2886 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | |
2887 nil) | |
2888 ;; In this case flag is neither set nor cleared. | |
2889 ;; Act as if clear, i.e. do nothing. | |
2890 ())))) | |
2891 | |
2892 | |
2893 ;;; Process included files: `@include' command | |
2894 | |
2895 ;; Updated 19 October 1990 | |
2896 ;; In the original version, include files were ignored by Info but | |
2897 ;; incorporated in to the printed manual. To make references to the | |
2898 ;; included file, the Texinfo source file has to refer to the included | |
2899 ;; files using the `(filename)nodename' format for refering to other | |
2900 ;; Info files. Also, the included files had to be formatted on their | |
2901 ;; own. It was just like they were another file. | |
2902 | |
2903 ;; Currently, include files are inserted into the buffer that is | |
2904 ;; formatted for Info. If large, the resulting info file is split and | |
2905 ;; tagified. For current include files to work, the master menu must | |
2906 ;; refer to all the nodes, and the highest level nodes in the include | |
2907 ;; files must have the correct next, prev, and up pointers. | |
2908 | |
2909 ;; The included file may have an @setfilename and even an @settitle, | |
2910 ;; but not an `\input texinfo' line. | |
2911 | |
2912 ;; Updated 24 March 1993 | |
2913 ;; In order for @raisesections and @lowersections to work, included | |
2914 ;; files must be inserted into the buffer holding the outer file | |
2915 ;; before other Info formatting takes place. So @include is no longer | |
2916 ;; is treated like other @-commands. | |
2917 (put 'include 'texinfo-format 'texinfo-format-noop) | |
2918 | |
2919 ; Original definition: | |
2920 ; (defun texinfo-format-include () | |
2921 ; (let ((filename (texinfo-parse-arg-discard)) | |
2922 ; (default-directory input-directory) | |
2923 ; subindex) | |
2924 ; (setq subindex | |
2925 ; (save-excursion | |
2926 ; (progn (find-file | |
2927 ; (cond ((file-readable-p (concat filename ".texinfo")) | |
2928 ; (concat filename ".texinfo")) | |
2929 ; ((file-readable-p (concat filename ".texi")) | |
2930 ; (concat filename ".texi")) | |
2931 ; ((file-readable-p (concat filename ".tex")) | |
2932 ; (concat filename ".tex")) | |
2933 ; ((file-readable-p filename) | |
2934 ; filename) | |
2935 ; (t (error "@include'd file %s not found" | |
2936 ; filename)))) | |
2937 ; (texinfo-format-buffer-1)))) | |
2938 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex)) | |
2939 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex)) | |
2940 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex)) | |
2941 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex)) | |
2942 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex)) | |
2943 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex)))) | |
2944 ; | |
2945 ;(defun texinfo-subindex (indexvar file content) | |
2946 ; (set indexvar (cons (list 'recurse file content) | |
2947 ; (symbol-value indexvar)))) | |
2948 | |
2949 ; Second definition: | |
2950 ; (put 'include 'texinfo-format 'texinfo-format-include) | |
2951 ; (defun texinfo-format-include () | |
2952 ; (let ((filename (concat input-directory | |
2953 ; (texinfo-parse-arg-discard))) | |
2954 ; (default-directory input-directory)) | |
2955 ; (message "Reading: %s" filename) | |
2956 ; (save-excursion | |
2957 ; (save-restriction | |
2958 ; (narrow-to-region | |
2959 ; (point) | |
2960 ; (+ (point) (car (cdr (insert-file-contents filename))))) | |
2961 ; (goto-char (point-min)) | |
2962 ; (texinfo-append-refill) | |
2963 ; (texinfo-format-convert (point-min) (point-max)))) | |
2964 ; (setq last-input-buffer input-buffer) ; to bypass setfilename | |
2965 ; )) | |
2966 | |
2967 | |
2968 ;;; Numerous commands do nothing in Texinfo | |
2969 | |
2970 ;; These commands are defined in texinfo.tex for printed output. | |
2971 | |
2972 (put 'bye 'texinfo-format 'texinfo-discard-line) | |
2973 (put 'c 'texinfo-format 'texinfo-discard-line-with-args) | |
2974 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args) | |
2975 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args) | |
2976 (put 'finalout 'texinfo-format 'texinfo-discard-line) | |
2977 (put 'group 'texinfo-end 'texinfo-discard-line-with-args) | |
2978 (put 'group 'texinfo-format 'texinfo-discard-line-with-args) | |
2979 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args) | |
2980 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args) | |
2981 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args) | |
2982 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args) | |
2983 (put 'need 'texinfo-format 'texinfo-discard-line-with-args) | |
2984 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args) | |
2985 (put 'page 'texinfo-format 'texinfo-discard-line-with-args) | |
2986 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args) | |
2987 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args) | |
2988 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args) | |
2989 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args) | |
2990 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args) | |
2991 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args) | |
2992 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args) | |
2993 (put 'smallbook 'texinfo-format 'texinfo-discard-line) | |
2994 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args) | |
2995 | |
2996 | |
2997 ;;; Some commands cannot be handled | |
2998 | |
2999 (defun texinfo-unsupported () | |
3000 (error "%s is not handled by texinfo" | |
3001 (buffer-substring texinfo-command-start texinfo-command-end))) | |
3002 | |
3003 ;;; Batch formatting | |
3004 | |
3005 ;;;###autoload | |
3006 (defun batch-texinfo-format () | |
3007 "Runs texinfo-format-buffer on the files remaining on the command line. | |
3008 Must be used only with -batch, and kills emacs on completion. | |
3009 Each file will be processed even if an error occurred previously. | |
3010 For example, invoke | |
3011 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"." | |
3012 (if (not noninteractive) | |
3013 (error "batch-texinfo-format may only be used -batch.")) | |
3014 (let ((version-control t) | |
3015 (auto-save-default nil) | |
3016 (find-file-run-dired nil) | |
3017 (kept-old-versions 259259) | |
3018 (kept-new-versions 259259)) | |
3019 (let ((error 0) | |
3020 file | |
3021 (files ())) | |
3022 (while command-line-args-left | |
3023 (setq file (expand-file-name (car command-line-args-left))) | |
3024 (cond ((not (file-exists-p file)) | |
3025 (message ">> %s does not exist!" file) | |
3026 (setq error 1 | |
3027 command-line-args-left (cdr command-line-args-left))) | |
3028 ((file-directory-p file) | |
3029 (setq command-line-args-left | |
3030 (nconc (directory-files file) | |
3031 (cdr command-line-args-left)))) | |
3032 (t | |
3033 (setq files (cons file files) | |
3034 command-line-args-left (cdr command-line-args-left))))) | |
3035 (while files | |
3036 (setq file (car files) | |
3037 files (cdr files)) | |
3038 (condition-case err | |
3039 (progn | |
3040 (if buffer-file-name (kill-buffer (current-buffer))) | |
3041 (find-file file) | |
3042 (buffer-disable-undo (current-buffer)) | |
3043 (set-buffer-modified-p nil) | |
3044 (texinfo-mode) | |
3045 (message "texinfo formatting %s..." file) | |
3046 (texinfo-format-buffer nil) | |
3047 (if (buffer-modified-p) | |
3048 (progn (message "Saving modified %s" (buffer-file-name)) | |
3049 (save-buffer)))) | |
3050 (error | |
3051 (message ">> Error: %s" (prin1-to-string err)) | |
3052 (message ">> point at") | |
3053 (let ((s (buffer-substring (point) | |
3054 (min (+ (point) 100) | |
3055 (point-max)))) | |
3056 (tem 0)) | |
3057 (while (setq tem (string-match "\n+" s tem)) | |
3058 (setq s (concat (substring s 0 (match-beginning 0)) | |
3059 "\n>> " | |
3060 (substring s (match-end 0))) | |
3061 tem (1+ tem))) | |
3062 (message ">> %s" s)) | |
3063 (setq error 1)))) | |
3064 (kill-emacs error)))) | |
3065 | |
3066 | |
3067 ;;; Place `provide' at end of file. | |
3068 (provide 'texinfmt) | |
3069 | |
3070 ;;; texinfmt.el ends here. |