]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfmt.el
Many doc fixes.
[gnu-emacs] / lisp / textmodes / texinfmt.el
1 ;;; texinfmt.el --- format Texinfo files into Info files.
2
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5
6 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
7 ;; Keywords: maint, tex, docs
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 ;;; Emacs lisp functions to convert Texinfo files to Info files.
29
30 (defvar texinfmt-version "2.37 of 24 May 1997")
31
32 (defun texinfmt-version (&optional here)
33 "Show the version of texinfmt.el in the minibuffer.
34 If optional argument HERE is non-nil, insert info at point."
35 (interactive "P")
36 (let ((version-string
37 (format "Version of \`texinfmt.el\': %s" texinfmt-version)))
38 (if here
39 (insert version-string)
40 (if (interactive-p)
41 (message "%s" version-string)
42 version-string))))
43
44 \f
45 ;;; Variable definitions
46
47 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
48 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
49
50 (defvar texinfo-format-syntax-table nil)
51
52 (defvar texinfo-vindex)
53 (defvar texinfo-findex)
54 (defvar texinfo-cindex)
55 (defvar texinfo-pindex)
56 (defvar texinfo-tindex)
57 (defvar texinfo-kindex)
58 (defvar texinfo-last-node)
59 (defvar texinfo-node-names)
60 (defvar texinfo-enclosure-list)
61 (defvar texinfo-alias-list)
62
63 (defvar texinfo-command-start)
64 (defvar texinfo-command-end)
65 (defvar texinfo-command-name)
66 (defvar texinfo-defun-type)
67 (defvar texinfo-last-node-pos)
68 (defvar texinfo-stack)
69 (defvar texinfo-short-index-cmds-alist)
70 (defvar texinfo-short-index-format-cmds-alist)
71 (defvar texinfo-format-filename)
72 (defvar texinfo-footnote-number)
73 (defvar texinfo-start-of-header)
74 (defvar texinfo-end-of-header)
75 (defvar texinfo-raisesections-alist)
76 (defvar texinfo-lowersections-alist)
77 \f
78 ;;; Syntax table
79
80 (if texinfo-format-syntax-table
81 nil
82 (setq texinfo-format-syntax-table (make-syntax-table))
83 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
84 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
85 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
86 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
87 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
88 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
89 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
90 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
91 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
92 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
93 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
94
95 \f
96 ;;; Top level buffer and region formatting functions
97
98 ;;;###autoload
99 (defun texinfo-format-buffer (&optional notagify)
100 "Process the current buffer as texinfo code, into an Info file.
101 The Info file output is generated in a buffer visiting the Info file
102 name specified in the @setfilename command.
103
104 Non-nil argument (prefix, if interactive) means don't make tag table
105 and don't split the file if large. You can use Info-tagify and
106 Info-split to do these manually."
107 (interactive "P")
108 (let ((lastmessage "Formatting Info file..."))
109 (message lastmessage)
110 (texinfo-format-buffer-1)
111 (if notagify
112 nil
113 (if (> (buffer-size) 30000)
114 (progn
115 (message (setq lastmessage "Making tags table for Info file..."))
116 (Info-tagify)))
117 (if (> (buffer-size) 100000)
118 (progn
119 (message (setq lastmessage "Splitting Info file..."))
120 (Info-split))))
121 (message (concat lastmessage
122 (if (interactive-p) "done. Now save it." "done.")))))
123
124 (defvar texinfo-region-buffer-name "*Info Region*"
125 "*Name of the temporary buffer used by \\[texinfo-format-region].")
126
127 ;;;###autoload
128 (defun texinfo-format-region (region-beginning region-end)
129 "Convert the current region of the Texinfo file to Info format.
130 This lets you see what that part of the file will look like in Info.
131 The command is bound to \\[texinfo-format-region]. The text that is
132 converted to Info is stored in a temporary buffer."
133 (interactive "r")
134 (message "Converting region to Info format...")
135 (let (texinfo-command-start
136 texinfo-command-end
137 texinfo-command-name
138 texinfo-vindex
139 texinfo-findex
140 texinfo-cindex
141 texinfo-pindex
142 texinfo-tindex
143 texinfo-kindex
144 texinfo-stack
145 (texinfo-format-filename "")
146 texinfo-example-start
147 texinfo-last-node-pos
148 texinfo-last-node
149 texinfo-node-names
150 (texinfo-footnote-number 0)
151 last-input-buffer
152 (fill-column-for-info fill-column)
153 (input-buffer (current-buffer))
154 (input-directory default-directory)
155 (header-text "")
156 (header-beginning 1)
157 (header-end 1))
158
159 ;;; Copy lines between beginning and end of header lines,
160 ;;; if any, or else copy the `@setfilename' line, if any.
161 (save-excursion
162 (save-restriction
163 (widen)
164 (goto-char (point-min))
165 (let ((search-end (save-excursion (forward-line 100) (point))))
166 (if (or
167 ;; Either copy header text.
168 (and
169 (prog1
170 (search-forward tex-start-of-header search-end t)
171 (forward-line 1)
172 ;; Mark beginning of header.
173 (setq header-beginning (point)))
174 (prog1
175 (search-forward tex-end-of-header nil t)
176 (beginning-of-line)
177 ;; Mark end of header
178 (setq header-end (point))))
179 ;; Or copy @filename line.
180 (prog2
181 (goto-char (point-min))
182 (search-forward "@setfilename" search-end t)
183 (beginning-of-line)
184 (setq header-beginning (point))
185 (forward-line 1)
186 (setq header-end (point))))
187
188 ;; Copy header
189 (setq header-text
190 (buffer-substring
191 (min header-beginning region-beginning)
192 header-end))))))
193
194 ;;; Find a buffer to use.
195 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
196 (erase-buffer)
197 ;; Insert the header into the buffer.
198 (insert header-text)
199 ;; Insert the region into the buffer.
200 (insert-buffer-substring
201 input-buffer
202 (max region-beginning header-end)
203 region-end)
204 ;; Make sure region ends in a newline.
205 (or (= (preceding-char) ?\n)
206 (insert "\n"))
207
208 (goto-char (point-min))
209 (texinfo-mode)
210 (message "Converting region to Info format...")
211 (setq fill-column fill-column-for-info)
212 ;; Install a syntax table useful for scanning command operands.
213 (set-syntax-table texinfo-format-syntax-table)
214
215 ;; Insert @include files so `texinfo-raise-lower-sections' can
216 ;; work on them without losing track of multiple
217 ;; @raise/@lowersections commands.
218 (while (re-search-forward "^@include" nil t)
219 (setq texinfo-command-end (point))
220 (let ((filename (concat input-directory
221 (texinfo-parse-line-arg))))
222 (re-search-backward "^@include")
223 (delete-region (point) (save-excursion (forward-line 1) (point)))
224 (message "Reading included file: %s" filename)
225 (save-excursion
226 (save-restriction
227 (narrow-to-region
228 (point)
229 (+ (point) (car (cdr (insert-file-contents filename)))))
230 (goto-char (point-min))
231 ;; Remove `@setfilename' line from included file, if any,
232 ;; so @setfilename command not duplicated.
233 (if (re-search-forward
234 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
235 (progn
236 (beginning-of-line)
237 (delete-region
238 (point) (save-excursion (forward-line 1) (point)))))))))
239
240 ;; Raise or lower level of each section, if necessary.
241 (goto-char (point-min))
242 (texinfo-raise-lower-sections)
243 ;; Append @refill to appropriate paragraphs for filling.
244 (goto-char (point-min))
245 (texinfo-append-refill)
246 ;; If the region includes the effective end of the data,
247 ;; discard everything after that.
248 (goto-char (point-max))
249 (if (re-search-backward "^@bye" nil t)
250 (delete-region (point) (point-max)))
251 ;; Make sure buffer ends in a newline.
252 (or (= (preceding-char) ?\n)
253 (insert "\n"))
254 ;; Don't use a previous value of texinfo-enclosure-list.
255 (setq texinfo-enclosure-list nil)
256 (setq texinfo-alias-list nil)
257
258 (goto-char (point-min))
259 (if (looking-at "\\\\input[ \t]+texinfo")
260 (delete-region (point) (save-excursion (forward-line 1) (point))))
261
262 ;; Insert Info region title text.
263 (goto-char (point-min))
264 (if (search-forward
265 "@setfilename" (save-excursion (forward-line 100) (point)) t)
266 (progn
267 (setq texinfo-command-end (point))
268 (beginning-of-line)
269 (setq texinfo-command-start (point))
270 (let ((arg (texinfo-parse-arg-discard)))
271 (insert " "
272 texinfo-region-buffer-name
273 " buffer for: `")
274 (insert (file-name-nondirectory (expand-file-name arg)))
275 (insert "', -*-Text-*-\n")))
276 ;; Else no `@setfilename' line
277 (insert " "
278 texinfo-region-buffer-name
279 " buffer -*-Text-*-\n"))
280 (insert "produced by `texinfo-format-region'\n"
281 "from a region in: "
282 (if (buffer-file-name input-buffer)
283 (concat "`"
284 (file-name-sans-versions
285 (file-name-nondirectory
286 (buffer-file-name input-buffer)))
287 "'")
288 (concat "buffer `" (buffer-name input-buffer) "'"))
289 "\nusing `texinfmt.el' version "
290 texinfmt-version
291 ".\n\n")
292
293 ;; Now convert for real.
294 (goto-char (point-min))
295 (texinfo-format-scan)
296 (goto-char (point-min))
297
298 (message "Done.")))
299
300 ;;;###autoload
301 (defun texi2info (&optional notagify)
302 "Convert the current buffer (written in Texinfo code) into an Info file.
303 The Info file output is generated in a buffer visiting the Info file
304 names specified in the @setfilename command.
305
306 This function automatically updates all node pointers and menus, and
307 creates a master menu. This work is done on a temporary buffer that
308 is automatically removed when the Info file is created. The original
309 Texinfo source buffer is not changed.
310
311 Non-nil argument (prefix, if interactive) means don't make tag table
312 and don't split the file if large. You can use Info-tagify and
313 Info-split to do these manually."
314 (interactive "P")
315 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" )))
316 (message "First updating nodes and menus, then creating Info file.")
317 ;; (sit-for 2)
318 (copy-to-buffer temp-buffer (point-min) (point-max))
319 (switch-to-buffer temp-buffer)
320 (texinfo-master-menu t)
321 (message "Now creating Info file.")
322 (sit-for 2)
323 (texinfo-format-buffer notagify)
324 (save-buffer)
325 (kill-buffer temp-buffer)))
326
327 \f
328 ;;; Primary internal formatting function for the whole buffer.
329
330 (defun texinfo-format-buffer-1 ()
331 (let (texinfo-format-filename
332 texinfo-example-start
333 texinfo-command-start
334 texinfo-command-end
335 texinfo-command-name
336 texinfo-last-node
337 texinfo-last-node-pos
338 texinfo-vindex
339 texinfo-findex
340 texinfo-cindex
341 texinfo-pindex
342 texinfo-tindex
343 texinfo-kindex
344 texinfo-stack
345 texinfo-node-names
346 (texinfo-footnote-number 0)
347 last-input-buffer
348 outfile
349 (fill-column-for-info fill-column)
350 (input-buffer (current-buffer))
351 (input-directory default-directory))
352 (setq texinfo-enclosure-list nil)
353 (setq texinfo-alias-list nil)
354 (save-excursion
355 (goto-char (point-min))
356 (or (search-forward "@setfilename" nil t)
357 (error "Texinfo file needs an `@setfilename FILENAME' line."))
358 (setq texinfo-command-end (point))
359 (setq outfile (texinfo-parse-line-arg)))
360
361 (find-file outfile)
362 (texinfo-mode)
363 (erase-buffer)
364
365 (message "Formatting Info file: %s" outfile)
366 (setq texinfo-format-filename
367 (file-name-nondirectory (expand-file-name outfile)))
368
369 (setq fill-column fill-column-for-info)
370 (set-syntax-table texinfo-format-syntax-table)
371
372 (insert-buffer-substring input-buffer)
373 (message "Converting %s to Info format..." (buffer-name input-buffer))
374
375 ;; Insert @include files so `texinfo-raise-lower-sections' can
376 ;; work on them without losing track of multiple
377 ;; @raise/@lowersections commands.
378 (goto-char (point-min))
379 (while (re-search-forward "^@include" nil t)
380 (setq texinfo-command-end (point))
381 (let ((filename (concat input-directory
382 (texinfo-parse-line-arg))))
383 (re-search-backward "^@include")
384 (delete-region (point) (save-excursion (forward-line 1) (point)))
385 (message "Reading included file: %s" filename)
386 (save-excursion
387 (save-restriction
388 (narrow-to-region
389 (point)
390 (+ (point) (car (cdr (insert-file-contents filename)))))
391 (goto-char (point-min))
392 ;; Remove `@setfilename' line from included file, if any,
393 ;; so @setfilename command not duplicated.
394 (if (re-search-forward
395 "^@setfilename"
396 (save-excursion (forward-line 100) (point)) t)
397 (progn
398 (beginning-of-line)
399 (delete-region
400 (point) (save-excursion (forward-line 1) (point)))))))))
401 ;; Raise or lower level of each section, if necessary.
402 (goto-char (point-min))
403 (texinfo-raise-lower-sections)
404 ;; Append @refill to appropriate paragraphs
405 (goto-char (point-min))
406 (texinfo-append-refill)
407 (goto-char (point-min))
408 (search-forward "@setfilename")
409 (beginning-of-line)
410 (delete-region (point-min) (point))
411 ;; Remove @bye at end of file, if it is there.
412 (goto-char (point-max))
413 (if (search-backward "@bye" nil t)
414 (delete-region (point) (point-max)))
415 ;; Make sure buffer ends in a newline.
416 (or (= (preceding-char) ?\n)
417 (insert "\n"))
418 ;; Scan the whole buffer, converting to Info format.
419 (texinfo-format-scan)
420 (goto-char (point-min))
421 ;; Insert info about how this file was made.
422 (insert "Info file: "
423 texinfo-format-filename ", -*-Text-*-\n"
424 "produced by `texinfo-format-buffer'\n"
425 ;; Date string removed so that regression testing is easier.
426 ;; "on "
427 ;; (insert (format-time-string "%e %b %Y")) " "
428 "from file"
429 (if (buffer-file-name input-buffer)
430 (concat " `"
431 (file-name-sans-versions
432 (file-name-nondirectory
433 (buffer-file-name input-buffer)))
434 "'")
435 (concat "buffer `" (buffer-name input-buffer) "'"))
436 "\nusing `texinfmt.el' version "
437 texinfmt-version
438 ".\n\n")
439 ;; Return data for indices.
440 (list outfile
441 texinfo-vindex texinfo-findex texinfo-cindex
442 texinfo-pindex texinfo-tindex texinfo-kindex)))
443
444 \f
445 ;;; Perform non-@-command file conversions: quotes and hyphens
446
447 (defun texinfo-format-convert (min max)
448 ;; Convert left and right quotes to typewriter font quotes.
449 (goto-char min)
450 (while (search-forward "``" max t)
451 (replace-match "\""))
452 (goto-char min)
453 (while (search-forward "''" max t)
454 (replace-match "\""))
455 ;; Convert three hyphens in a row to two.
456 (goto-char min)
457 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
458 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
459 2)))))
460
461 \f
462 ;;; Handle paragraph filling
463
464 ;; Keep as concatinated lists for ease of maintenance
465
466 (defvar texinfo-no-refill-regexp
467 (concat
468 "^@"
469 "\\("
470 "direntry\\|"
471 "example\\|"
472 "smallexample\\|"
473 "lisp\\|"
474 "smalllisp\\|"
475 "display\\|"
476 "format\\|"
477 "flushleft\\|"
478 "flushright\\|"
479 "menu\\|"
480 "multitable\\|"
481 "titlepage\\|"
482 "iftex\\|"
483 "ifhtml\\|"
484 "tex\\|"
485 "html"
486 "\\)")
487 "Regexp specifying environments in which paragraphs are not filled.")
488
489 (defvar texinfo-accent-commands
490 (concat
491 "@^\\|"
492 "@`\\|"
493 "@'\\|"
494 "@\"\\|"
495 "@,\\|"
496 "@=\\|"
497 "@~\\|"
498 "@OE{\\|"
499 "@oe{\\|"
500 "@AA{\\|"
501 "@aa{\\|"
502 "@AE{\\|"
503 "@ae{\\|"
504 "@ss{\\|"
505 "@questiondown{\\|"
506 "@exclamdown{\\|"
507 "@L{\\|"
508 "@l{\\|"
509 "@O{\\|"
510 "@o{\\|"
511 "@dotaccent{\\|"
512 "@ubaraccent{\\|"
513 "@d{\\|"
514 "@H{\\|"
515 "@ringaccent{\\|"
516 "@tieaccent{\\|"
517 "@u{\\|"
518 "@v{\\|"
519 "@dotless{"
520 ))
521
522 (defvar texinfo-part-of-para-regexp
523 (concat
524 "^@"
525 "\\("
526 "b{\\|"
527 "bullet{\\|"
528 "cite{\\|"
529 "code{\\|"
530 "email{\\|"
531 "emph{\\|"
532 "equiv{\\|"
533 "error{\\|"
534 "expansion{\\|"
535 "file{\\|"
536 "i{\\|"
537 "inforef{\\|"
538 "kbd{\\|"
539 "key{\\|"
540 "lisp{\\|"
541 "minus{\\|"
542 "point{\\|"
543 "print{\\|"
544 "pxref{\\|"
545 "r{\\|"
546 "ref{\\|"
547 "result{\\|"
548 "samp{\\|"
549 "sc{\\|"
550 "t{\\|"
551 "TeX{\\|"
552 "today{\\|"
553 "url{\\|"
554 "var{\\|"
555 "w{\\|"
556 "xref{\\|"
557 "@-\\|" ; @- is a descretionary hyphen (not an accent) (a noop).
558 texinfo-accent-commands
559 "\\)"
560 )
561 "Regexp specifying @-commands found within paragraphs.")
562
563 (defun texinfo-append-refill ()
564 "Append @refill at end of each paragraph that should be filled.
565 Do not append @refill to paragraphs within @example and similar environments.
566 Do not append @refill to paragraphs containing @w{TEXT} or @*."
567
568 ;; It is necessary to append @refill before other processing because
569 ;; the other processing removes information that tells Texinfo
570 ;; whether the text should or should not be filled.
571
572 (while (< (point) (point-max))
573 (let ((refill-blank-lines "^[ \t\n]*$")
574 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
575 (beginning-of-line)
576 ;; 1. Skip over blank lines;
577 ;; skip over lines beginning with @-commands,
578 ;; but do not skip over lines
579 ;; that are no-refill environments such as @example or
580 ;; that begin with within-paragraph @-commands such as @code.
581 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
582 (not (looking-at
583 (concat
584 "\\("
585 texinfo-no-refill-regexp
586 "\\|"
587 texinfo-part-of-para-regexp
588 "\\)")))
589 (< (point) (point-max)))
590 (forward-line 1))
591 ;; 2. Skip over @example and similar no-refill environments.
592 (if (looking-at texinfo-no-refill-regexp)
593 (let ((environment
594 (buffer-substring (match-beginning 1) (match-end 1))))
595 (progn (re-search-forward (concat "^@end " environment) nil t)
596 (forward-line 1)))
597 ;; Else
598 ;; 3. Do not refill a paragraph containing @w or @*, or ending
599 ;; with @<newline> followed by a newline.
600 (if (or
601 (>= (point) (point-max))
602 (re-search-forward
603 "@w{\\|@\\*\\|@\n\n"
604 (save-excursion
605 (forward-paragraph)
606 (forward-line 1)
607 (point)) t))
608 ;; Go to end of paragraph and do nothing.
609 (forward-paragraph)
610 ;; 4. Else go to end of paragraph and insert @refill
611 (forward-paragraph)
612 (forward-line -1)
613 (end-of-line)
614 (delete-region
615 (point)
616 (save-excursion (skip-chars-backward " \t") (point)))
617 ;; `looking-at-backward' not available in v. 18.57
618 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
619 (if (not (re-search-backward
620 "@refill\\|@bye"
621 (save-excursion (beginning-of-line) (point))
622 t))
623 (insert "@refill"))
624 (forward-line 1))))))
625
626 \f
627 ;;; Handle `@raisesections' and `@lowersections' commands
628
629 ;; These commands change the hierarchical level of chapter structuring
630 ;; commands.
631 ;;
632 ;; @raisesections changes @subsection to @section,
633 ;; @section to @chapter,
634 ;; etc.
635 ;;
636 ;; @lowersections changes @chapter to @section
637 ;; @subsection to @subsubsection,
638 ;; etc.
639 ;;
640 ;; An @raisesections/@lowersections command changes only those
641 ;; structuring commands that follow the @raisesections/@lowersections
642 ;; command.
643 ;;
644 ;; Repeated @raisesections/@lowersections continue to raise or lower
645 ;; the heading level.
646 ;;
647 ;; An @lowersections command cancels an @raisesections command, and
648 ;; vice versa.
649 ;;
650 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
651 ;; trying to do so does not elicit an error---you just get more
652 ;; headings that mean the same thing as you keep raising or lowering
653 ;; (for example, after a single @raisesections, both @chapter and
654 ;; @section produce chapter headings).
655
656 (defun texinfo-raise-lower-sections ()
657 "Raise or lower the hierarchical level of chapters, sections, etc.
658
659 This function acts according to `@raisesections' and `@lowersections'
660 commands in the Texinfo file.
661
662 For example, an `@lowersections' command is useful if you wish to
663 include what is written as an outer or standalone Texinfo file in
664 another Texinfo file as an inner, included file. The `@lowersections'
665 command changes chapters to sections, sections to subsections and so
666 on.
667
668 @raisesections changes @subsection to @section,
669 @section to @chapter,
670 @heading to @chapheading,
671 etc.
672
673 @lowersections changes @chapter to @section,
674 @subsection to @subsubsection,
675 @heading to @subheading,
676 etc.
677
678 An `@raisesections' or `@lowersections' command changes only those
679 structuring commands that follow the `@raisesections' or
680 `@lowersections' command.
681
682 An `@lowersections' command cancels an `@raisesections' command, and
683 vice versa.
684
685 Repeated use of the commands continue to raise or lower the hierarchical
686 level a step at a time.
687
688 An attempt to raise above `chapters' reproduces chapter commands; an
689 attempt to lower below subsubsections reproduces subsubsection
690 commands."
691
692 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
693 ;; it is a regexp matching chapter, section, other headings
694 ;; (but not the top node).
695
696 (let (type (level 0))
697 (while
698 (re-search-forward
699 (concat
700 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
701 texinfo-section-types-regexp
702 "\\)\\)")
703 nil t)
704 (beginning-of-line)
705 (save-excursion (setq type (read (current-buffer))))
706 (cond
707
708 ;; 1. Increment level
709 ((eq type '@raisesections)
710 (setq level (1+ level))
711 (delete-region
712 (point) (save-excursion (forward-line 1) (point))))
713
714 ;; 2. Decrement level
715 ((eq type '@lowersections)
716 (setq level (1- level))
717 (delete-region
718 (point) (save-excursion (forward-line 1) (point))))
719
720 ;; Now handle structuring commands
721 ((cond
722
723 ;; 3. Raise level when positive
724 ((> level 0)
725 (let ((count level)
726 (new-level type))
727 (while (> count 0)
728 (setq new-level
729 (cdr (assq new-level texinfo-raisesections-alist)))
730 (setq count (1- count)))
731 (kill-word 1)
732 (insert (symbol-name new-level))))
733
734 ;; 4. Do nothing except move point when level is zero
735 ((= level 0) (forward-line 1))
736
737 ;; 5. Lower level when positive
738 ((< level 0)
739 (let ((count level)
740 (new-level type))
741 (while (< count 0)
742 (setq new-level
743 (cdr (assq new-level texinfo-lowersections-alist)))
744 (setq count (1+ count)))
745 (kill-word 1)
746 (insert (symbol-name new-level))))))))))
747
748 (defvar texinfo-raisesections-alist
749 '((@chapter . @chapter) ; Cannot go higher
750 (@unnumbered . @unnumbered)
751 (@centerchap . @unnumbered)
752
753 (@majorheading . @majorheading)
754 (@chapheading . @chapheading)
755 (@appendix . @appendix)
756
757 (@section . @chapter)
758 (@unnumberedsec . @unnumbered)
759 (@heading . @chapheading)
760 (@appendixsec . @appendix)
761
762 (@subsection . @section)
763 (@unnumberedsubsec . @unnumberedsec)
764 (@subheading . @heading)
765 (@appendixsubsec . @appendixsec)
766
767 (@subsubsection . @subsection)
768 (@unnumberedsubsubsec . @unnumberedsubsec)
769 (@subsubheading . @subheading)
770 (@appendixsubsubsec . @appendixsubsec))
771 "*An alist of next higher levels for chapters, sections. etc.
772 For example, section to chapter, subsection to section.
773 Used by `texinfo-raise-lower-sections'.
774 The keys specify types of section; the values correspond to the next
775 higher types.")
776
777 (defvar texinfo-lowersections-alist
778 '((@chapter . @section)
779 (@unnumbered . @unnumberedsec)
780 (@centerchap . @unnumberedsec)
781 (@majorheading . @heading)
782 (@chapheading . @heading)
783 (@appendix . @appendixsec)
784
785 (@section . @subsection)
786 (@unnumberedsec . @unnumberedsubsec)
787 (@heading . @subheading)
788 (@appendixsec . @appendixsubsec)
789
790 (@subsection . @subsubsection)
791 (@unnumberedsubsec . @unnumberedsubsubsec)
792 (@subheading . @subsubheading)
793 (@appendixsubsec . @appendixsubsubsec)
794
795 (@subsubsection . @subsubsection) ; Cannot go lower.
796 (@unnumberedsubsubsec . @unnumberedsubsubsec)
797 (@subsubheading . @subsubheading)
798 (@appendixsubsubsec . @appendixsubsubsec))
799 "*An alist of next lower levels for chapters, sections. etc.
800 For example, chapter to section, section to subsection.
801 Used by `texinfo-raise-lower-sections'.
802 The keys specify types of section; the values correspond to the next
803 lower types.")
804
805 \f
806 ;;; Perform those texinfo-to-info conversions that apply to the whole input
807 ;;; uniformly.
808
809 (defun texinfo-format-scan ()
810 (texinfo-format-convert (point-min) (point-max))
811 ;; Scan for @-commands.
812 (goto-char (point-min))
813 (while (search-forward "@" nil t)
814 ;;
815 ;; These are the single-character accent commands: @^ @` @' @" @= @~
816 ;; In Info, they are simply quoted and the @ deleted.
817 ;; Other single-character commands:
818 ;; @* forces a line break,
819 ;; @- is a discretionary hyphenation point; does nothing in Info.
820 ;; @<space>, @<tab>, @<newline> each produce a single space,
821 ;; unless followed by a newline.
822 ;;
823 ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]")
824 (if (looking-at "[@{}^'`\"=~ \t\n*?!-]")
825 ;; @*, causes a line break.
826 (cond
827 ;; @*, a line break
828 ((= (following-char) ?*)
829 ;; remove command
830 (delete-region (1- (point)) (1+ (point)))
831 ;; insert return if not at end of line;
832 ;; else line is already broken.
833 (if (not (= (following-char) ?\n))
834 (insert ?\n)))
835 ;; @-, deleted
836 ((= (following-char) ?-)
837 (delete-region (1- (point)) (1+ (point))))
838 ;; @<space>, @<tab>, @<newline>: produce a single space,
839 ;; unless followed by a newline.
840 ((= (following-char) ? )
841 (delete-region (1- (point)) (1+ (point)))
842 ;; insert single space if not at end of line;
843 ;; else line is already broken.
844 (if (not (= (following-char) ?\n))
845 (insert ? )))
846 ((= (following-char) ?\t)
847 (delete-region (1- (point)) (1+ (point)))
848 ;; insert single space if not at end of line;
849 ;; else line is already broken.
850 (if (not (= (following-char) ?\n))
851 (insert ? )))
852 ;; following char is a carriage return
853 ((= (following-char) ?
854 )
855 ;; remove command
856 (delete-region (1- (point)) (1+ (point)))
857 ;; insert single space if not at end of line;
858 ;; else line is already broken.
859 (if (not (= (following-char) ?\n))
860 (insert ? )))
861 ;; Otherwise: the other characters are simply quoted. Delete the @.
862 (t
863 (delete-char -1)
864 (forward-char 1)))
865 ;; @ is followed by a command-word; find the end of the word.
866 (setq texinfo-command-start (1- (point)))
867 (if (= (char-syntax (following-char)) ?w)
868 (forward-word 1)
869 (forward-char 1))
870 (setq texinfo-command-end (point))
871 ;; Handle let aliasing
872 (setq texinfo-command-name
873 (let (trial
874 (cmdname
875 (buffer-substring
876 (1+ texinfo-command-start) texinfo-command-end)))
877 (while (setq trial (assoc cmdname texinfo-alias-list))
878 (setq cmdname (cdr trial)))
879 (intern cmdname)))
880 ;; Call the handler for this command.
881 (let ((enclosure-type
882 (assoc
883 (symbol-name texinfo-command-name)
884 texinfo-enclosure-list)))
885 (if enclosure-type
886 (progn
887 (insert
888 (car (car (cdr enclosure-type)))
889 (texinfo-parse-arg-discard)
890 (car (cdr (car (cdr enclosure-type)))))
891 (goto-char texinfo-command-start))
892 (let ((cmd (get texinfo-command-name 'texinfo-format)))
893 (if cmd (funcall cmd) (texinfo-unsupported)))))))
894
895 (cond (texinfo-stack
896 (goto-char (nth 2 (car texinfo-stack)))
897 (error "Unterminated @%s" (car (car texinfo-stack))))))
898
899 (put 'begin 'texinfo-format 'texinfo-format-begin)
900 (defun texinfo-format-begin ()
901 (texinfo-format-begin-end 'texinfo-format))
902
903 (put 'end 'texinfo-format 'texinfo-format-end)
904 (defun texinfo-format-end ()
905 (texinfo-format-begin-end 'texinfo-end))
906
907 (defun texinfo-format-begin-end (prop)
908 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
909 (let ((cmd (get texinfo-command-name prop)))
910 (if cmd (funcall cmd)
911 (texinfo-unsupported))))
912 \f
913 ;;; Parsing functions
914
915 (defun texinfo-parse-line-arg ()
916 "Return argument of @-command as string.
917 Argument is separated from command either by a space or by a brace.
918 If a space, return rest of line, with beginning and ending white
919 space removed. If a brace, return string between braces.
920 Leave point after argument."
921 (goto-char texinfo-command-end)
922 (let ((start (point)))
923 (cond ((looking-at " ")
924 (skip-chars-forward " ")
925 (setq start (point))
926 (end-of-line)
927 (skip-chars-backward " ")
928 (delete-region (point) (progn (end-of-line) (point)))
929 (setq texinfo-command-end (1+ (point))))
930 ((looking-at "{")
931 (setq start (1+ (point)))
932 (forward-list 1)
933 (setq texinfo-command-end (point))
934 (forward-char -1))
935 (t
936 (error "Invalid texinfo command arg format")))
937 (prog1 (buffer-substring start (point))
938 (if (eolp) (forward-char 1)))))
939
940 (defun texinfo-parse-expanded-arg ()
941 (goto-char texinfo-command-end)
942 (let ((start (point))
943 marker)
944 (cond ((looking-at " ")
945 (skip-chars-forward " ")
946 (setq start (point))
947 (end-of-line)
948 (setq texinfo-command-end (1+ (point))))
949 ((looking-at "{")
950 (setq start (1+ (point)))
951 (forward-list 1)
952 (setq texinfo-command-end (point))
953 (forward-char -1))
954 (t
955 (error "Invalid texinfo command arg format")))
956 (setq marker (move-marker (make-marker) texinfo-command-end))
957 (texinfo-format-expand-region start (point))
958 (setq texinfo-command-end (marker-position marker))
959 (move-marker marker nil)
960 (prog1 (buffer-substring start (point))
961 (if (eolp) (forward-char 1)))))
962
963 (defun texinfo-format-expand-region (start end)
964 (save-restriction
965 (narrow-to-region start end)
966 (let (texinfo-command-start
967 texinfo-command-end
968 texinfo-command-name
969 texinfo-stack)
970 (texinfo-format-scan))
971 (goto-char (point-max))))
972
973 (defun texinfo-parse-arg-discard ()
974 "Delete command and argument; return argument of command."
975 (prog1 (texinfo-parse-line-arg)
976 (texinfo-discard-command)))
977
978 (defun texinfo-discard-command ()
979 (delete-region texinfo-command-start texinfo-command-end))
980
981 (defun texinfo-optional-braces-discard ()
982 "Discard braces following command, if any."
983 (goto-char texinfo-command-end)
984 (let ((start (point)))
985 (cond ((looking-at "[ \t]*\n")) ; do nothing
986 ((looking-at "{") ; remove braces, if any
987 (forward-list 1)
988 (setq texinfo-command-end (point)))
989 (t
990 (error
991 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
992 (delete-region texinfo-command-start texinfo-command-end)))
993
994 (defun texinfo-format-parse-line-args ()
995 (let ((start (1- (point)))
996 next beg end
997 args)
998 (skip-chars-forward " ")
999 (while (not (eolp))
1000 (setq beg (point))
1001 (re-search-forward "[\n,]")
1002 (setq next (point))
1003 (if (bolp) (setq next (1- next)))
1004 (forward-char -1)
1005 (skip-chars-backward " ")
1006 (setq end (point))
1007 (setq args (cons (if (> end beg) (buffer-substring beg end))
1008 args))
1009 (goto-char next)
1010 (skip-chars-forward " "))
1011 (if (eolp) (forward-char 1))
1012 (setq texinfo-command-end (point))
1013 (nreverse args)))
1014
1015 (defun texinfo-format-parse-args ()
1016 (let ((start (1- (point)))
1017 next beg end
1018 args)
1019 (search-forward "{")
1020 (save-excursion
1021 (texinfo-format-expand-region
1022 (point)
1023 (save-excursion (up-list 1) (1- (point)))))
1024 ;; The following does not handle cross references of the form:
1025 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1026 ;; re-search-forward finds the first right brace after the second
1027 ;; comma.
1028 (while (/= (preceding-char) ?\})
1029 (skip-chars-forward " \t\n")
1030 (setq beg (point))
1031 (re-search-forward "[},]")
1032 (setq next (point))
1033 (forward-char -1)
1034 (skip-chars-backward " \t\n")
1035 (setq end (point))
1036 (cond ((< beg end)
1037 (goto-char beg)
1038 (while (search-forward "\n" end t)
1039 (replace-match " "))))
1040 (setq args (cons (if (> end beg) (buffer-substring beg end))
1041 args))
1042 (goto-char next))
1043 (if (eolp) (forward-char 1))
1044 (setq texinfo-command-end (point))
1045 (nreverse args)))
1046
1047 (defun texinfo-format-parse-defun-args ()
1048 (goto-char texinfo-command-end)
1049 (let ((start (point)))
1050 (end-of-line)
1051 (setq texinfo-command-end (1+ (point)))
1052 (let ((marker (move-marker (make-marker) texinfo-command-end)))
1053 (texinfo-format-expand-region start (point))
1054 (setq texinfo-command-end (marker-position marker))
1055 (move-marker marker nil))
1056 (goto-char start)
1057 (let ((args '())
1058 beg end)
1059 (skip-chars-forward " ")
1060 (while (not (eolp))
1061 (cond ((looking-at "{")
1062 (setq beg (1+ (point)))
1063 (forward-list 1)
1064 (setq end (1- (point))))
1065 (t
1066 (setq beg (point))
1067 (re-search-forward "[\n ]")
1068 (forward-char -1)
1069 (setq end (point))))
1070 (setq args (cons (buffer-substring beg end) args))
1071 (skip-chars-forward " "))
1072 (forward-char 1)
1073 (nreverse args))))
1074
1075 (defun texinfo-discard-line ()
1076 (goto-char texinfo-command-end)
1077 (skip-chars-forward " \t")
1078 (or (eolp)
1079 (error "Extraneous text at end of command line."))
1080 (goto-char texinfo-command-start)
1081 (or (bolp)
1082 (error "Extraneous text at beginning of command line."))
1083 (delete-region (point) (progn (forward-line 1) (point))))
1084
1085 (defun texinfo-discard-line-with-args ()
1086 (goto-char texinfo-command-start)
1087 (delete-region (point) (progn (forward-line 1) (point))))
1088
1089 \f
1090 ;;; @setfilename
1091
1092 ;; Only `texinfo-format-buffer' handles @setfilename with this
1093 ;; definition; `texinfo-format-region' handles @setfilename, if any,
1094 ;; specially.
1095 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
1096 (defun texinfo-format-setfilename ()
1097 (texinfo-parse-arg-discard))
1098 \f
1099 ;;; @node, @menu, @detailmenu
1100
1101 (put 'node 'texinfo-format 'texinfo-format-node)
1102 (put 'nwnode 'texinfo-format 'texinfo-format-node)
1103 (defun texinfo-format-node ()
1104 (let* ((args (texinfo-format-parse-line-args))
1105 (name (nth 0 args))
1106 (next (nth 1 args))
1107 (prev (nth 2 args))
1108 (up (nth 3 args)))
1109 (texinfo-discard-command)
1110 (setq texinfo-last-node name)
1111 (let ((tem (downcase name)))
1112 (if (assoc tem texinfo-node-names)
1113 (error "Duplicate node name: %s" name)
1114 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
1115 (setq texinfo-footnote-number 0)
1116 ;; insert "\n\^_" unconditionally since this is what info is looking for
1117 (insert "\n\^_\nFile: " texinfo-format-filename
1118 ", Node: " name)
1119 (if next
1120 (insert ", Next: " next))
1121 (if prev
1122 (insert ", Prev: " prev))
1123 (if up
1124 (insert ", Up: " up))
1125 (insert ?\n)
1126 (setq texinfo-last-node-pos (point))))
1127
1128 (put 'menu 'texinfo-format 'texinfo-format-menu)
1129 (defun texinfo-format-menu ()
1130 (texinfo-discard-line)
1131 (insert "* Menu:\n\n"))
1132
1133 (put 'menu 'texinfo-end 'texinfo-discard-command)
1134
1135 ;; The @detailmenu should be removed eventually.
1136
1137 ;; According to Karl Berry, 31 August 1996:
1138 ;;
1139 ;; You don't like, I don't like it. I agree, it would be better just to
1140 ;; fix the bug [in `makeinfo']. .. At this point, since inserting those
1141 ;; two commands in the Elisp fn is trivial, I don't especially want to
1142 ;; expend more effort...
1143 ;;
1144 ;; I added a couple sentences of documentation to the manual (putting the
1145 ;; blame on makeinfo where it belongs :-().
1146
1147 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
1148 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
1149
1150 ;; (Also see `texnfo-upd.el')
1151
1152 \f
1153 ;;; Cross references
1154
1155 ;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
1156 ;; -> *Note FNAME: (FILE)NODE
1157 ;; If FILE is missing,
1158 ;; *Note FNAME: NODE
1159 ;; If FNAME is empty and NAME is present
1160 ;; *Note NAME: Node
1161 ;; If both NAME and FNAME are missing
1162 ;; *Note NODE::
1163 ;; texinfo ignores the DOCUMENT argument.
1164 ;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1165 ;; If FILE is specified, (FILE)NODE is used for xrefs.
1166 ;; If fifth argument DOCUMENT is specified, produces
1167 ;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1168 ;; of DOCUMENT
1169
1170 ;; @ref a reference that does not put `See' or `see' in
1171 ;; the hardcopy and is the same as @xref in Info
1172 (put 'ref 'texinfo-format 'texinfo-format-xref)
1173
1174 (put 'xref 'texinfo-format 'texinfo-format-xref)
1175 (defun texinfo-format-xref ()
1176 (let ((args (texinfo-format-parse-args)))
1177 (texinfo-discard-command)
1178 (insert "*Note ")
1179 (let ((fname (or (nth 1 args) (nth 2 args))))
1180 (if (null (or fname (nth 3 args)))
1181 (insert (car args) "::")
1182 (insert (or fname (car args)) ": ")
1183 (if (nth 3 args)
1184 (insert "(" (nth 3 args) ")"))
1185 (insert (car args))))))
1186
1187 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
1188 (defun texinfo-format-pxref ()
1189 (texinfo-format-xref)
1190 (or (save-excursion
1191 (forward-char -2)
1192 (looking-at "::"))
1193 (insert ".")))
1194
1195 ;; @inforef{NODE, FNAME, FILE}
1196 ;; Like @xref{NODE, FNAME,,FILE} in texinfo.
1197 ;; In Tex, generates "See Info file FILE, node NODE"
1198 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
1199 (defun texinfo-format-inforef ()
1200 (let ((args (texinfo-format-parse-args)))
1201 (texinfo-discard-command)
1202 (if (nth 1 args)
1203 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
1204 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
1205
1206 \f
1207 ;;; Section headings
1208
1209 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1210 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1211 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1212 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1213 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1214 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1215 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1216 (put 'top 'texinfo-format 'texinfo-format-chapter)
1217 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1218 (put 'centerchap 'texinfo-format 'texinfo-format-chapter)
1219 (defun texinfo-format-chapter ()
1220 (texinfo-format-chapter-1 ?*))
1221
1222 (put 'heading 'texinfo-format 'texinfo-format-section)
1223 (put 'isection 'texinfo-format 'texinfo-format-section)
1224 (put 'section 'texinfo-format 'texinfo-format-section)
1225 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1226 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1227 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1228 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1229 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1230 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1231 (defun texinfo-format-section ()
1232 (texinfo-format-chapter-1 ?=))
1233
1234 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1235 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1236 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1237 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1238 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1239 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1240 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1241 (defun texinfo-format-subsection ()
1242 (texinfo-format-chapter-1 ?-))
1243
1244 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1245 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1246 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1247 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1248 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1249 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1250 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1251 (defun texinfo-format-subsubsection ()
1252 (texinfo-format-chapter-1 ?.))
1253
1254 (defun texinfo-format-chapter-1 (belowchar)
1255 (let ((arg (texinfo-parse-arg-discard)))
1256 (message "Formatting: %s ... " arg) ; So we can see where we are.
1257 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1258 (forward-line -2)))
1259
1260 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1261 (defun texinfo-format-sectionpad ()
1262 (let ((str (texinfo-parse-arg-discard)))
1263 (forward-char -1)
1264 (let ((column (current-column)))
1265 (forward-char 1)
1266 (while (> column 0)
1267 (insert str)
1268 (setq column (1- column))))
1269 (insert ?\n)))
1270
1271 \f
1272 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1273
1274 (put '\. 'texinfo-format 'texinfo-format-\.)
1275 (defun texinfo-format-\. ()
1276 (texinfo-discard-command)
1277 (insert "."))
1278
1279 (put '\: 'texinfo-format 'texinfo-format-\:)
1280 (defun texinfo-format-\: ()
1281 (texinfo-discard-command))
1282
1283 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1284 (defun texinfo-format-soft-hyphen ()
1285 (texinfo-discard-command))
1286
1287 \f
1288 ;;; @center, @sp, and @br
1289
1290 (put 'center 'texinfo-format 'texinfo-format-center)
1291 (defun texinfo-format-center ()
1292 (let ((arg (texinfo-parse-expanded-arg)))
1293 (texinfo-discard-command)
1294 (insert arg)
1295 (insert ?\n)
1296 (save-restriction
1297 (goto-char (1- (point)))
1298 (let ((indent-tabs-mode nil))
1299 (center-line)))))
1300
1301 (put 'sp 'texinfo-format 'texinfo-format-sp)
1302 (defun texinfo-format-sp ()
1303 (let* ((arg (texinfo-parse-arg-discard))
1304 (num (read arg)))
1305 (insert-char ?\n num)))
1306
1307 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1308 (defun texinfo-format-paragraph-break ()
1309 "Force a paragraph break.
1310 If used within a line, follow `@br' with braces."
1311 (texinfo-optional-braces-discard)
1312 ;; insert one return if at end of line;
1313 ;; else insert two returns, to generate a blank line.
1314 (if (= (following-char) ?\n)
1315 (insert ?\n)
1316 (insert-char ?\n 2)))
1317
1318 \f
1319 ;;; @footnote and @footnotestyle
1320
1321 ;; In Texinfo, footnotes are created with the `@footnote' command.
1322 ;; This command is followed immediately by a left brace, then by the text of
1323 ;; the footnote, and then by a terminating right brace. The
1324 ;; template for a footnote is:
1325 ;;
1326 ;; @footnote{TEXT}
1327 ;;
1328 ;; Info has two footnote styles:
1329 ;;
1330 ;; * In the End of node style, all the footnotes for a single node
1331 ;; are placed at the end of that node. The footnotes are
1332 ;; separated from the rest of the node by a line of dashes with
1333 ;; the word `Footnotes' within it.
1334 ;;
1335 ;; * In the Separate node style, all the footnotes for a single node
1336 ;; are placed in an automatically constructed node of their own.
1337
1338 ;; Footnote style is specified by the @footnotestyle command, either
1339 ;; @footnotestyle separate
1340 ;; or
1341 ;; @footnotestyle end
1342 ;;
1343 ;; The default is separate
1344
1345 (defvar texinfo-footnote-style "separate"
1346 "Footnote style, either separate or end.")
1347
1348 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1349 (defun texinfo-footnotestyle ()
1350 "Specify whether footnotes are at end of node or in separate nodes.
1351 Argument is either end or separate."
1352 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1353
1354 (defvar texinfo-footnote-number)
1355
1356 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1357 (defun texinfo-format-footnote ()
1358 "Format a footnote in either end of node or separate node style.
1359 The texinfo-footnote-style variable controls which style is used."
1360 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1361 (cond ((string= texinfo-footnote-style "end")
1362 (texinfo-format-end-node))
1363 ((string= texinfo-footnote-style "separate")
1364 (texinfo-format-separate-node))))
1365
1366 (defun texinfo-format-separate-node ()
1367 "Format footnote in Separate node style, with notes in own node.
1368 The node is constructed automatically."
1369 (let* (start
1370 (arg (texinfo-parse-line-arg))
1371 (node-name-beginning
1372 (save-excursion
1373 (re-search-backward
1374 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1375 (match-end 0)))
1376 (node-name
1377 (save-excursion
1378 (buffer-substring
1379 (progn (goto-char node-name-beginning) ; skip over node command
1380 (skip-chars-forward " \t") ; and over spaces
1381 (point))
1382 (if (search-forward
1383 ","
1384 (save-excursion (end-of-line) (point)) t) ; bound search
1385 (1- (point))
1386 (end-of-line) (point))))))
1387 (texinfo-discard-command) ; remove or insert whitespace, as needed
1388 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1389 (point))
1390 (insert (format " (%d) (*Note %s-Footnotes::)"
1391 texinfo-footnote-number node-name))
1392 (fill-paragraph nil)
1393 (save-excursion
1394 (if (re-search-forward "^@node" nil 'move)
1395 (forward-line -1))
1396
1397 ;; two cases: for the first footnote, we must insert a node header;
1398 ;; for the second and subsequent footnotes, we need only insert
1399 ;; the text of the footnote.
1400
1401 (if (save-excursion
1402 (re-search-backward
1403 (concat node-name "-Footnotes, Up: ")
1404 node-name-beginning
1405 t))
1406 (progn ; already at least one footnote
1407 (setq start (point))
1408 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1409 (fill-region start (point)))
1410 ;; else not yet a footnote
1411 (insert "\n\^_\nFile: " texinfo-format-filename
1412 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1413 (setq start (point))
1414 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1415 (fill-region start (point))))))
1416
1417 (defun texinfo-format-end-node ()
1418 "Format footnote in the End of node style, with notes at end of node."
1419 (let (start
1420 (arg (texinfo-parse-line-arg)))
1421 (texinfo-discard-command) ; remove or insert whitespace, as needed
1422 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1423 (point))
1424 (insert (format " (%d) " texinfo-footnote-number))
1425 (fill-paragraph nil)
1426 (save-excursion
1427 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1428 (progn ; already have footnote, put new one before end of node
1429 (if (re-search-forward "^@node" nil 'move)
1430 (forward-line -1))
1431 (setq start (point))
1432 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1433 (fill-region start (point)))
1434 ;; else no prior footnote
1435 (if (re-search-forward "^@node" nil 'move)
1436 (forward-line -1))
1437 (insert "\n--------- Footnotes ---------\n")
1438 (setq start (point))
1439 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1440
1441 \f
1442 ;;; @itemize, @enumerate, and similar commands
1443
1444 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1445 ;; @enumerate pushes (enumerate 0 STARTPOS).
1446 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1447 ;; For itemize, this puts in and rescans the COMMANDS.
1448 ;; For enumerate, this increments the number and puts it in.
1449 ;; In either case, it puts a Backspace at the front of the line
1450 ;; which marks it not to be indented later.
1451 ;; All other lines get indented by 5 when the @end is reached.
1452
1453 (defvar texinfo-stack-depth 0
1454 "Count of number of unpopped texinfo-push-stack calls.
1455 Used by @refill indenting command to avoid indenting within lists, etc.")
1456
1457 (defun texinfo-push-stack (check arg)
1458 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1459 (setq texinfo-stack
1460 (cons (list check arg texinfo-command-start)
1461 texinfo-stack)))
1462
1463 (defun texinfo-pop-stack (check)
1464 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1465 (if (null texinfo-stack)
1466 (error "Unmatched @end %s" check))
1467 (if (not (eq (car (car texinfo-stack)) check))
1468 (error "@end %s matches @%s"
1469 check (car (car texinfo-stack))))
1470 (prog1 (cdr (car texinfo-stack))
1471 (setq texinfo-stack (cdr texinfo-stack))))
1472
1473 (put 'itemize 'texinfo-format 'texinfo-itemize)
1474 (defun texinfo-itemize ()
1475 (texinfo-push-stack
1476 'itemize
1477 (progn (skip-chars-forward " \t")
1478 (if (eolp)
1479 "@bullet"
1480 (texinfo-parse-line-arg))))
1481 (texinfo-discard-line-with-args)
1482 (setq fill-column (- fill-column 5)))
1483
1484 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1485 (defun texinfo-end-itemize ()
1486 (setq fill-column (+ fill-column 5))
1487 (texinfo-discard-command)
1488 (let ((stacktop
1489 (texinfo-pop-stack 'itemize)))
1490 (texinfo-do-itemize (nth 1 stacktop))))
1491
1492 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1493 (defun texinfo-enumerate ()
1494 (texinfo-push-stack
1495 'enumerate
1496 (progn (skip-chars-forward " \t")
1497 (if (eolp)
1498 1
1499 (read (current-buffer)))))
1500 (if (and (symbolp (car (cdr (car texinfo-stack))))
1501 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1502 (error
1503 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1504 (texinfo-discard-line-with-args)
1505 (setq fill-column (- fill-column 5)))
1506
1507 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1508 (defun texinfo-end-enumerate ()
1509 (setq fill-column (+ fill-column 5))
1510 (texinfo-discard-command)
1511 (let ((stacktop
1512 (texinfo-pop-stack 'enumerate)))
1513 (texinfo-do-itemize (nth 1 stacktop))))
1514
1515 ;; @alphaenumerate never became a standard part of Texinfo
1516 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1517 (defun texinfo-alphaenumerate ()
1518 (texinfo-push-stack 'alphaenumerate (1- ?a))
1519 (setq fill-column (- fill-column 5))
1520 (texinfo-discard-line))
1521
1522 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1523 (defun texinfo-end-alphaenumerate ()
1524 (setq fill-column (+ fill-column 5))
1525 (texinfo-discard-command)
1526 (let ((stacktop
1527 (texinfo-pop-stack 'alphaenumerate)))
1528 (texinfo-do-itemize (nth 1 stacktop))))
1529
1530 ;; @capsenumerate never became a standard part of Texinfo
1531 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1532 (defun texinfo-capsenumerate ()
1533 (texinfo-push-stack 'capsenumerate (1- ?A))
1534 (setq fill-column (- fill-column 5))
1535 (texinfo-discard-line))
1536
1537 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1538 (defun texinfo-end-capsenumerate ()
1539 (setq fill-column (+ fill-column 5))
1540 (texinfo-discard-command)
1541 (let ((stacktop
1542 (texinfo-pop-stack 'capsenumerate)))
1543 (texinfo-do-itemize (nth 1 stacktop))))
1544
1545 ;; At the @end, indent all the lines within the construct
1546 ;; except those marked with backspace. FROM says where
1547 ;; construct started.
1548 (defun texinfo-do-itemize (from)
1549 (save-excursion
1550 (while (progn (forward-line -1)
1551 (>= (point) from))
1552 (if (= (following-char) ?\b)
1553 (save-excursion
1554 (delete-char 1)
1555 (end-of-line)
1556 (delete-char 6))
1557 (if (not (looking-at "[ \t]*$"))
1558 (save-excursion (insert " ")))))))
1559
1560 (put 'item 'texinfo-format 'texinfo-item)
1561 (put 'itemx 'texinfo-format 'texinfo-item)
1562 (defun texinfo-item ()
1563 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1564
1565 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1566 (defun texinfo-itemize-item ()
1567 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1568 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1569 (if (looking-at "[ \t]*[^ \t\n]+")
1570 ;; Text on same line as @item command.
1571 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1572 ;; Else text on next line.
1573 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1574 (forward-line -1))
1575
1576 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1577 (defun texinfo-enumerate-item ()
1578 (texinfo-discard-line)
1579 (let (enumerating-symbol)
1580 (cond ((integerp (car (cdr (car texinfo-stack))))
1581 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1582 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1583 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1584 ((symbolp (car (cdr (car texinfo-stack))))
1585 (setq enumerating-symbol
1586 (symbol-name (car (cdr (car texinfo-stack)))))
1587 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1588 (equal ?\{ (string-to-char enumerating-symbol)))
1589 (error
1590 "Too many items in enumerated list; alphabet ends at Z."))
1591 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1592 (setcar (cdr (car texinfo-stack))
1593 (make-symbol
1594 (char-to-string
1595 (1+
1596 (string-to-char enumerating-symbol))))))
1597 (t
1598 (error
1599 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1600 (forward-line -1)))
1601
1602 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1603 (defun texinfo-alphaenumerate-item ()
1604 (texinfo-discard-line)
1605 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1606 (if (> next ?z)
1607 (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
1608 (setcar (cdr (car texinfo-stack)) next)
1609 (insert "\b " next ". \n"))
1610 (forward-line -1))
1611
1612 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1613 (defun texinfo-capsenumerate-item ()
1614 (texinfo-discard-line)
1615 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1616 (if (> next ?Z)
1617 (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
1618 (setcar (cdr (car texinfo-stack)) next)
1619 (insert "\b " next ". \n"))
1620 (forward-line -1))
1621
1622 \f
1623 ;;; @table
1624
1625 ;; The `@table' command produces two-column tables.
1626
1627 (put 'table 'texinfo-format 'texinfo-table)
1628 (defun texinfo-table ()
1629 (texinfo-push-stack
1630 'table
1631 (progn (skip-chars-forward " \t")
1632 (if (eolp)
1633 "@asis"
1634 (texinfo-parse-line-arg))))
1635 (texinfo-discard-line-with-args)
1636 (setq fill-column (- fill-column 5)))
1637
1638 (put 'table 'texinfo-item 'texinfo-table-item)
1639 (defun texinfo-table-item ()
1640 (let ((arg (texinfo-parse-arg-discard))
1641 (itemfont (car (cdr (car texinfo-stack)))))
1642 (insert ?\b itemfont ?\{ arg "}\n \n"))
1643 (forward-line -2))
1644
1645 (put 'table 'texinfo-end 'texinfo-end-table)
1646 (defun texinfo-end-table ()
1647 (setq fill-column (+ fill-column 5))
1648 (texinfo-discard-command)
1649 (let ((stacktop
1650 (texinfo-pop-stack 'table)))
1651 (texinfo-do-itemize (nth 1 stacktop))))
1652
1653 ;; @description appears to be an undocumented variant on @table that
1654 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1655 ;; part of makeinfo.c The command appears to be a relic of the past.
1656 (put 'description 'texinfo-end 'texinfo-end-table)
1657 (put 'description 'texinfo-format 'texinfo-description)
1658 (defun texinfo-description ()
1659 (texinfo-push-stack 'table "@asis")
1660 (setq fill-column (- fill-column 5))
1661 (texinfo-discard-line))
1662
1663 \f
1664 ;;; @ftable, @vtable
1665
1666 ;; The `@ftable' and `@vtable' commands are like the `@table' command
1667 ;; but they also insert each entry in the first column of the table
1668 ;; into the function or variable index.
1669
1670 ;; Handle the @ftable and @vtable commands:
1671
1672 (put 'ftable 'texinfo-format 'texinfo-ftable)
1673 (put 'vtable 'texinfo-format 'texinfo-vtable)
1674
1675 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1676 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1677
1678 (defun texinfo-indextable (table-type)
1679 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1680 (setq fill-column (- fill-column 5)))
1681
1682 ;; Handle the @item commands within ftable and vtable:
1683
1684 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1685 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1686
1687 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1688 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1689
1690 (defun texinfo-indextable-item (index-type)
1691 (let ((item (texinfo-parse-arg-discard))
1692 (itemfont (car (cdr (car texinfo-stack))))
1693 (indexvar index-type))
1694 (insert ?\b itemfont ?\{ item "}\n \n")
1695 (set indexvar
1696 (cons
1697 (list item texinfo-last-node)
1698 (symbol-value indexvar)))
1699 (forward-line -2)))
1700
1701 ;; Handle @end ftable, @end vtable
1702
1703 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1704 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1705
1706 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1707 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1708
1709 (defun texinfo-end-indextable (table-type)
1710 (setq fill-column (+ fill-column 5))
1711 (texinfo-discard-command)
1712 (let ((stacktop
1713 (texinfo-pop-stack table-type)))
1714 (texinfo-do-itemize (nth 1 stacktop))))
1715
1716 \f
1717 ;;; @multitable ... @end multitable
1718
1719 ;; Produce a multi-column table, with as many columns as desired.
1720 ;;
1721 ;; A multi-column table has this template:
1722 ;;
1723 ;; @multitable {A1} {A2} {A3}
1724 ;; @item A1 @tab A2 @tab A3
1725 ;; @item B1 @tab B2 @tab B3
1726 ;; @item C1 @tab C2 @tab C3
1727 ;; @end multitable
1728 ;;
1729 ;; where the width of the text in brackets specifies the width of the
1730 ;; respective column.
1731 ;;
1732 ;; Or else:
1733 ;;
1734 ;; @multitable @columnfractions .25 .3 .45
1735 ;; @item A1 @tab A2 @tab A3
1736 ;; @item B1 @tab B2 @tab B3
1737 ;; @end multitable
1738 ;;
1739 ;; where the fractions specify the width of each column as a percent
1740 ;; of the current width of the text (i.e., of the fill-column).
1741 ;;
1742 ;; Long lines of text are filled within columns.
1743 ;;
1744 ;; Using the Emacs Lisp formatter, texinfmt.el,
1745 ;; the whitespace between columns can be increased by setting
1746 ;; `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1747 ;; there is at least one blank space between columns.
1748 ;;
1749 ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
1750 ;; commands that are defined in texinfo.tex for printed output.
1751 ;;
1752 ;; @multitableparskip,
1753 ;; @multitableparindent,
1754 ;; @multitablecolmargin,
1755 ;; @multitablelinespace.
1756
1757 ;; How @multitable works.
1758 ;; =====================
1759 ;;
1760 ;; `texinfo-multitable' reads the @multitable line and determines from it
1761 ;; how wide each column should be.
1762 ;;
1763 ;; Also, it pushes this information, along with an identifying symbol,
1764 ;; onto the `texinfo-stack'. At the @end multitable command, the stack
1765 ;; is checked for its matching @multitable command, and then popped, or
1766 ;; else an error is signaled. Also, this command pushes the location of
1767 ;; the start of the table onto the stack.
1768 ;;
1769 ;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end
1770 ;; multitable truly is ending a corresponding beginning, and if it is,
1771 ;; pops the stack.
1772 ;;
1773 ;; `texinfo-multitable-widths' is called by `texinfo-multitable'.
1774 ;; The function returns a list of the widths of each column in a
1775 ;; multi-column table, based on the information supplied by the arguments
1776 ;; to the @multitable command (by arguments, I mean the text on the rest
1777 ;; of the @multitable line, not the remainder of the multi-column table
1778 ;; environment).
1779 ;;
1780 ;; `texinfo-multitable-item' formats a row within a multicolumn table.
1781 ;; This command is executed when texinfmt sees @item inside @multitable.
1782 ;; Cells in row are separated by `@tab's. Widths of cells are specified
1783 ;; by the arguments in the @multitable line. Cells are filled. All cells
1784 ;; are made to be the same height by padding their bottoms, as needed,
1785 ;; with blanks.
1786 ;;
1787 ;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'.
1788 ;; This function returns the text in a multitable row, as a string.
1789 ;; The start of a row is marked by an @item and the end of row is the
1790 ;; beginning of next @item or beginning of the @end multitable line.
1791 ;; Cells within a row are separated by @tab.
1792 ;;
1793 ;; Note that @tab, the cell separators, are not treated as independent
1794 ;; Texinfo commands.
1795
1796 (defvar texinfo-extra-inter-column-width 0
1797 "*Number of extra spaces between entries (columns) in @multitable.")
1798
1799 (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
1800 (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
1801
1802 ;; These commands are defined in texinfo.tex for printed output.
1803 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
1804 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
1805 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
1806 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
1807
1808 (put 'multitable 'texinfo-format 'texinfo-multitable)
1809
1810 (defun texinfo-multitable ()
1811 "Produce multi-column tables.
1812
1813 A multi-column table has this template:
1814
1815 @multitable {A1} {A2} {A3}
1816 @item A1 @tab A2 @tab A3
1817 @item B1 @tab B2 @tab B3
1818 @item C1 @tab C2 @tab C3
1819 @end multitable
1820
1821 where the width of the text in brackets specifies the width of the
1822 respective column.
1823
1824 Or else:
1825
1826 @multitable @columnfractions .25 .3 .45
1827 @item A1 @tab A2 @tab A3
1828 @item B1 @tab B2 @tab B3
1829 @end multitable
1830
1831 where the fractions specify the width of each column as a percent
1832 of the current width of the text (i.e., of the fill-column).
1833
1834 Long lines of text are filled within columns.
1835
1836 Using the Emacs Lisp formatter, texinfmt.el,
1837 the whitespace between columns can be increased by setting
1838 `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1839 there is at least one blank space between columns.
1840
1841 The Emacs Lisp formatter, texinfmt.el, ignores the following four
1842 commands that are defined in texinfo.tex for printed output.
1843
1844 @multitableparskip,
1845 @multitableparindent,
1846 @multitablecolmargin,
1847 @multitablelinespace."
1848
1849 ;; This function pushes information onto the `texinfo-stack'.
1850 ;; A stack element consists of:
1851 ;; - type-of-command, i.e., multitable
1852 ;; - the information about column widths, and
1853 ;; - the position of texinfo-command-start.
1854 ;; e.g., ('multitable (1 2 3 4) 123)
1855 ;; The command line is then deleted.
1856 (texinfo-push-stack
1857 'multitable
1858 ;; push width information on stack
1859 (texinfo-multitable-widths))
1860 (texinfo-discard-line-with-args))
1861
1862 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
1863 (defun texinfo-end-multitable ()
1864 "Discard the @end multitable line and pop the stack of multitable."
1865 (texinfo-discard-command)
1866 (texinfo-pop-stack 'multitable))
1867
1868 (defun texinfo-multitable-widths ()
1869 "Return list of widths of each column in a multi-column table."
1870 (let (texinfo-multitable-width-list)
1871 ;; Fractions format:
1872 ;; @multitable @columnfractions .25 .3 .45
1873 ;;
1874 ;; Template format:
1875 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
1876 ;; Place point before first argument
1877 (skip-chars-forward " \t")
1878 (cond
1879 ;; Check for common misspelling
1880 ((looking-at "@columnfraction ")
1881 (error "In @multitable, @columnfractions misspelled"))
1882 ;; Case 1: @columnfractions .25 .3 .45
1883 ((looking-at "@columnfractions")
1884 (forward-word 1)
1885 (while (not (eolp))
1886 (setq texinfo-multitable-width-list
1887 (cons
1888 (truncate
1889 (1-
1890 (* fill-column (read (get-buffer (current-buffer))))))
1891 texinfo-multitable-width-list))))
1892 ;;
1893 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
1894 ((looking-at "{")
1895 (let ((start-of-templates (point)))
1896 (while (not (eolp))
1897 (skip-chars-forward " \t")
1898 (let* ((start-of-template (1+ (point)))
1899 (end-of-template
1900 ;; forward-sexp works with braces in Texinfo mode
1901 (progn (forward-sexp 1) (1- (point)))))
1902 (setq texinfo-multitable-width-list
1903 (cons (- end-of-template start-of-template)
1904 texinfo-multitable-width-list))
1905 ;; Remove carriage return from within a template, if any.
1906 ;; This helps those those who want to use more than
1907 ;; one line's worth of words in @multitable line.
1908 (narrow-to-region start-of-template end-of-template)
1909 (goto-char (point-min))
1910 (while (search-forward "
1911 " nil t)
1912 (delete-char -1))
1913 (goto-char (point-max))
1914 (widen)
1915 (forward-char 1)))))
1916 ;;
1917 ;; Case 3: Trouble
1918 (t
1919 (error
1920 "You probably need to specify column widths for @multitable correctly.")))
1921 ;; Check whether columns fit on page.
1922 (let ((desired-columns
1923 (+
1924 ;; between column spaces
1925 (length texinfo-multitable-width-list)
1926 ;; additional between column spaces, if any
1927 texinfo-extra-inter-column-width
1928 ;; sum of spaces for each entry
1929 (apply '+ texinfo-multitable-width-list))))
1930 (if (> desired-columns fill-column)
1931 (error
1932 (format
1933 "Multi-column table width, %d chars, is greater than page width, %d chars."
1934 desired-columns fill-column))))
1935 texinfo-multitable-width-list))
1936
1937 ;; @item A1 @tab A2 @tab A3
1938 (defun texinfo-multitable-extract-row ()
1939 "Return multitable row, as a string.
1940 End of row is beginning of next @item or beginning of @end.
1941 Cells within rows are separated by @tab."
1942 (skip-chars-forward " \t")
1943 (let* ((start (point))
1944 (end (progn
1945 (re-search-forward "@item\\|@end")
1946 (match-beginning 0)))
1947 (row (progn (goto-char end)
1948 (skip-chars-backward " ")
1949 ;; remove whitespace at end of argument
1950 (delete-region (point) end)
1951 (buffer-substring start (point)))))
1952 (delete-region texinfo-command-start end)
1953 row))
1954
1955 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
1956 (defun texinfo-multitable-item ()
1957 "Format a row within a multicolumn table.
1958 Cells in row are separated by @tab.
1959 Widths of cells are specified by the arguments in the @multitable line.
1960 All cells are made to be the same height.
1961 This command is executed when texinfmt sees @item inside @multitable."
1962 (let ((original-buffer (current-buffer))
1963 (table-widths (reverse (car (cdr (car texinfo-stack)))))
1964 (existing-fill-column fill-column)
1965 start
1966 end
1967 (table-column 0)
1968 (table-entry-height 0)
1969 ;; unformatted row looks like: A1 @tab A2 @tab A3
1970 ;; extract-row command deletes the source line in the table.
1971 (unformated-row (texinfo-multitable-extract-row)))
1972 ;; Use a temporary buffer
1973 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
1974 (delete-region (point-min) (point-max))
1975 (insert unformated-row)
1976 (goto-char (point-min))
1977 ;; 1. Check for correct number of @tab in line.
1978 (let ((tab-number 1)) ; one @tab between two columns
1979 (while (search-forward "@tab" nil t)
1980 (setq tab-number (1+ tab-number)))
1981 (if (/= tab-number (length table-widths))
1982 (error "Wrong number of @tab's in a @multitable row.")))
1983 (goto-char (point-min))
1984 ;; 2. Format each cell, and copy to a rectangle
1985 ;; buffer looks like this: A1 @tab A2 @tab A3
1986 ;; Cell #1: format up to @tab
1987 ;; Cell #2: format up to @tab
1988 ;; Cell #3: format up to eob
1989 (while (not (eobp))
1990 (setq start (point))
1991 (setq end (save-excursion
1992 (if (search-forward "@tab" nil 'move)
1993 ;; Delete the @tab command, including the @-sign
1994 (delete-region
1995 (point)
1996 (progn (forward-word -1) (1- (point)))))
1997 (point)))
1998 ;; Set fill-column *wider* than needed to produce inter-column space
1999 (setq fill-column (+ 1
2000 texinfo-extra-inter-column-width
2001 (nth table-column table-widths)))
2002 (narrow-to-region start end)
2003 ;; Remove whitespace before and after entry.
2004 (skip-chars-forward " ")
2005 (delete-region (point) (save-excursion (beginning-of-line) (point)))
2006 (goto-char (point-max))
2007 (skip-chars-backward " ")
2008 (delete-region (point) (save-excursion (end-of-line) (point)))
2009 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
2010 ;; does not see an unterminated @multitable.
2011 (let (texinfo-stack) ; nil
2012 (texinfo-format-scan))
2013 (let (fill-prefix) ; no fill prefix
2014 (fill-region (point-min) (point-max)))
2015 (setq table-entry-height
2016 (max table-entry-height (count-lines (point-min) (point-max))))
2017 ;; 3. Move point to end of bottom line, and pad that line to fill column.
2018 (goto-char (point-min))
2019 (forward-line (1- table-entry-height))
2020 (let* ((beg (point)) ; beginning of line
2021 ;; add one more space for inter-column spacing
2022 (needed-whitespace
2023 (1+
2024 (- fill-column
2025 (-
2026 (progn (end-of-line) (point)) ; end of existing line
2027 beg)))))
2028 (insert (make-string
2029 (if (> needed-whitespace 0) needed-whitespace 1)
2030 ? )))
2031 ;; now, put formatted cell into a rectangle
2032 (set (intern (concat texinfo-multitable-rectangle-name
2033 (int-to-string table-column)))
2034 (extract-rectangle (point-min) (point)))
2035 (delete-region (point-min) (point))
2036 (goto-char (point-max))
2037 (setq table-column (1+ table-column))
2038 (widen))
2039 ;; 4. Add extra lines to rectangles so all are of same height
2040 (let ((total-number-of-columns table-column)
2041 (column-number 0)
2042 here)
2043 (while (> table-column 0)
2044 (let ((this-rectangle (int-to-string table-column)))
2045 (while (< (length this-rectangle) table-entry-height)
2046 (setq this-rectangle (append this-rectangle '("")))))
2047 (setq table-column (1- table-column)))
2048 ;; 5. Insert formatted rectangles in original buffer
2049 (switch-to-buffer original-buffer)
2050 (open-line table-entry-height)
2051 (while (< column-number total-number-of-columns)
2052 (setq here (point))
2053 (insert-rectangle
2054 (eval (intern
2055 (concat texinfo-multitable-rectangle-name
2056 (int-to-string column-number)))))
2057 (goto-char here)
2058 (end-of-line)
2059 (setq column-number (1+ column-number))))
2060 (kill-buffer texinfo-multitable-buffer-name)
2061 (setq fill-column existing-fill-column)))
2062
2063 \f
2064 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html
2065
2066 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
2067 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
2068
2069 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
2070 (defun texinfo-format-iftex ()
2071 (delete-region texinfo-command-start
2072 (progn (re-search-forward "@end iftex[ \t]*\n")
2073 (point))))
2074
2075 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
2076 (defun texinfo-format-ifhtml ()
2077 (delete-region texinfo-command-start
2078 (progn (re-search-forward "@end ifhtml[ \t]*\n")
2079 (point))))
2080
2081 (put 'tex 'texinfo-format 'texinfo-format-tex)
2082 (defun texinfo-format-tex ()
2083 (delete-region texinfo-command-start
2084 (progn (re-search-forward "@end tex[ \t]*\n")
2085 (point))))
2086
2087 (put 'html 'texinfo-format 'texinfo-format-html)
2088 (defun texinfo-format-html ()
2089 (delete-region texinfo-command-start
2090 (progn (re-search-forward "@end html[ \t]*\n")
2091 (point))))
2092
2093 \f
2094 ;;; @titlepage
2095
2096 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
2097 (defun texinfo-format-titlepage ()
2098 (delete-region texinfo-command-start
2099 (progn (re-search-forward "@end titlepage[ \t]*\n")
2100 (point))))
2101
2102 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
2103
2104 ;; @titlespec an alternative titling command; ignored by Info
2105
2106 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
2107 (defun texinfo-format-titlespec ()
2108 (delete-region texinfo-command-start
2109 (progn (re-search-forward "@end titlespec[ \t]*\n")
2110 (point))))
2111
2112 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
2113
2114 \f
2115 ;;; @today
2116
2117 (put 'today 'texinfo-format 'texinfo-format-today)
2118
2119 ;; Produces Day Month Year style of output. eg `1 Jan 1900'
2120 ;; The `@today{}' command requires a pair of braces, like `@dots{}'.
2121 (defun texinfo-format-today ()
2122 (texinfo-parse-arg-discard)
2123 (insert (format-time-string "%e %b %Y")))
2124
2125 \f
2126 ;;; @timestamp{}
2127 ;; Produce `Day Month Year Hour:Min' style of output.
2128 ;; eg `1 Jan 1900 13:52'
2129
2130 (put 'timestamp 'texinfo-format 'texinfo-format-timestamp)
2131
2132 ;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'.
2133 (defun texinfo-format-timestamp ()
2134 "Insert the current local time and date."
2135 (texinfo-parse-arg-discard)
2136 ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z"
2137 (insert (format-time-string "%e %b %Y %R")))
2138
2139 \f
2140 ;;; @ignore
2141
2142 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
2143 (defun texinfo-format-ignore ()
2144 (delete-region texinfo-command-start
2145 (progn (re-search-forward "@end ignore[ \t]*\n")
2146 (point))))
2147
2148 (put 'endignore 'texinfo-format 'texinfo-discard-line)
2149
2150 \f
2151 ;;; Define the Info enclosure command: @definfoenclose
2152
2153 ;; A `@definfoenclose' command may be used to define a highlighting
2154 ;; command for Info, but not for TeX. A command defined using
2155 ;; `@definfoenclose' marks text by enclosing it in strings that precede
2156 ;; and follow the text.
2157 ;;
2158 ;; Presumably, if you define a command with `@definfoenclose` for Info,
2159 ;; you will also define the same command in the TeX definitions file,
2160 ;; `texinfo.tex' in a manner appropriate for typesetting.
2161 ;;
2162 ;; Write a `@definfoenclose' command on a line and follow it with three
2163 ;; arguments separated by commas (commas are used as separators in an
2164 ;; `@node' line in the same way). The first argument to
2165 ;; `@definfoenclose' is the @-command name \(without the `@'\); the
2166 ;; second argument is the Info start delimiter string; and the third
2167 ;; argument is the Info end delimiter string. The latter two arguments
2168 ;; enclose the highlighted text in the Info file. A delimiter string
2169 ;; may contain spaces. Neither the start nor end delimiter is
2170 ;; required. However, if you do not provide a start delimiter, you
2171 ;; must follow the command name with two commas in a row; otherwise,
2172 ;; the Info formatting commands will misinterpret the end delimiter
2173 ;; string as a start delimiter string.
2174 ;;
2175 ;; If you do a @definfoenclose{} on the name of a pre-defined macro (such
2176 ;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
2177 ;; override the built-in definition.
2178 ;;
2179 ;; An enclosure command defined this way takes one argument in braces.
2180 ;;
2181 ;; For example, you can write:
2182 ;;
2183 ;; @ifinfo
2184 ;; @definfoenclose phoo, //, \\
2185 ;; @end ifinfo
2186 ;;
2187 ;; near the beginning of a Texinfo file at the beginning of the lines
2188 ;; to define `@phoo' as an Info formatting command that inserts `//'
2189 ;; before and `\\' after the argument to `@phoo'. You can then write
2190 ;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
2191 ;;
2192 ;; Also, for TeX formatting, you could write
2193 ;;
2194 ;; @iftex
2195 ;; @global@let@phoo=@i
2196 ;; @end iftex
2197 ;;
2198 ;; to define `@phoo' as a command that causes TeX to typeset
2199 ;; the argument to `@phoo' in italics.
2200 ;;
2201 ;; Note that each definition applies to its own formatter: one for TeX,
2202 ;; the other for texinfo-format-buffer or texinfo-format-region.
2203 ;;
2204 ;; Here is another example: write
2205 ;;
2206 ;; @definfoenclose headword, , :
2207 ;;
2208 ;; near the beginning of the file, to define `@headword' as an Info
2209 ;; formatting command that inserts nothing before and a colon after the
2210 ;; argument to `@headword'.
2211
2212 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
2213 (defun texinfo-define-info-enclosure ()
2214 (let* ((args (texinfo-format-parse-line-args))
2215 (command-name (nth 0 args))
2216 (beginning-delimiter (or (nth 1 args) ""))
2217 (end-delimiter (or (nth 2 args) "")))
2218 (texinfo-discard-command)
2219 (setq texinfo-enclosure-list
2220 (cons
2221 (list command-name
2222 (list
2223 beginning-delimiter
2224 end-delimiter))
2225 texinfo-enclosure-list))))
2226
2227 \f
2228 ;;; @var, @code and the like
2229
2230 (put 'var 'texinfo-format 'texinfo-format-var)
2231 ;; @sc a small caps font for TeX; formatted as `var' in Info
2232 (put 'sc 'texinfo-format 'texinfo-format-var)
2233 (defun texinfo-format-var ()
2234 (insert (upcase (texinfo-parse-arg-discard)))
2235 (goto-char texinfo-command-start))
2236
2237 (put 'url 'texinfo-format 'texinfo-format-code)
2238 (put 'cite 'texinfo-format 'texinfo-format-code)
2239 (put 'code 'texinfo-format 'texinfo-format-code)
2240 (put 'file 'texinfo-format 'texinfo-format-code)
2241 (put 'samp 'texinfo-format 'texinfo-format-code)
2242 (defun texinfo-format-code ()
2243 (insert "`" (texinfo-parse-arg-discard) "'")
2244 (goto-char texinfo-command-start))
2245
2246 (put 'emph 'texinfo-format 'texinfo-format-emph)
2247 (put 'strong 'texinfo-format 'texinfo-format-emph)
2248 (defun texinfo-format-emph ()
2249 (insert "*" (texinfo-parse-arg-discard) "*")
2250 (goto-char texinfo-command-start))
2251
2252 (put 'dfn 'texinfo-format 'texinfo-format-defn)
2253 (put 'defn 'texinfo-format 'texinfo-format-defn)
2254 (defun texinfo-format-defn ()
2255 (insert "\"" (texinfo-parse-arg-discard) "\"")
2256 (goto-char texinfo-command-start))
2257
2258 (put 'email 'texinfo-format 'texinfo-format-key)
2259 (put 'key 'texinfo-format 'texinfo-format-key)
2260 ;; I've decided not want to have angle brackets around these -- rms.
2261 (defun texinfo-format-key ()
2262 (insert (texinfo-parse-arg-discard))
2263 (goto-char texinfo-command-start))
2264
2265 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
2266 (defun texinfo-format-bullet ()
2267 "Insert an asterisk.
2268 If used within a line, follow `@bullet' with braces."
2269 (texinfo-optional-braces-discard)
2270 (insert "*"))
2271
2272 \f
2273 ;;; @kbd
2274
2275 ;; Inside of @example ... @end example and similar environments,
2276 ;; @kbd does nothing; but outside of such environments, it places
2277 ;; single quotation markes around its argument.
2278
2279 (defvar texinfo-format-kbd-regexp
2280 (concat
2281 "^@"
2282 "\\("
2283 "example\\|"
2284 "smallexample\\|"
2285 "lisp\\|"
2286 "smalllisp"
2287 "\\)")
2288 "Regexp specifying environments in which @kbd does not put `...'
2289 around argument.")
2290
2291 (defvar texinfo-format-kbd-end-regexp
2292 (concat
2293 "^@end "
2294 "\\("
2295 "example\\|"
2296 "smallexample\\|"
2297 "lisp\\|"
2298 "smalllisp"
2299 "\\)")
2300 "Regexp specifying end of environments in which @kbd does not put `...'
2301 around argument. (See `texinfo-format-kbd-regexp')")
2302
2303 (put 'kbd 'texinfo-format 'texinfo-format-kbd)
2304 (defun texinfo-format-kbd ()
2305 "Place single quote marks around arg, except in @example and similar."
2306 ;; Search forward for @end example closer than an @example.
2307 ;; Can stop search at nearest @node or texinfo-section-types-regexp
2308 (let* ((stop
2309 (save-excursion
2310 (re-search-forward
2311 (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)")
2312 nil
2313 'move-to-end) ; if necessary, return point at end of buffer
2314 (point)))
2315 (example-location
2316 (save-excursion
2317 (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end)
2318 (point)))
2319 (end-example-location
2320 (save-excursion
2321 (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end)
2322 (point))))
2323 ;; If inside @example, @end example will be closer than @example
2324 ;; or end of search i.e., end-example-location less than example-location
2325 (if (>= end-example-location example-location)
2326 ;; outside an @example or equivalent
2327 (insert "`" (texinfo-parse-arg-discard) "'")
2328 ;; else, in @example; do not surround with `...'
2329 (insert (texinfo-parse-arg-discard)))
2330 (goto-char texinfo-command-start)))
2331
2332 \f
2333 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
2334
2335 (put 'display 'texinfo-format 'texinfo-format-example)
2336 (put 'example 'texinfo-format 'texinfo-format-example)
2337 (put 'lisp 'texinfo-format 'texinfo-format-example)
2338 (put 'quotation 'texinfo-format 'texinfo-format-example)
2339 (put 'smallexample 'texinfo-format 'texinfo-format-example)
2340 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
2341 (defun texinfo-format-example ()
2342 (texinfo-push-stack 'example nil)
2343 (setq fill-column (- fill-column 5))
2344 (texinfo-discard-line))
2345
2346 (put 'example 'texinfo-end 'texinfo-end-example)
2347 (put 'display 'texinfo-end 'texinfo-end-example)
2348 (put 'lisp 'texinfo-end 'texinfo-end-example)
2349 (put 'quotation 'texinfo-end 'texinfo-end-example)
2350 (put 'smallexample 'texinfo-end 'texinfo-end-example)
2351 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
2352 (defun texinfo-end-example ()
2353 (setq fill-column (+ fill-column 5))
2354 (texinfo-discard-command)
2355 (let ((stacktop
2356 (texinfo-pop-stack 'example)))
2357 (texinfo-do-itemize (nth 1 stacktop))))
2358
2359 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
2360 (defun texinfo-format-exdent ()
2361 (texinfo-discard-command)
2362 (delete-region (point)
2363 (progn
2364 (skip-chars-forward " ")
2365 (point)))
2366 (insert ?\b)
2367 ;; Cancel out the deletion that texinfo-do-itemize
2368 ;; is going to do at the end of this line.
2369 (save-excursion
2370 (end-of-line)
2371 (insert "\n ")))
2372
2373 \f
2374 ;; @direntry and @dircategory
2375
2376 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
2377 (defun texinfo-format-direntry ()
2378 (texinfo-push-stack 'direntry nil)
2379 (texinfo-discard-line)
2380 (insert "START-INFO-DIR-ENTRY\n\n"))
2381
2382 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
2383 (defun texinfo-end-direntry ()
2384 (texinfo-discard-command)
2385 (insert "END-INFO-DIR-ENTRY\n\n")
2386 (texinfo-pop-stack 'direntry))
2387
2388 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
2389 (defun texinfo-format-dircategory ()
2390 (let ((str (texinfo-parse-arg-discard)))
2391 (delete-region (point)
2392 (progn
2393 (skip-chars-forward " ")
2394 (point)))
2395 (insert "INFO-DIR-SECTION " str "\n")))
2396 \f
2397 ;;; @cartouche
2398
2399 ;; The @cartouche command is a noop in Info; in a printed manual,
2400 ;; it makes a box with rounded corners.
2401
2402 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
2403 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
2404
2405 \f
2406 ;;; @flushleft and @format
2407
2408 ;; The @flushleft command left justifies every line but leaves the
2409 ;; right end ragged. As far as Info is concerned, @flushleft is a
2410 ;; `do-nothing' command
2411
2412 ;; The @format command is similar to @example except that it does not
2413 ;; indent; this means that in Info, @format is similar to @flushleft.
2414
2415 (put 'format 'texinfo-format 'texinfo-format-flushleft)
2416 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
2417 (defun texinfo-format-flushleft ()
2418 (texinfo-discard-line))
2419
2420 (put 'format 'texinfo-end 'texinfo-end-flushleft)
2421 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
2422 (defun texinfo-end-flushleft ()
2423 (texinfo-discard-command))
2424
2425 \f
2426 ;;; @flushright
2427
2428 ;; The @flushright command right justifies every line but leaves the
2429 ;; left end ragged. Spaces and tabs at the right ends of lines are
2430 ;; removed so that visible text lines up on the right side.
2431
2432 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
2433 (defun texinfo-format-flushright ()
2434 (texinfo-push-stack 'flushright nil)
2435 (texinfo-discard-line))
2436
2437 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
2438 (defun texinfo-end-flushright ()
2439 (texinfo-discard-command)
2440
2441 (let ((stacktop
2442 (texinfo-pop-stack 'flushright)))
2443
2444 (texinfo-do-flushright (nth 1 stacktop))))
2445
2446 (defun texinfo-do-flushright (from)
2447 (save-excursion
2448 (while (progn (forward-line -1)
2449 (>= (point) from))
2450
2451 (beginning-of-line)
2452 (insert
2453 (make-string
2454 (- fill-column
2455 (save-excursion
2456 (end-of-line)
2457 (skip-chars-backward " \t")
2458 (delete-region (point) (progn (end-of-line) (point)))
2459 (current-column)))
2460 ? )))))
2461
2462 \f
2463 ;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds
2464
2465 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
2466 (defun texinfo-format-ctrl ()
2467 (let ((str (texinfo-parse-arg-discard)))
2468 (insert (logand 31 (aref str 0)))))
2469
2470 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
2471 (defun texinfo-format-TeX ()
2472 (texinfo-parse-arg-discard)
2473 (insert "TeX"))
2474
2475 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
2476 (defun texinfo-format-copyright ()
2477 (texinfo-parse-arg-discard)
2478 (insert "(C)"))
2479
2480 (put 'minus 'texinfo-format 'texinfo-format-minus)
2481 (defun texinfo-format-minus ()
2482 "Insert a minus sign.
2483 If used within a line, follow `@minus' with braces."
2484 (texinfo-optional-braces-discard)
2485 (insert "-"))
2486
2487 (put 'dots 'texinfo-format 'texinfo-format-dots)
2488 (defun texinfo-format-dots ()
2489 (texinfo-parse-arg-discard)
2490 (insert "..."))
2491
2492 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
2493 (defun texinfo-format-enddots ()
2494 (texinfo-parse-arg-discard)
2495 (insert "...."))
2496
2497 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
2498 (defun texinfo-format-pounds ()
2499 (texinfo-parse-arg-discard)
2500 (insert "#"))
2501
2502 \f
2503 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
2504
2505 ;;; Indent only those paragraphs that are refilled as a result of an
2506 ;;; @refill command.
2507
2508 ;; * If the value is `asis', do not change the existing indentation at
2509 ;; the starts of paragraphs.
2510
2511 ;; * If the value zero, delete any existing indentation.
2512
2513 ;; * If the value is greater than zero, indent each paragraph by that
2514 ;; number of spaces.
2515
2516 ;;; But do not refill paragraphs with an @refill command that are
2517 ;;; preceded by @noindent or are part of a table, list, or deffn.
2518
2519 (defvar texinfo-paragraph-indent "asis"
2520 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
2521
2522 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
2523
2524 (defun texinfo-paragraphindent ()
2525 "Specify the number of spaces for @refill to indent a paragraph.
2526 Default is to leave the number of spaces as is."
2527 (let ((arg (texinfo-parse-arg-discard)))
2528 (if (string= "asis" arg)
2529 (setq texinfo-paragraph-indent "asis")
2530 (setq texinfo-paragraph-indent (string-to-int arg)))))
2531
2532 (put 'refill 'texinfo-format 'texinfo-format-refill)
2533 (defun texinfo-format-refill ()
2534 "Refill paragraph. Also, indent first line as set by @paragraphindent.
2535 Default is to leave paragraph indentation as is."
2536 (texinfo-discard-command)
2537 (forward-paragraph -1)
2538 (if (looking-at "[ \t\n]*$") (forward-line 1))
2539 ;; Do not indent if an entry in a list, table, or deffn,
2540 ;; or if paragraph is preceded by @noindent.
2541 ;; Otherwise, indent
2542 (cond
2543 ;; delete a @noindent line and do not indent paragraph
2544 ((save-excursion (forward-line -1)
2545 (looking-at "^@noindent"))
2546 (forward-line -1)
2547 (delete-region (point) (progn (forward-line 1) (point))))
2548 ;; do nothing if "asis"
2549 ((equal texinfo-paragraph-indent "asis"))
2550 ;; do no indenting in list, etc.
2551 ((> texinfo-stack-depth 0))
2552 ;; otherwise delete existing whitespace and indent
2553 (t
2554 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2555 (insert (make-string texinfo-paragraph-indent ? ))))
2556 (forward-paragraph 1)
2557 (forward-line -1)
2558 (end-of-line)
2559 ;; Do not fill a section title line with asterisks, hyphens, etc. that
2560 ;; are used to underline it. This could occur if the line following
2561 ;; the underlining is not an index entry and has text within it.
2562 (let* ((previous-paragraph-separate paragraph-separate)
2563 (paragraph-separate
2564 (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+"))
2565 (previous-paragraph-start paragraph-start)
2566 (paragraph-start
2567 (concat paragraph-start "\\|[-=.]+\\|\\*\\*+")))
2568 (unwind-protect
2569 (fill-paragraph nil)
2570 (setq paragraph-separate previous-paragraph-separate)
2571 (setq paragraph-start previous-paragraph-start))))
2572
2573 (put 'noindent 'texinfo-format 'texinfo-noindent)
2574 (defun texinfo-noindent ()
2575 (save-excursion
2576 (forward-paragraph 1)
2577 (if (search-backward "@refill"
2578 (save-excursion (forward-line -1) (point)) t)
2579 () ; leave @noindent command so @refill command knows not to indent
2580 ;; else
2581 (texinfo-discard-line))))
2582
2583 \f
2584 ;;; Index generation
2585
2586 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
2587 (defun texinfo-format-vindex ()
2588 (texinfo-index 'texinfo-vindex))
2589
2590 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
2591 (defun texinfo-format-cindex ()
2592 (texinfo-index 'texinfo-cindex))
2593
2594 (put 'findex 'texinfo-format 'texinfo-format-findex)
2595 (defun texinfo-format-findex ()
2596 (texinfo-index 'texinfo-findex))
2597
2598 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
2599 (defun texinfo-format-pindex ()
2600 (texinfo-index 'texinfo-pindex))
2601
2602 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
2603 (defun texinfo-format-tindex ()
2604 (texinfo-index 'texinfo-tindex))
2605
2606 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
2607 (defun texinfo-format-kindex ()
2608 (texinfo-index 'texinfo-kindex))
2609
2610 (defun texinfo-index (indexvar)
2611 (let ((arg (texinfo-parse-expanded-arg)))
2612 (texinfo-discard-command)
2613 (set indexvar
2614 (cons (list arg
2615 texinfo-last-node
2616 ;; Region formatting may not provide last node position.
2617 (if texinfo-last-node-pos
2618 (1+ (count-lines texinfo-last-node-pos (point)))
2619 1))
2620 (symbol-value indexvar)))))
2621
2622 (defconst texinfo-indexvar-alist
2623 '(("cp" . texinfo-cindex)
2624 ("fn" . texinfo-findex)
2625 ("vr" . texinfo-vindex)
2626 ("tp" . texinfo-tindex)
2627 ("pg" . texinfo-pindex)
2628 ("ky" . texinfo-kindex)))
2629
2630 \f
2631 ;;; @defindex @defcodeindex
2632 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
2633 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
2634
2635 (defun texinfo-format-defindex ()
2636 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
2637 (indexing-command (intern (concat index-name "index")))
2638 (index-formatting-command ; eg: `texinfo-format-aaindex'
2639 (intern (concat "texinfo-format-" index-name "index")))
2640 (index-alist-name ; eg: `texinfo-aaindex'
2641 (intern (concat "texinfo-" index-name "index"))))
2642
2643 (set index-alist-name nil)
2644
2645 (put indexing-command ; eg, aaindex
2646 'texinfo-format
2647 index-formatting-command) ; eg, texinfo-format-aaindex
2648
2649 ;; eg: "aa" . texinfo-aaindex
2650 (or (assoc index-name texinfo-indexvar-alist)
2651 (setq texinfo-indexvar-alist
2652 (cons
2653 (cons index-name
2654 index-alist-name)
2655 texinfo-indexvar-alist)))
2656
2657 (fset index-formatting-command
2658 (list 'lambda 'nil
2659 (list 'texinfo-index
2660 (list 'quote index-alist-name))))))
2661
2662 \f
2663 ;;; @synindex @syncodeindex
2664
2665 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
2666 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
2667
2668 (defun texinfo-format-synindex ()
2669 (let* ((args (texinfo-parse-arg-discard))
2670 (second (cdr (read-from-string args)))
2671 (joiner (symbol-name (car (read-from-string args))))
2672 (joined (symbol-name (car (read-from-string args second)))))
2673
2674 (if (assoc joiner texinfo-short-index-cmds-alist)
2675 (put
2676 (cdr (assoc joiner texinfo-short-index-cmds-alist))
2677 'texinfo-format
2678 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
2679 (intern (concat "texinfo-format-" joined "index"))))
2680 (put
2681 (intern (concat joiner "index"))
2682 'texinfo-format
2683 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2684 (intern (concat "texinfo-format-" joined "index")))))))
2685
2686 (defconst texinfo-short-index-cmds-alist
2687 '(("cp" . cindex)
2688 ("fn" . findex)
2689 ("vr" . vindex)
2690 ("tp" . tindex)
2691 ("pg" . pindex)
2692 ("ky" . kindex)))
2693
2694 (defconst texinfo-short-index-format-cmds-alist
2695 '(("cp" . texinfo-format-cindex)
2696 ("fn" . texinfo-format-findex)
2697 ("vr" . texinfo-format-vindex)
2698 ("tp" . texinfo-format-tindex)
2699 ("pg" . texinfo-format-pindex)
2700 ("ky" . texinfo-format-kindex)))
2701
2702 \f
2703 ;;; Sort and index (for VMS)
2704
2705 ;; Sort an index which is in the current buffer between START and END.
2706 ;; Used on VMS, where the `sort' utility is not available.
2707 (defun texinfo-sort-region (start end)
2708 (require 'sort)
2709 (save-restriction
2710 (narrow-to-region start end)
2711 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
2712
2713 ;; Subroutine for sorting an index.
2714 ;; At start of a line, return a string to sort the line under.
2715 (defun texinfo-sort-startkeyfun ()
2716 (let ((line
2717 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
2718 ;; Canonicalize whitespace and eliminate funny chars.
2719 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
2720 (setq line (concat (substring line 0 (match-beginning 0))
2721 " "
2722 (substring line (match-end 0) (length line)))))
2723 line))
2724
2725 \f
2726 ;;; @printindex
2727
2728 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
2729
2730 (defun texinfo-format-printindex ()
2731 (let ((indexelts (symbol-value
2732 (cdr (assoc (texinfo-parse-arg-discard)
2733 texinfo-indexvar-alist))))
2734 opoint)
2735 (insert "\n* Menu:\n\n")
2736 (setq opoint (point))
2737 (texinfo-print-index nil indexelts)
2738
2739 (if (memq system-type '(vax-vms windows-nt ms-dos))
2740 (texinfo-sort-region opoint (point))
2741 (shell-command-on-region opoint (point) "sort -fd" 1))))
2742
2743 (defun texinfo-print-index (file indexelts)
2744 (while indexelts
2745 (if (stringp (car (car indexelts)))
2746 (progn
2747 (insert "* " (car (car indexelts)) ": " )
2748 (indent-to 32)
2749 (insert
2750 (if file (concat "(" file ")") "")
2751 (nth 1 (car indexelts)) ".")
2752 (indent-to 54)
2753 (insert
2754 (if (nth 2 (car indexelts))
2755 (format " %d." (nth 2 (car indexelts)))
2756 "")
2757 "\n"))
2758 ;; index entries from @include'd file
2759 (texinfo-print-index (nth 1 (car indexelts))
2760 (nth 2 (car indexelts))))
2761 (setq indexelts (cdr indexelts))))
2762
2763 \f
2764 ;;; Glyphs: @equiv, @error, etc
2765
2766 ;; @equiv to show that two expressions are equivalent
2767 ;; @error to show an error message
2768 ;; @expansion to show what a macro expands to
2769 ;; @point to show the location of point in an example
2770 ;; @print to show what an evaluated expression prints
2771 ;; @result to indicate the value returned by an expression
2772
2773 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
2774 (defun texinfo-format-equiv ()
2775 (texinfo-parse-arg-discard)
2776 (insert "=="))
2777
2778 (put 'error 'texinfo-format 'texinfo-format-error)
2779 (defun texinfo-format-error ()
2780 (texinfo-parse-arg-discard)
2781 (insert "error-->"))
2782
2783 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
2784 (defun texinfo-format-expansion ()
2785 (texinfo-parse-arg-discard)
2786 (insert "==>"))
2787
2788 (put 'point 'texinfo-format 'texinfo-format-point)
2789 (defun texinfo-format-point ()
2790 (texinfo-parse-arg-discard)
2791 (insert "-!-"))
2792
2793 (put 'print 'texinfo-format 'texinfo-format-print)
2794 (defun texinfo-format-print ()
2795 (texinfo-parse-arg-discard)
2796 (insert "-|"))
2797
2798 (put 'result 'texinfo-format 'texinfo-format-result)
2799 (defun texinfo-format-result ()
2800 (texinfo-parse-arg-discard)
2801 (insert "=>"))
2802
2803 \f
2804 ;;; Accent commands
2805
2806 ;; Info presumes a plain ASCII output, so the accented characters do
2807 ;; not look as they would if typeset, or output with a different
2808 ;; character set.
2809
2810 ;; See the `texinfo-accent-commands' variable
2811 ;; in the section for `texinfo-append-refill'.
2812 ;; Also, see the defun for `texinfo-format-scan'
2813 ;; for single-character accent commands.
2814
2815 ;; Command Info output Name
2816
2817 ;; These do not have braces:
2818 ;; @^ ==> ^ circumflex accent
2819 ;; @` ==> ` grave accent
2820 ;; @' ==> ' acute accent
2821 ;; @" ==> " umlaut accent
2822 ;; @= ==> = overbar accent
2823 ;; @~ ==> ~ tilde accent
2824
2825 ;; These have braces, but take no argument:
2826 ;; @OE{} ==> OE French-OE-ligature
2827 ;; @oe{} ==> oe
2828 ;; @AA{} ==> AA Scandinavian-A-with-circle
2829 ;; @aa{} ==> aa
2830 ;; @AE{} ==> AE Latin-Scandinavian-AE
2831 ;; @ae{} ==> ae
2832 ;; @ss{} ==> ss German-sharp-S
2833
2834 ;; @questiondown{} ==> ? upside-down-question-mark
2835 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
2836 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
2837 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
2838 ;; @O{} ==> O/ Scandinavian O-with-slash
2839 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
2840
2841 ;; These have braces, and take an argument:
2842 ;; @,{c} ==> c, cedilla accent
2843 ;; @dotaccent{o} ==> .o overdot-accent
2844 ;; @ubaraccent{o} ==> _o underbar-accent
2845 ;; @udotaccent{o} ==> o-. underdot-accent
2846 ;; @H{o} ==> ""o long Hungarian umlaut
2847 ;; @ringaccent{o} ==> *o ring accent
2848 ;; @tieaccent{oo} ==> [oo tie after accent
2849 ;; @u{o} ==> (o breve accent
2850 ;; @v{o} ==> <o hacek accent
2851 ;; @dotless{i} ==> i dotless i and dotless j
2852
2853 ;; ==========
2854
2855 ;; Note: The defun texinfo-format-scan
2856 ;; looks at "[@{}^'`\",=~ *?!-]"
2857 ;; In the case of @*, a line break is inserted;
2858 ;; in the other cases, the characters are simply quoted and the @ is deleted.
2859 ;; Thus, `texinfo-format-scan' handles the following
2860 ;; single-character accent commands: @^ @` @' @" @, @- @= @~
2861
2862 ;; @^ ==> ^ circumflex accent
2863 ;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent)
2864 ;; (defun texinfo-format-circumflex-accent ()
2865 ;; (texinfo-discard-command)
2866 ;; (insert "^"))
2867 ;;
2868 ;; @` ==> ` grave accent
2869 ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
2870 ;; (defun texinfo-format-grave-accent ()
2871 ;; (texinfo-discard-command)
2872 ;; (insert "\`"))
2873 ;;
2874 ;; @' ==> ' acute accent
2875 ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
2876 ;; (defun texinfo-format-acute-accent ()
2877 ;; (texinfo-discard-command)
2878 ;; (insert "'"))
2879 ;;
2880 ;; @" ==> " umlaut accent
2881 ;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent)
2882 ;; (defun texinfo-format-umlaut-accent ()
2883 ;; (texinfo-discard-command)
2884 ;; (insert "\""))
2885 ;;
2886 ;; @= ==> = overbar accent
2887 ;; (put '= 'texinfo-format 'texinfo-format-overbar-accent)
2888 ;; (defun texinfo-format-overbar-accent ()
2889 ;; (texinfo-discard-command)
2890 ;; (insert "="))
2891 ;;
2892 ;; @~ ==> ~ tilde accent
2893 ;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent)
2894 ;; (defun texinfo-format-tilde-accent ()
2895 ;; (texinfo-discard-command)
2896 ;; (insert "~"))
2897
2898 ;; @OE{} ==> OE French-OE-ligature
2899 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
2900 (defun texinfo-format-French-OE-ligature ()
2901 (insert "OE" (texinfo-parse-arg-discard))
2902 (goto-char texinfo-command-start))
2903
2904 ;; @oe{} ==> oe
2905 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
2906 (defun texinfo-format-French-oe-ligature () ; lower case
2907 (insert "oe" (texinfo-parse-arg-discard))
2908 (goto-char texinfo-command-start))
2909
2910 ;; @AA{} ==> AA Scandinavian-A-with-circle
2911 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
2912 (defun texinfo-format-Scandinavian-A-with-circle ()
2913 (insert "AA" (texinfo-parse-arg-discard))
2914 (goto-char texinfo-command-start))
2915
2916 ;; @aa{} ==> aa
2917 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
2918 (defun texinfo-format-Scandinavian-a-with-circle () ; lower case
2919 (insert "aa" (texinfo-parse-arg-discard))
2920 (goto-char texinfo-command-start))
2921
2922 ;; @AE{} ==> AE Latin-Scandinavian-AE
2923 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
2924 (defun texinfo-format-Latin-Scandinavian-AE ()
2925 (insert "AE" (texinfo-parse-arg-discard))
2926 (goto-char texinfo-command-start))
2927
2928 ;; @ae{} ==> ae
2929 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
2930 (defun texinfo-format-Latin-Scandinavian-ae () ; lower case
2931 (insert "ae" (texinfo-parse-arg-discard))
2932 (goto-char texinfo-command-start))
2933
2934 ;; @ss{} ==> ss German-sharp-S
2935 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
2936 (defun texinfo-format-German-sharp-S ()
2937 (insert "ss" (texinfo-parse-arg-discard))
2938 (goto-char texinfo-command-start))
2939
2940 ;; @questiondown{} ==> ? upside-down-question-mark
2941 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
2942 (defun texinfo-format-upside-down-question-mark ()
2943 (insert "?" (texinfo-parse-arg-discard))
2944 (goto-char texinfo-command-start))
2945
2946 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
2947 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
2948 (defun texinfo-format-upside-down-exclamation-mark ()
2949 (insert "!" (texinfo-parse-arg-discard))
2950 (goto-char texinfo-command-start))
2951
2952 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
2953 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
2954 (defun texinfo-format-Polish-suppressed-L ()
2955 (insert (texinfo-parse-arg-discard) "/L")
2956 (goto-char texinfo-command-start))
2957
2958 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
2959 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
2960 (defun texinfo-format-Polish-suppressed-l-lower-case ()
2961 (insert (texinfo-parse-arg-discard) "/l")
2962 (goto-char texinfo-command-start))
2963
2964
2965 ;; @O{} ==> O/ Scandinavian O-with-slash
2966 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
2967 (defun texinfo-format-Scandinavian-O-with-slash ()
2968 (insert (texinfo-parse-arg-discard) "O/")
2969 (goto-char texinfo-command-start))
2970
2971 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
2972 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
2973 (defun texinfo-format-Scandinavian-o-with-slash-lower-case ()
2974 (insert (texinfo-parse-arg-discard) "o/")
2975 (goto-char texinfo-command-start))
2976
2977 ;; Take arguments
2978
2979 ;; @,{c} ==> c, cedilla accent
2980 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
2981 (defun texinfo-format-cedilla-accent ()
2982 (insert (texinfo-parse-arg-discard) ",")
2983 (goto-char texinfo-command-start))
2984
2985
2986 ;; @dotaccent{o} ==> .o overdot-accent
2987 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
2988 (defun texinfo-format-overdot-accent ()
2989 (insert "." (texinfo-parse-arg-discard))
2990 (goto-char texinfo-command-start))
2991
2992 ;; @ubaraccent{o} ==> _o underbar-accent
2993 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
2994 (defun texinfo-format-underbar-accent ()
2995 (insert "_" (texinfo-parse-arg-discard))
2996 (goto-char texinfo-command-start))
2997
2998 ;; @udotaccent{o} ==> o-. underdot-accent
2999 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
3000 (defun texinfo-format-underdot-accent ()
3001 (insert (texinfo-parse-arg-discard) "-.")
3002 (goto-char texinfo-command-start))
3003
3004 ;; @H{o} ==> ""o long Hungarian umlaut
3005 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
3006 (defun texinfo-format-long-Hungarian-umlaut ()
3007 (insert "\"\"" (texinfo-parse-arg-discard))
3008 (goto-char texinfo-command-start))
3009
3010 ;; @ringaccent{o} ==> *o ring accent
3011 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
3012 (defun texinfo-format-ring-accent ()
3013 (insert "*" (texinfo-parse-arg-discard))
3014 (goto-char texinfo-command-start))
3015
3016 ;; @tieaccent{oo} ==> [oo tie after accent
3017 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
3018 (defun texinfo-format-tie-after-accent ()
3019 (insert "[" (texinfo-parse-arg-discard))
3020 (goto-char texinfo-command-start))
3021
3022
3023 ;; @u{o} ==> (o breve accent
3024 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
3025 (defun texinfo-format-breve-accent ()
3026 (insert "(" (texinfo-parse-arg-discard))
3027 (goto-char texinfo-command-start))
3028
3029 ;; @v{o} ==> <o hacek accent
3030 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
3031 (defun texinfo-format-hacek-accent ()
3032 (insert "<" (texinfo-parse-arg-discard))
3033 (goto-char texinfo-command-start))
3034
3035
3036 ;; @dotless{i} ==> i dotless i and dotless j
3037 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
3038 (defun texinfo-format-dotless ()
3039 (insert (texinfo-parse-arg-discard))
3040 (goto-char texinfo-command-start))
3041
3042 \f
3043 ;;; Definition formatting: @deffn, @defun, etc
3044
3045 ;; What definition formatting produces:
3046 ;;
3047 ;; @deffn category name args...
3048 ;; In Info, `Category: name ARGS'
3049 ;; In index: name: node. line#.
3050 ;;
3051 ;; @defvr category name
3052 ;; In Info, `Category: name'
3053 ;; In index: name: node. line#.
3054 ;;
3055 ;; @deftp category name attributes...
3056 ;; `category name attributes...' Note: @deftp args in lower case.
3057 ;; In index: name: node. line#.
3058 ;;
3059 ;; Specialized function-like or variable-like entity:
3060 ;;
3061 ;; @defun, @defmac, @defspec, @defvar, @defopt
3062 ;;
3063 ;; @defun name args In Info, `Function: name ARGS'
3064 ;; @defmac name args In Info, `Macro: name ARGS'
3065 ;; @defvar name In Info, `Variable: name'
3066 ;; etc.
3067 ;; In index: name: node. line#.
3068 ;;
3069 ;; Generalized typed-function-like or typed-variable-like entity:
3070 ;; @deftypefn category data-type name args...
3071 ;; In Info, `Category: data-type name args...'
3072 ;; @deftypevr category data-type name
3073 ;; In Info, `Category: data-type name'
3074 ;; In index: name: node. line#.
3075 ;;
3076 ;; Specialized typed-function-like or typed-variable-like entity:
3077 ;; @deftypefun data-type name args...
3078 ;; In Info, `Function: data-type name ARGS'
3079 ;; In index: name: node. line#.
3080 ;;
3081 ;; @deftypevar data-type name
3082 ;; In Info, `Variable: data-type name'
3083 ;; In index: name: node. line#. but include args after name!?
3084 ;;
3085 ;; Generalized object oriented entity:
3086 ;; @defop category class name args...
3087 ;; In Info, `Category on class: name ARG'
3088 ;; In index: name on class: node. line#.
3089 ;;
3090 ;; @defcv category class name
3091 ;; In Info, `Category of class: name'
3092 ;; In index: name of class: node. line#.
3093 ;;
3094 ;; Specialized object oriented entity:
3095 ;; @defmethod class name args...
3096 ;; In Info, `Method on class: name ARGS'
3097 ;; In index: name on class: node. line#.
3098 ;;
3099 ;; @defivar class name
3100 ;; In Info, `Instance variable of class: name'
3101 ;; In index: name of class: node. line#.
3102
3103 \f
3104 ;;; The definition formatting functions
3105
3106 (defun texinfo-format-defun ()
3107 (texinfo-push-stack 'defun nil)
3108 (setq fill-column (- fill-column 5))
3109 (texinfo-format-defun-1 t))
3110
3111 (defun texinfo-end-defun ()
3112 (setq fill-column (+ fill-column 5))
3113 (texinfo-discard-command)
3114 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
3115 (texinfo-do-itemize start)
3116 ;; Delete extra newline inserted after header.
3117 (save-excursion
3118 (goto-char start)
3119 (delete-char -1))))
3120
3121 (defun texinfo-format-defunx ()
3122 (texinfo-format-defun-1 nil))
3123
3124 (defun texinfo-format-defun-1 (first-p)
3125 (let ((parse-args (texinfo-format-parse-defun-args))
3126 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
3127 (texinfo-discard-command)
3128 ;; Delete extra newline inserted after previous header line.
3129 (if (not first-p)
3130 (delete-char -1))
3131 (funcall
3132 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
3133 ;; Insert extra newline so that paragraph filling does not mess
3134 ;; with header line.
3135 (insert "\n\n")
3136 (rplaca (cdr (cdr (car texinfo-stack))) (point))
3137 (funcall
3138 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
3139
3140 ;;; Formatting the first line of a definition
3141
3142 ;; @deffn, @defvr, @deftp
3143 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3144 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3145 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3146 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3147 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3148 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3149 (defun texinfo-format-deffn (parsed-args)
3150 ;; Generalized function-like, variable-like, or generic data-type entity:
3151 ;; @deffn category name args...
3152 ;; In Info, `Category: name ARGS'
3153 ;; @deftp category name attributes...
3154 ;; `category name attributes...' Note: @deftp args in lower case.
3155 (let ((category (car parsed-args))
3156 (name (car (cdr parsed-args)))
3157 (args (cdr (cdr parsed-args))))
3158 (insert " -- " category ": " name)
3159 (while args
3160 (insert " "
3161 (if (or (= ?& (aref (car args) 0))
3162 (eq (eval (car texinfo-defun-type)) 'deftp-type))
3163 (car args)
3164 (upcase (car args))))
3165 (setq args (cdr args)))))
3166
3167 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
3168 (put 'defun 'texinfo-deffn-formatting-property
3169 'texinfo-format-specialized-defun)
3170 (put 'defunx 'texinfo-deffn-formatting-property
3171 'texinfo-format-specialized-defun)
3172 (put 'defmac 'texinfo-deffn-formatting-property
3173 'texinfo-format-specialized-defun)
3174 (put 'defmacx 'texinfo-deffn-formatting-property
3175 'texinfo-format-specialized-defun)
3176 (put 'defspec 'texinfo-deffn-formatting-property
3177 'texinfo-format-specialized-defun)
3178 (put 'defspecx 'texinfo-deffn-formatting-property
3179 'texinfo-format-specialized-defun)
3180 (put 'defvar 'texinfo-deffn-formatting-property
3181 'texinfo-format-specialized-defun)
3182 (put 'defvarx 'texinfo-deffn-formatting-property
3183 'texinfo-format-specialized-defun)
3184 (put 'defopt 'texinfo-deffn-formatting-property
3185 'texinfo-format-specialized-defun)
3186 (put 'defoptx 'texinfo-deffn-formatting-property
3187 'texinfo-format-specialized-defun)
3188 (defun texinfo-format-specialized-defun (parsed-args)
3189 ;; Specialized function-like or variable-like entity:
3190 ;; @defun name args In Info, `Function: Name ARGS'
3191 ;; @defmac name args In Info, `Macro: Name ARGS'
3192 ;; @defvar name In Info, `Variable: Name'
3193 ;; Use cdr of texinfo-defun-type to determine category:
3194 (let ((category (car (cdr texinfo-defun-type)))
3195 (name (car parsed-args))
3196 (args (cdr parsed-args)))
3197 (insert " -- " category ": " name)
3198 (while args
3199 (insert " "
3200 (if (= ?& (aref (car args) 0))
3201 (car args)
3202 (upcase (car args))))
3203 (setq args (cdr args)))))
3204
3205 ;; @deftypefn, @deftypevr: Generalized typed
3206 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3207 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3208 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3209 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3210 (defun texinfo-format-deftypefn (parsed-args)
3211 ;; Generalized typed-function-like or typed-variable-like entity:
3212 ;; @deftypefn category data-type name args...
3213 ;; In Info, `Category: data-type name args...'
3214 ;; @deftypevr category data-type name
3215 ;; In Info, `Category: data-type name'
3216 ;; Note: args in lower case, unless modified in command line.
3217 (let ((category (car parsed-args))
3218 (data-type (car (cdr parsed-args)))
3219 (name (car (cdr (cdr parsed-args))))
3220 (args (cdr (cdr (cdr parsed-args)))))
3221 (insert " -- " category ": " data-type " " name)
3222 (while args
3223 (insert " " (car args))
3224 (setq args (cdr args)))))
3225
3226 ;; @deftypefun, @deftypevar: Specialized typed
3227 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3228 (put 'deftypefunx 'texinfo-deffn-formatting-property
3229 'texinfo-format-deftypefun)
3230 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3231 (put 'deftypevarx 'texinfo-deffn-formatting-property
3232 'texinfo-format-deftypefun)
3233 (defun texinfo-format-deftypefun (parsed-args)
3234 ;; Specialized typed-function-like or typed-variable-like entity:
3235 ;; @deftypefun data-type name args...
3236 ;; In Info, `Function: data-type name ARGS'
3237 ;; @deftypevar data-type name
3238 ;; In Info, `Variable: data-type name'
3239 ;; Note: args in lower case, unless modified in command line.
3240 ;; Use cdr of texinfo-defun-type to determine category:
3241 (let ((category (car (cdr texinfo-defun-type)))
3242 (data-type (car parsed-args))
3243 (name (car (cdr parsed-args)))
3244 (args (cdr (cdr parsed-args))))
3245 (insert " -- " category ": " data-type " " name)
3246 (while args
3247 (insert " " (car args))
3248 (setq args (cdr args)))))
3249
3250 ;; @defop: Generalized object-oriented
3251 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3252 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3253 (defun texinfo-format-defop (parsed-args)
3254 ;; Generalized object oriented entity:
3255 ;; @defop category class name args...
3256 ;; In Info, `Category on class: name ARG'
3257 ;; Note: args in upper case; use of `on'
3258 (let ((category (car parsed-args))
3259 (class (car (cdr parsed-args)))
3260 (name (car (cdr (cdr parsed-args))))
3261 (args (cdr (cdr (cdr parsed-args)))))
3262 (insert " -- " category " on " class ": " name)
3263 (while args
3264 (insert " " (upcase (car args)))
3265 (setq args (cdr args)))))
3266
3267 ;; @defcv: Generalized object-oriented
3268 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3269 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3270 (defun texinfo-format-defcv (parsed-args)
3271 ;; Generalized object oriented entity:
3272 ;; @defcv category class name
3273 ;; In Info, `Category of class: name'
3274 ;; Note: args in upper case; use of `of'
3275 (let ((category (car parsed-args))
3276 (class (car (cdr parsed-args)))
3277 (name (car (cdr (cdr parsed-args))))
3278 (args (cdr (cdr (cdr parsed-args)))))
3279 (insert " -- " category " of " class ": " name)
3280 (while args
3281 (insert " " (upcase (car args)))
3282 (setq args (cdr args)))))
3283
3284 ;; @defmethod: Specialized object-oriented
3285 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3286 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3287 (defun texinfo-format-defmethod (parsed-args)
3288 ;; Specialized object oriented entity:
3289 ;; @defmethod class name args...
3290 ;; In Info, `Method on class: name ARGS'
3291 ;; Note: args in upper case; use of `on'
3292 ;; Use cdr of texinfo-defun-type to determine category:
3293 (let ((category (car (cdr texinfo-defun-type)))
3294 (class (car parsed-args))
3295 (name (car (cdr parsed-args)))
3296 (args (cdr (cdr parsed-args))))
3297 (insert " -- " category " on " class ": " name)
3298 (while args
3299 (insert " " (upcase (car args)))
3300 (setq args (cdr args)))))
3301
3302 ;; @defivar: Specialized object-oriented
3303 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3304 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3305 (defun texinfo-format-defivar (parsed-args)
3306 ;; Specialized object oriented entity:
3307 ;; @defivar class name
3308 ;; In Info, `Instance variable of class: name'
3309 ;; Note: args in upper case; use of `of'
3310 ;; Use cdr of texinfo-defun-type to determine category:
3311 (let ((category (car (cdr texinfo-defun-type)))
3312 (class (car parsed-args))
3313 (name (car (cdr parsed-args)))
3314 (args (cdr (cdr parsed-args))))
3315 (insert " -- " category " of " class ": " name)
3316 (while args
3317 (insert " " (upcase (car args)))
3318 (setq args (cdr args)))))
3319
3320 \f
3321 ;;; Indexing for definitions
3322
3323 ;; An index entry has three parts: the `entry proper', the node name, and the
3324 ;; line number. Depending on the which command is used, the entry is
3325 ;; formatted differently:
3326 ;;
3327 ;; @defun,
3328 ;; @defmac,
3329 ;; @defspec,
3330 ;; @defvar,
3331 ;; @defopt all use their 1st argument as the entry-proper
3332 ;;
3333 ;; @deffn,
3334 ;; @defvr,
3335 ;; @deftp
3336 ;; @deftypefun
3337 ;; @deftypevar all use their 2nd argument as the entry-proper
3338 ;;
3339 ;; @deftypefn,
3340 ;; @deftypevr both use their 3rd argument as the entry-proper
3341 ;;
3342 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
3343 ;; formatted: NAME on CLASS
3344
3345 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
3346 ;; formatted: NAME on CLASS
3347 ;;
3348 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
3349 ;; formatted: NAME of CLASS
3350 ;;
3351 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
3352 ;; formatted: NAME of CLASS
3353
3354 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
3355 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3356 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
3357 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3358 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
3359 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3360 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
3361 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3362 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
3363 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3364 (defun texinfo-index-defun (parsed-args)
3365 ;; use 1st parsed-arg as entry-proper
3366 ;; `index-list' will be texinfo-findex or the like
3367 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3368 (set index-list
3369 (cons
3370 ;; Three elements: entry-proper, node-name, line-number
3371 (list
3372 (car parsed-args)
3373 texinfo-last-node
3374 ;; Region formatting may not provide last node position.
3375 (if texinfo-last-node-pos
3376 (1+ (count-lines texinfo-last-node-pos (point)))
3377 1))
3378 (symbol-value index-list)))))
3379
3380 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3381 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3382 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3383 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3384 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3385 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3386 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3387 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3388 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3389 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3390 (defun texinfo-index-deffn (parsed-args)
3391 ;; use 2nd parsed-arg as entry-proper
3392 ;; `index-list' will be texinfo-findex or the like
3393 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3394 (set index-list
3395 (cons
3396 ;; Three elements: entry-proper, node-name, line-number
3397 (list
3398 (car (cdr parsed-args))
3399 texinfo-last-node
3400 ;; Region formatting may not provide last node position.
3401 (if texinfo-last-node-pos
3402 (1+ (count-lines texinfo-last-node-pos (point)))
3403 1))
3404 (symbol-value index-list)))))
3405
3406 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3407 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3408 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3409 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3410 (defun texinfo-index-deftypefn (parsed-args)
3411 ;; use 3rd parsed-arg as entry-proper
3412 ;; `index-list' will be texinfo-findex or the like
3413 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3414 (set index-list
3415 (cons
3416 ;; Three elements: entry-proper, node-name, line-number
3417 (list
3418 (car (cdr (cdr parsed-args)))
3419 texinfo-last-node
3420 ;; Region formatting may not provide last node position.
3421 (if texinfo-last-node-pos
3422 (1+ (count-lines texinfo-last-node-pos (point)))
3423 1))
3424 (symbol-value index-list)))))
3425
3426 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3427 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3428 (defun texinfo-index-defmethod (parsed-args)
3429 ;; use 2nd on 1st parsed-arg as entry-proper
3430 ;; `index-list' will be texinfo-findex or the like
3431 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3432 (set index-list
3433 (cons
3434 ;; Three elements: entry-proper, node-name, line-number
3435 (list
3436 (format "%s on %s"
3437 (car (cdr parsed-args))
3438 (car parsed-args))
3439 texinfo-last-node
3440 ;; Region formatting may not provide last node position.
3441 (if texinfo-last-node-pos
3442 (1+ (count-lines texinfo-last-node-pos (point)))
3443 1))
3444 (symbol-value index-list)))))
3445
3446 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
3447 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
3448 (defun texinfo-index-defop (parsed-args)
3449 ;; use 3rd on 2nd parsed-arg as entry-proper
3450 ;; `index-list' will be texinfo-findex or the like
3451 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3452 (set index-list
3453 (cons
3454 ;; Three elements: entry-proper, node-name, line-number
3455 (list
3456 (format "%s on %s"
3457 (car (cdr (cdr parsed-args)))
3458 (car (cdr parsed-args)))
3459 texinfo-last-node
3460 ;; Region formatting may not provide last node position.
3461 (if texinfo-last-node-pos
3462 (1+ (count-lines texinfo-last-node-pos (point)))
3463 1))
3464 (symbol-value index-list)))))
3465
3466 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3467 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3468 (defun texinfo-index-defivar (parsed-args)
3469 ;; use 2nd of 1st parsed-arg as entry-proper
3470 ;; `index-list' will be texinfo-findex or the like
3471 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3472 (set index-list
3473 (cons
3474 ;; Three elements: entry-proper, node-name, line-number
3475 (list
3476 (format "%s of %s"
3477 (car (cdr parsed-args))
3478 (car parsed-args))
3479 texinfo-last-node
3480 ;; Region formatting may not provide last node position.
3481 (if texinfo-last-node-pos
3482 (1+ (count-lines texinfo-last-node-pos (point)))
3483 1))
3484 (symbol-value index-list)))))
3485
3486 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3487 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3488 (defun texinfo-index-defcv (parsed-args)
3489 ;; use 3rd of 2nd parsed-arg as entry-proper
3490 ;; `index-list' will be texinfo-findex or the like
3491 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3492 (set index-list
3493 (cons
3494 ;; Three elements: entry-proper, node-name, line-number
3495 (list
3496 (format "%s of %s"
3497 (car (cdr (cdr parsed-args)))
3498 (car (cdr parsed-args)))
3499 texinfo-last-node
3500 ;; Region formatting may not provide last node position.
3501 (if texinfo-last-node-pos
3502 (1+ (count-lines texinfo-last-node-pos (point)))
3503 1))
3504 (symbol-value index-list)))))
3505
3506 \f
3507 ;;; Properties for definitions
3508
3509 ;; Each definition command has six properties:
3510 ;;
3511 ;; 1. texinfo-deffn-formatting-property to format definition line
3512 ;; 2. texinfo-defun-indexing-property to create index entry
3513 ;; 3. texinfo-format formatting command
3514 ;; 4. texinfo-end end formatting command
3515 ;; 5. texinfo-defun-type type of deffn to format
3516 ;; 6. texinfo-defun-index type of index to use
3517 ;;
3518 ;; The `x' forms of each definition command are used for the second
3519 ;; and subsequent header lines.
3520
3521 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
3522 ;; are listed just before the appropriate formatting and indexing commands.
3523
3524 (put 'deffn 'texinfo-format 'texinfo-format-defun)
3525 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
3526 (put 'deffn 'texinfo-end 'texinfo-end-defun)
3527 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
3528 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
3529 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
3530 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
3531
3532 (put 'defun 'texinfo-format 'texinfo-format-defun)
3533 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
3534 (put 'defun 'texinfo-end 'texinfo-end-defun)
3535 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
3536 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
3537 (put 'defun 'texinfo-defun-index 'texinfo-findex)
3538 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
3539
3540 (put 'defmac 'texinfo-format 'texinfo-format-defun)
3541 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
3542 (put 'defmac 'texinfo-end 'texinfo-end-defun)
3543 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
3544 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
3545 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
3546 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
3547
3548 (put 'defspec 'texinfo-format 'texinfo-format-defun)
3549 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
3550 (put 'defspec 'texinfo-end 'texinfo-end-defun)
3551 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
3552 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
3553 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
3554 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
3555
3556 (put 'defvr 'texinfo-format 'texinfo-format-defun)
3557 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
3558 (put 'defvr 'texinfo-end 'texinfo-end-defun)
3559 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
3560 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
3561 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
3562 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
3563
3564 (put 'defvar 'texinfo-format 'texinfo-format-defun)
3565 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
3566 (put 'defvar 'texinfo-end 'texinfo-end-defun)
3567 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
3568 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
3569 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
3570 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
3571
3572 (put 'defconst 'texinfo-format 'texinfo-format-defun)
3573 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
3574 (put 'defconst 'texinfo-end 'texinfo-end-defun)
3575 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
3576 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
3577 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
3578 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
3579
3580 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
3581 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
3582 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
3583 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
3584 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
3585 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
3586 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
3587
3588 (put 'defopt 'texinfo-format 'texinfo-format-defun)
3589 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
3590 (put 'defopt 'texinfo-end 'texinfo-end-defun)
3591 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
3592 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
3593 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
3594 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
3595
3596 (put 'deftp 'texinfo-format 'texinfo-format-defun)
3597 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
3598 (put 'deftp 'texinfo-end 'texinfo-end-defun)
3599 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
3600 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
3601 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
3602 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
3603
3604 ;;; Object-oriented stuff is a little hairier.
3605
3606 (put 'defop 'texinfo-format 'texinfo-format-defun)
3607 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
3608 (put 'defop 'texinfo-end 'texinfo-end-defun)
3609 (put 'defop 'texinfo-defun-type '('defop-type nil))
3610 (put 'defopx 'texinfo-defun-type '('defop-type nil))
3611 (put 'defop 'texinfo-defun-index 'texinfo-findex)
3612 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
3613
3614 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
3615 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
3616 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
3617 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
3618 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
3619 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
3620 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
3621
3622 (put 'defcv 'texinfo-format 'texinfo-format-defun)
3623 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
3624 (put 'defcv 'texinfo-end 'texinfo-end-defun)
3625 (put 'defcv 'texinfo-defun-type '('defop-type nil))
3626 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
3627 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
3628 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
3629
3630 (put 'defivar 'texinfo-format 'texinfo-format-defun)
3631 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
3632 (put 'defivar 'texinfo-end 'texinfo-end-defun)
3633 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
3634 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
3635 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
3636 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
3637
3638 ;;; Typed functions and variables
3639
3640 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
3641 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
3642 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
3643 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
3644 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
3645 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
3646 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
3647
3648 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
3649 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
3650 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
3651 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
3652 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
3653 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
3654 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
3655
3656 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
3657 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
3658 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
3659 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
3660 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
3661 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
3662 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
3663
3664 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
3665 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
3666 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
3667 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
3668 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
3669 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
3670 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
3671
3672 \f
3673 ;;; @set, @clear, @ifset, @ifclear
3674
3675 ;; If a flag is set with @set FLAG, then text between @ifset and @end
3676 ;; ifset is formatted normally, but if the flag is is cleared with
3677 ;; @clear FLAG, then the text is not formatted; it is ignored.
3678
3679 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
3680 ;; and @end ifclear is formatted normally, but if the flag is is set with
3681 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
3682 ;; is the opposite of @ifset.
3683
3684 ;; If a flag is set to a string with @set FLAG,
3685 ;; replace @value{FLAG} with the string.
3686 ;; If a flag with a value is cleared,
3687 ;; @value{FLAG} is invalid,
3688 ;; as if there had never been any @set FLAG previously.
3689
3690 (put 'clear 'texinfo-format 'texinfo-clear)
3691 (defun texinfo-clear ()
3692 "Clear the value of the flag."
3693 (let* ((arg (texinfo-parse-arg-discard))
3694 (flag (car (read-from-string arg)))
3695 (value (substring arg (cdr (read-from-string arg)))))
3696 (put flag 'texinfo-whether-setp 'flag-cleared)
3697 (put flag 'texinfo-set-value "")))
3698
3699 (put 'set 'texinfo-format 'texinfo-set)
3700 (defun texinfo-set ()
3701 "Set the value of the flag, optionally to a string.
3702 The command `@set foo This is a string.'
3703 sets flag foo to the value: `This is a string.'
3704 The command `@value{foo}' expands to the value."
3705 (let* ((arg (texinfo-parse-arg-discard))
3706 (flag (car (read-from-string arg)))
3707 (value (substring arg (cdr (read-from-string arg)))))
3708 (put flag 'texinfo-whether-setp 'flag-set)
3709 (put flag 'texinfo-set-value value)))
3710
3711 (put 'value 'texinfo-format 'texinfo-value)
3712 (defun texinfo-value ()
3713 "Insert the string to which the flag is set.
3714 The command `@set foo This is a string.'
3715 sets flag foo to the value: `This is a string.'
3716 The command `@value{foo}' expands to the value."
3717 (let ((arg (texinfo-parse-arg-discard)))
3718 (cond ((and
3719 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3720 'flag-set)
3721 (get (car (read-from-string arg)) 'texinfo-set-value))
3722 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
3723 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3724 'flag-cleared)
3725 (insert (format "{No value for \"%s\"}" arg)))
3726 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
3727 (insert (format "{No value for \"%s\"}" arg))))))
3728
3729 (put 'ifset 'texinfo-end 'texinfo-discard-command)
3730 (put 'ifset 'texinfo-format 'texinfo-if-set)
3731 (defun texinfo-if-set ()
3732 "If set, continue formatting; else do not format region up to @end ifset"
3733 (let ((arg (texinfo-parse-arg-discard)))
3734 (cond
3735 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3736 'flag-set)
3737 ;; Format the text (i.e., do not remove it); do nothing here.
3738 ())
3739 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3740 'flag-cleared)
3741 ;; Clear region (i.e., cause the text to be ignored).
3742 (delete-region texinfo-command-start
3743 (progn (re-search-forward "@end ifset[ \t]*\n")
3744 (point))))
3745 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3746 nil)
3747 ;; In this case flag is neither set nor cleared.
3748 ;; Act as if set, i.e. do nothing.
3749 ()))))
3750
3751 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
3752 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
3753 (defun texinfo-if-clear ()
3754 "If clear, continue formatting; if set, do not format up to @end ifset"
3755 (let ((arg (texinfo-parse-arg-discard)))
3756 (cond
3757 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3758 'flag-set)
3759 ;; Clear region (i.e., cause the text to be ignored).
3760 (delete-region texinfo-command-start
3761 (progn (re-search-forward "@end ifclear[ \t]*\n")
3762 (point))))
3763 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3764 'flag-cleared)
3765 ;; Format the text (i.e., do not remove it); do nothing here.
3766 ())
3767 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3768 nil)
3769 ;; In this case flag is neither set nor cleared.
3770 ;; Act as if clear, i.e. do nothing.
3771 ()))))
3772 \f
3773 ;;; @ifeq
3774
3775 (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
3776 (defun texinfo-format-ifeq ()
3777 "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
3778 Otherwise produces no output.
3779
3780 Thus:
3781 @ifeq{ arg1 , arg1 , @code{foo}} bar
3782
3783 ==> `foo' bar.
3784 but
3785 @ifeq{ arg1 , arg2 , @code{foo}} bar
3786
3787 ==> bar
3788
3789 Note that the Texinfo command and its arguments must be arguments to
3790 the @ifeq command."
3791 ;; compare-buffer-substrings does not exist in version 18; don't use
3792 (goto-char texinfo-command-end)
3793 (let* ((case-fold-search t)
3794 (stop (save-excursion (forward-sexp 1) (point)))
3795 start end
3796 ;; @ifeq{arg1, arg2, @command{optional-args}}
3797 (arg1
3798 (progn
3799 (forward-char 1)
3800 (skip-chars-forward " ")
3801 (setq start (point))
3802 (search-forward "," stop t)
3803 (skip-chars-backward ", ")
3804 (buffer-substring start (point))))
3805 (arg2
3806 (progn
3807 (search-forward "," stop t)
3808 (skip-chars-forward " ")
3809 (setq start (point))
3810 (search-forward "," stop t)
3811 (skip-chars-backward ", ")
3812 (buffer-substring start (point))))
3813 (texinfo-command
3814 (progn
3815 (search-forward "," stop t)
3816 (skip-chars-forward " ")
3817 (setq start (point))
3818 (goto-char (1- stop))
3819 (skip-chars-backward " ")
3820 (buffer-substring start (point)))))
3821 (delete-region texinfo-command-start stop)
3822 (if (equal arg1 arg2)
3823 (insert texinfo-command))
3824 (goto-char texinfo-command-start)))
3825
3826 \f
3827 ;;; Process included files: `@include' command
3828
3829 ;; Updated 19 October 1990
3830 ;; In the original version, include files were ignored by Info but
3831 ;; incorporated in to the printed manual. To make references to the
3832 ;; included file, the Texinfo source file has to refer to the included
3833 ;; files using the `(filename)nodename' format for referring to other
3834 ;; Info files. Also, the included files had to be formatted on their
3835 ;; own. It was just like they were another file.
3836
3837 ;; Currently, include files are inserted into the buffer that is
3838 ;; formatted for Info. If large, the resulting info file is split and
3839 ;; tagified. For current include files to work, the master menu must
3840 ;; refer to all the nodes, and the highest level nodes in the include
3841 ;; files must have the correct next, prev, and up pointers.
3842
3843 ;; The included file may have an @setfilename and even an @settitle,
3844 ;; but not an `\input texinfo' line.
3845
3846 ;; Updated 24 March 1993
3847 ;; In order for @raisesections and @lowersections to work, included
3848 ;; files must be inserted into the buffer holding the outer file
3849 ;; before other Info formatting takes place. So @include is no longer
3850 ;; is treated like other @-commands.
3851 (put 'include 'texinfo-format 'texinfo-format-noop)
3852
3853 ;; Original definition:
3854 ;; (defun texinfo-format-include ()
3855 ;; (let ((filename (texinfo-parse-arg-discard))
3856 ;; (default-directory input-directory)
3857 ;; subindex)
3858 ;; (setq subindex
3859 ;; (save-excursion
3860 ;; (progn (find-file
3861 ;; (cond ((file-readable-p (concat filename ".texinfo"))
3862 ;; (concat filename ".texinfo"))
3863 ;; ((file-readable-p (concat filename ".texi"))
3864 ;; (concat filename ".texi"))
3865 ;; ((file-readable-p (concat filename ".tex"))
3866 ;; (concat filename ".tex"))
3867 ;; ((file-readable-p filename)
3868 ;; filename)
3869 ;; (t (error "@include'd file %s not found"
3870 ;; filename))))
3871 ;; (texinfo-format-buffer-1))))
3872 ;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
3873 ;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
3874 ;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
3875 ;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
3876 ;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
3877 ;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
3878 ;;
3879 ;;(defun texinfo-subindex (indexvar file content)
3880 ;; (set indexvar (cons (list 'recurse file content)
3881 ;; (symbol-value indexvar))))
3882
3883 ;; Second definition:
3884 ;; (put 'include 'texinfo-format 'texinfo-format-include)
3885 ;; (defun texinfo-format-include ()
3886 ;; (let ((filename (concat input-directory
3887 ;; (texinfo-parse-arg-discard)))
3888 ;; (default-directory input-directory))
3889 ;; (message "Reading: %s" filename)
3890 ;; (save-excursion
3891 ;; (save-restriction
3892 ;; (narrow-to-region
3893 ;; (point)
3894 ;; (+ (point) (car (cdr (insert-file-contents filename)))))
3895 ;; (goto-char (point-min))
3896 ;; (texinfo-append-refill)
3897 ;; (texinfo-format-convert (point-min) (point-max))))
3898 ;; (setq last-input-buffer input-buffer) ; to bypass setfilename
3899 ;; ))
3900
3901 \f
3902 ;;; Numerous commands do nothing in Info
3903 ;; These commands are defined in texinfo.tex for printed output.
3904
3905 \f
3906 ;;; various noops, such as @b{foo}, that take arguments in braces
3907
3908 (put 'b 'texinfo-format 'texinfo-format-noop)
3909 (put 'i 'texinfo-format 'texinfo-format-noop)
3910 (put 'r 'texinfo-format 'texinfo-format-noop)
3911 (put 't 'texinfo-format 'texinfo-format-noop)
3912 (put 'w 'texinfo-format 'texinfo-format-noop)
3913 (put 'asis 'texinfo-format 'texinfo-format-noop)
3914 (put 'dmn 'texinfo-format 'texinfo-format-noop)
3915 (put 'math 'texinfo-format 'texinfo-format-noop)
3916 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
3917 (defun texinfo-format-noop ()
3918 (insert (texinfo-parse-arg-discard))
3919 (goto-char texinfo-command-start))
3920
3921 ;; @hyphenation command discards an argument within braces
3922 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
3923 (defun texinfo-discard-command-and-arg ()
3924 "Discard both @-command and its argument in braces."
3925 (goto-char texinfo-command-end)
3926 (forward-list 1)
3927 (setq texinfo-command-end (point))
3928 (delete-region texinfo-command-start texinfo-command-end))
3929
3930 \f
3931 ;;; Do nothing commands, such as @smallbook, that have no args and no braces
3932 ;; These must appear on a line of their own
3933
3934 (put 'bye 'texinfo-format 'texinfo-discard-line)
3935 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
3936 (put 'finalout 'texinfo-format 'texinfo-discard-line)
3937 (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
3938 (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
3939 (put 'medbreak 'texinfo-format 'texinfo-discard-line)
3940 (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
3941
3942 \f
3943 ;;; These noop commands discard the rest of the line.
3944
3945 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
3946 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
3947 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
3948 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
3949 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
3950 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
3951 (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
3952 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
3953 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
3954 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
3955 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
3956 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
3957 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
3958 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
3959 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
3960 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
3961 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
3962 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
3963 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
3964 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
3965 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
3966 (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
3967
3968 \f
3969 ;;; Some commands cannot be handled
3970
3971 (defun texinfo-unsupported ()
3972 (error "%s is not handled by texinfo"
3973 (buffer-substring texinfo-command-start texinfo-command-end)))
3974 \f
3975 ;;; Batch formatting
3976
3977 (defun batch-texinfo-format ()
3978 "Runs texinfo-format-buffer on the files remaining on the command line.
3979 Must be used only with -batch, and kills emacs on completion.
3980 Each file will be processed even if an error occurred previously.
3981 For example, invoke
3982 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
3983 (if (not noninteractive)
3984 (error "batch-texinfo-format may only be used -batch."))
3985 (let ((version-control t)
3986 (auto-save-default nil)
3987 (find-file-run-dired nil)
3988 (kept-old-versions 259259)
3989 (kept-new-versions 259259))
3990 (let ((error 0)
3991 file
3992 (files ()))
3993 (while command-line-args-left
3994 (setq file (expand-file-name (car command-line-args-left)))
3995 (cond ((not (file-exists-p file))
3996 (message ">> %s does not exist!" file)
3997 (setq error 1
3998 command-line-args-left (cdr command-line-args-left)))
3999 ((file-directory-p file)
4000 (setq command-line-args-left
4001 (nconc (directory-files file)
4002 (cdr command-line-args-left))))
4003 (t
4004 (setq files (cons file files)
4005 command-line-args-left (cdr command-line-args-left)))))
4006 (while files
4007 (setq file (car files)
4008 files (cdr files))
4009 (condition-case err
4010 (progn
4011 (if buffer-file-name (kill-buffer (current-buffer)))
4012 (find-file file)
4013 (buffer-disable-undo (current-buffer))
4014 (set-buffer-modified-p nil)
4015 (texinfo-mode)
4016 (message "texinfo formatting %s..." file)
4017 (texinfo-format-buffer nil)
4018 (if (buffer-modified-p)
4019 (progn (message "Saving modified %s" (buffer-file-name))
4020 (save-buffer))))
4021 (error
4022 (message ">> Error: %s" (prin1-to-string err))
4023 (message ">> point at")
4024 (let ((s (buffer-substring (point)
4025 (min (+ (point) 100)
4026 (point-max))))
4027 (tem 0))
4028 (while (setq tem (string-match "\n+" s tem))
4029 (setq s (concat (substring s 0 (match-beginning 0))
4030 "\n>> "
4031 (substring s (match-end 0)))
4032 tem (1+ tem)))
4033 (message ">> %s" s))
4034 (setq error 1))))
4035 (kill-emacs error))))
4036
4037 \f
4038 ;;; Place `provide' at end of file.
4039 (provide 'texinfmt)
4040
4041 ;;; texinfmt.el ends here.