1 ;;; ptexinfmt.el -- portable Texinfo formatter.
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 1999 Yoshiki Hayashi <yoshiki@xemacs.org>
6 ;; Copyright (C) 2000 TAKAHASHI Kaoru <kaoru@kaisei.org>
8 ;; Author: TAKAHASHI Kaoru <kaoru@kaisei.org>
9 ;; Yoshiki Hayashi <yoshiki@xemacs.org>
10 ;; Maintainer: TAKAHASHI Kaoru <kaoru@kaisei.org>
11 ;; Created: 7 Jul 2000
12 ;; Keywords: maint, tex, docs, emulation, compatibility
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
32 ;; makeinfo.el (gnujdoc project)
34 ;; Support texinfmt.el 2.32 or later.
44 (defvar ptexinfmt-disable-broken-notice t
45 "If non-nil disable notice, when call `broken-facility'.")
48 (broken-facility texinfo-format-var
49 "Don't perse @COMMAND included @var"
52 (let (texinfo-enclosure-list texinfo-alias-list)
54 (insert "@var{@asis{foo}}\n")
55 (texinfo-format-expand-region (point-min) (point-max))
58 ptexinfmt-disable-broken-notice)
61 (broken-facility texinfo-format-xref
62 "Can't format 1st argument empty @xref."
65 (let (texinfo-enclosure-list texinfo-alias-list)
67 (insert "@xref{, xref, , file}\n")
68 (texinfo-format-expand-region (point-min) (point-max))
71 ptexinfmt-disable-broken-notice)
74 (broken-facility texinfo-format-uref
75 "Parse 2 times @uref argument."
78 (let (texinfo-enclosure-list texinfo-alias-list)
80 (insert "@uref{mailto:foo@@bar.com}\n")
81 (texinfo-format-expand-region (point-min) (point-max))
84 ptexinfmt-disable-broken-notice)
87 ;; Removed Texinfo 3.8
88 (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
89 (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
90 (put 'medbreak 'texinfo-format 'texinfo-discard-line)
91 (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
92 ;; Removed Texinfo 3.9
93 (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
95 ;;; Hardcopy and HTML (discard)
97 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
98 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
101 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
102 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
103 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
104 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
105 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
108 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
109 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
112 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
113 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
114 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
117 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
118 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
119 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
120 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
121 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
122 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
123 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
126 (put 'page 'texinfo-format 'texinfo-discard-line)
127 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
133 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
134 (defun-maybe texinfo-format-dircategory ()
135 (let ((str (texinfo-parse-arg-discard)))
136 (delete-region (point)
138 (skip-chars-forward " ")
140 (insert "INFO-DIR-SECTION " str "\n")))
143 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
144 (defun-maybe texinfo-format-direntry ()
145 (texinfo-push-stack 'direntry nil)
146 (texinfo-discard-line)
147 (insert "START-INFO-DIR-ENTRY\n\n"))
149 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
150 (defun-maybe texinfo-end-direntry ()
151 (texinfo-discard-command)
152 (insert "END-INFO-DIR-ENTRY\n\n")
153 (texinfo-pop-stack 'direntry))
156 ;;; Block Enclosing and Conditional
157 ;; @detailmenu ... @end detailmenu
158 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
159 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
161 ;; @smalldisplay ... @end smalldisplay
162 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
163 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
165 ;; @smallformat ... @end smallformat
166 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
167 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
169 ;; @ifnottex ... @end ifnottex
170 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
171 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
173 ;; @ifnothtml ... @end ifnothtml
174 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
175 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
177 ;; @ifnotinfo ... @end ifnotinfo
178 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
179 (put 'endifnotinfo 'texinfo-format 'texinfo-discard-line)
180 (defun-maybe texinfo-format-ifnotinfo ()
181 (delete-region texinfo-command-start
182 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
185 ;; @html ... @end html
186 (put 'html 'texinfo-format 'texinfo-format-html)
187 (put 'endhtml 'texinfo-format 'texinfo-discard-line)
188 (defun-maybe texinfo-format-html ()
189 (delete-region texinfo-command-start
190 (progn (re-search-forward "@end html[ \t]*\n")
196 ;; @url, @env, @command
197 (put 'url 'texinfo-format 'texinfo-format-code)
198 (put 'env 'texinfo-format 'texinfo-format-code)
199 (put 'command 'texinfo-format 'texinfo-format-code)
202 (put 'acronym 'texinfo-format 'texinfo-format-var)
204 (when-broken texinfo-format-var
205 (fmakunbound 'texinfo-format-var))
206 (defun-maybe texinfo-format-var ()
207 (let ((arg (texinfo-parse-expanded-arg)))
208 (texinfo-discard-command)
209 (insert (upcase arg))))
212 (put 'key 'texinfo-format 'texinfo-format-key)
213 (defun-maybe texinfo-format-key ()
214 (insert (texinfo-parse-arg-discard))
215 (goto-char texinfo-command-start))
217 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
218 (put 'email 'texinfo-format 'texinfo-format-email)
219 (defun-maybe texinfo-format-email ()
220 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
221 Insert < ... > around EMAIL-ADDRESS."
222 (let ((args (texinfo-format-parse-args)))
223 (texinfo-discard-command)
226 (insert (nth 1 args) " <" (nth 0 args) ">")
227 (insert "<" (nth 0 args) ">"))))
230 (put 'option 'texinfo-format 'texinfo-format-option)
231 (defun texinfo-format-option ()
232 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
233 ;; `looking-at-backward' not available in v. 18.57, 20.2
234 ;; searched-for character is a control-H
235 (if (not (search-backward "\010"
236 (save-excursion (beginning-of-line) (point))
238 (insert "`" (texinfo-parse-arg-discard) "'")
239 (insert (texinfo-parse-arg-discard)))
240 (goto-char texinfo-command-start))
244 ;;; Accents and Special characters
245 ;; @pounds{} ==> # Pounds Sterling
246 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
247 (defun-maybe texinfo-format-pounds ()
248 (texinfo-parse-arg-discard)
251 ;; @OE{} ==> OE French-OE-ligature
252 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
253 (defun-maybe texinfo-format-French-OE-ligature ()
254 (insert "OE" (texinfo-parse-arg-discard))
255 (goto-char texinfo-command-start))
258 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
259 (defun-maybe texinfo-format-French-oe-ligature () ; lower case
260 (insert "oe" (texinfo-parse-arg-discard))
261 (goto-char texinfo-command-start))
263 ;; @AA{} ==> AA Scandinavian-A-with-circle
264 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
265 (defun-maybe texinfo-format-Scandinavian-A-with-circle ()
266 (insert "AA" (texinfo-parse-arg-discard))
267 (goto-char texinfo-command-start))
270 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
271 (defun-maybe texinfo-format-Scandinavian-a-with-circle () ; lower case
272 (insert "aa" (texinfo-parse-arg-discard))
273 (goto-char texinfo-command-start))
275 ;; @AE{} ==> AE Latin-Scandinavian-AE
276 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
277 (defun-maybe texinfo-format-Latin-Scandinavian-AE ()
278 (insert "AE" (texinfo-parse-arg-discard))
279 (goto-char texinfo-command-start))
282 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
283 (defun-maybe texinfo-format-Latin-Scandinavian-ae () ; lower case
284 (insert "ae" (texinfo-parse-arg-discard))
285 (goto-char texinfo-command-start))
287 ;; @ss{} ==> ss German-sharp-S
288 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
289 (defun-maybe texinfo-format-German-sharp-S ()
290 (insert "ss" (texinfo-parse-arg-discard))
291 (goto-char texinfo-command-start))
293 ;; @questiondown{} ==> ? upside-down-question-mark
294 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
295 (defun-maybe texinfo-format-upside-down-question-mark ()
296 (insert "?" (texinfo-parse-arg-discard))
297 (goto-char texinfo-command-start))
299 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
300 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
301 (defun-maybe texinfo-format-upside-down-exclamation-mark ()
302 (insert "!" (texinfo-parse-arg-discard))
303 (goto-char texinfo-command-start))
305 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
306 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
307 (defun-maybe texinfo-format-Polish-suppressed-L ()
308 (insert (texinfo-parse-arg-discard) "/L")
309 (goto-char texinfo-command-start))
311 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
312 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
313 (defun-maybe texinfo-format-Polish-suppressed-l-lower-case ()
314 (insert (texinfo-parse-arg-discard) "/l")
315 (goto-char texinfo-command-start))
317 ;; @O{} ==> O/ Scandinavian O-with-slash
318 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
319 (defun-maybe texinfo-format-Scandinavian-O-with-slash ()
320 (insert (texinfo-parse-arg-discard) "O/")
321 (goto-char texinfo-command-start))
323 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
324 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
325 (defun-maybe texinfo-format-Scandinavian-o-with-slash-lower-case ()
326 (insert (texinfo-parse-arg-discard) "o/")
327 (goto-char texinfo-command-start))
329 ;; @,{c} ==> c, cedilla accent
330 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
331 (defun-maybe texinfo-format-cedilla-accent ()
332 (insert (texinfo-parse-arg-discard) ",")
333 (goto-char texinfo-command-start))
336 ;; @dotaccent{o} ==> .o overdot-accent
337 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
338 (defun-maybe texinfo-format-overdot-accent ()
339 (insert "." (texinfo-parse-arg-discard))
340 (goto-char texinfo-command-start))
342 ;; @ubaraccent{o} ==> _o underbar-accent
343 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
344 (defun-maybe texinfo-format-underbar-accent ()
345 (insert "_" (texinfo-parse-arg-discard))
346 (goto-char texinfo-command-start))
348 ;; @udotaccent{o} ==> o-. underdot-accent
349 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
350 (defun-maybe texinfo-format-underdot-accent ()
351 (insert (texinfo-parse-arg-discard) "-.")
352 (goto-char texinfo-command-start))
354 ;; @H{o} ==> ""o long Hungarian umlaut
355 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
356 (defun-maybe texinfo-format-long-Hungarian-umlaut ()
357 (insert "\"\"" (texinfo-parse-arg-discard))
358 (goto-char texinfo-command-start))
360 ;; @ringaccent{o} ==> *o ring accent
361 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
362 (defun-maybe texinfo-format-ring-accent ()
363 (insert "*" (texinfo-parse-arg-discard))
364 (goto-char texinfo-command-start))
366 ;; @tieaccent{oo} ==> [oo tie after accent
367 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
368 (defun-maybe texinfo-format-tie-after-accent ()
369 (insert "[" (texinfo-parse-arg-discard))
370 (goto-char texinfo-command-start))
372 ;; @u{o} ==> (o breve accent
373 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
374 (defun-maybe texinfo-format-breve-accent ()
375 (insert "(" (texinfo-parse-arg-discard))
376 (goto-char texinfo-command-start))
378 ;; @v{o} ==> <o hacek accent
379 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
380 (defun-maybe texinfo-format-hacek-accent ()
381 (insert "<" (texinfo-parse-arg-discard))
382 (goto-char texinfo-command-start))
384 ;; @dotless{i} ==> i dotless i and dotless j
385 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
386 (defun-maybe texinfo-format-dotless ()
387 (insert (texinfo-parse-arg-discard))
388 (goto-char texinfo-command-start))
394 (put 'ref 'texinfo-format 'texinfo-format-xref)
396 (when-broken texinfo-format-xref
397 (fmakunbound 'texinfo-format-xref))
398 (defun-maybe texinfo-format-xref ()
399 (let ((args (texinfo-format-parse-args)))
400 (texinfo-discard-command)
402 (let ((fname (or (nth 1 args) (nth 2 args))))
403 (if (null (or fname (nth 3 args)))
404 (insert (nth 0 args) "::")
405 (insert (or fname (nth 0 args)) ": ")
407 (insert "(" (nth 3 args) ")"))
408 (unless (null (nth 0 args))
409 (insert (nth 0 args)))))))
412 (put 'uref 'texinfo-format 'texinfo-format-uref)
413 (when-broken texinfo-format-uref
414 (fmakunbound 'texinfo-format-uref))
415 (defun-maybe texinfo-format-uref ()
416 "Format URL and optional URL-TITLE.
417 Insert ` ... ' around URL if no URL-TITLE argument;
418 otherwise, insert URL-TITLE followed by URL in parentheses."
419 (let ((args (texinfo-format-parse-args)))
420 (texinfo-discard-command)
423 (insert (nth 1 args) " (" (nth 0 args) ")")
424 (insert "`" (nth 0 args) "'"))))
428 ;;; New command definition
429 ;; @alias NEW=EXISTING
430 (put 'alias 'texinfo-format 'texinfo-alias)
431 (defun-maybe texinfo-alias ()
432 (let ((start (1- (point)))
434 (skip-chars-forward " ")
435 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
436 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
437 (error "Invalid alias command")
438 (setq texinfo-alias-list
441 (buffer-substring (match-beginning 1) (match-end 1))
442 (buffer-substring (match-beginning 2) (match-end 2)))
444 (texinfo-discard-command))))
446 ;; @definfoenclose NEWCMD, BEFORE, AFTER
451 ;; @image{FILENAME, [WIDTH], [HEIGHT]}
452 (put 'image 'texinfo-format 'texinfo-format-image)
453 (defun-maybe texinfo-format-image ()
454 (let ((args (texinfo-format-parse-args)) ; parse FILENAME?
456 (when (null (nth 0 args))
457 (error "Invalid image command"))
458 (texinfo-discard-command)
459 ;; makeinfo uses FILENAME.txt
460 (setq filename (format "%s.txt" (nth 0 args)))
461 (message "Reading included file: %s" filename)
462 ;; verbatim for Info output
463 (goto-char (+ (point) (cadr (insert-file-contents filename))))
464 (message "Reading included file: %s...done" filename)))
471 ;;; @multitable ... @end multitable
472 (defvar-maybe texinfo-extra-inter-column-width 0
473 "*Number of extra spaces between entries (columns) in @multitable.")
475 (defvar-maybe texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
476 (defvar-maybe texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
478 ;; These commands are defined in texinfo.tex for printed output.
479 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
480 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
481 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
482 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
484 (put 'multitable 'texinfo-format 'texinfo-multitable)
486 (defun-maybe texinfo-multitable ()
487 "Produce multi-column tables."
489 ;; This function pushes information onto the `texinfo-stack'.
490 ;; A stack element consists of:
491 ;; - type-of-command, i.e., multitable
492 ;; - the information about column widths, and
493 ;; - the position of texinfo-command-start.
494 ;; e.g., ('multitable (1 2 3 4) 123)
495 ;; The command line is then deleted.
498 ;; push width information on stack
499 (texinfo-multitable-widths))
500 (texinfo-discard-line-with-args))
502 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
503 (defun-maybe texinfo-end-multitable ()
504 "Discard the @end multitable line and pop the stack of multitable."
505 (texinfo-discard-command)
506 (texinfo-pop-stack 'multitable))
508 (defun-maybe texinfo-multitable-widths ()
509 "Return list of widths of each column in a multi-column table."
510 (let (texinfo-multitable-width-list)
512 ;; @multitable @columnfractions .25 .3 .45
515 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
516 ;; Place point before first argument
517 (skip-chars-forward " \t")
519 ;; Check for common misspelling
520 ((looking-at "@columnfraction ")
521 (error "In @multitable, @columnfractions misspelled"))
522 ;; Case 1: @columnfractions .25 .3 .45
523 ((looking-at "@columnfractions")
526 (setq texinfo-multitable-width-list
530 (* fill-column (read (get-buffer (current-buffer))))))
531 texinfo-multitable-width-list))))
533 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
535 (let ((start-of-templates (point)))
537 (skip-chars-forward " \t")
538 (let* ((start-of-template (1+ (point)))
540 ;; forward-sexp works with braces in Texinfo mode
541 (progn (forward-sexp 1) (1- (point)))))
542 (setq texinfo-multitable-width-list
543 (cons (- (progn (goto-char end-of-template) (current-column))
544 (progn (goto-char start-of-template) (current-column)))
545 texinfo-multitable-width-list))
546 ;; Remove carriage return from within a template, if any.
547 ;; This helps those those who want to use more than
548 ;; one line's worth of words in @multitable line.
549 (narrow-to-region start-of-template end-of-template)
550 (goto-char (point-min))
551 (while (search-forward "
554 (goto-char (point-max))
561 "You probably need to specify column widths for @multitable correctly.")))
562 ;; Check whether columns fit on page.
563 (let ((desired-columns
565 ;; between column spaces
566 (length texinfo-multitable-width-list)
567 ;; additional between column spaces, if any
568 texinfo-extra-inter-column-width
569 ;; sum of spaces for each entry
570 (apply '+ texinfo-multitable-width-list))))
571 (if (> desired-columns fill-column)
574 "Multi-column table width, %d chars, is greater than page width, %d chars."
575 desired-columns fill-column))))
576 texinfo-multitable-width-list))
578 ;; @item A1 @tab A2 @tab A3
579 (defun-maybe texinfo-multitable-extract-row ()
580 "Return multitable row, as a string.
581 End of row is beginning of next @item or beginning of @end.
582 Cells within rows are separated by @tab."
583 (skip-chars-forward " \t")
584 (let* ((start (point))
586 (re-search-forward "@item\\|@end")
587 (match-beginning 0)))
588 (row (progn (goto-char end)
589 (skip-chars-backward " ")
590 ;; remove whitespace at end of argument
591 (delete-region (point) end)
592 (buffer-substring start (point)))))
593 (delete-region texinfo-command-start end)
596 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
597 (defun-maybe texinfo-multitable-item ()
598 "Format a row within a multicolumn table.
599 Cells in row are separated by @tab.
600 Widths of cells are specified by the arguments in the @multitable line.
601 All cells are made to be the same height.
602 This command is executed when texinfmt sees @item inside @multitable."
603 (let ((original-buffer (current-buffer))
604 (table-widths (reverse (car (cdr (car texinfo-stack)))))
605 (existing-fill-column fill-column)
609 (table-entry-height 0)
610 ;; unformatted row looks like: A1 @tab A2 @tab A3
611 ;; extract-row command deletes the source line in the table.
612 (unformated-row (texinfo-multitable-extract-row)))
613 ;; Use a temporary buffer
614 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
615 (delete-region (point-min) (point-max))
616 (insert unformated-row)
617 (goto-char (point-min))
618 ;; 1. Check for correct number of @tab in line.
619 (let ((tab-number 1)) ; one @tab between two columns
620 (while (search-forward "@tab" nil t)
621 (setq tab-number (1+ tab-number)))
622 (if (/= tab-number (length table-widths))
623 (error "Wrong number of @tab's in a @multitable row.")))
624 (goto-char (point-min))
625 ;; 2. Format each cell, and copy to a rectangle
626 ;; buffer looks like this: A1 @tab A2 @tab A3
627 ;; Cell #1: format up to @tab
628 ;; Cell #2: format up to @tab
629 ;; Cell #3: format up to eob
632 (setq end (save-excursion
633 (if (search-forward "@tab" nil 'move)
634 ;; Delete the @tab command, including the @-sign
637 (progn (forward-word -1) (1- (point)))))
639 ;; Set fill-column *wider* than needed to produce inter-column space
640 (setq fill-column (+ 1
641 texinfo-extra-inter-column-width
642 (nth table-column table-widths)))
643 (narrow-to-region start end)
644 ;; Remove whitespace before and after entry.
645 (skip-chars-forward " ")
646 (delete-region (point) (save-excursion (beginning-of-line) (point)))
647 (goto-char (point-max))
648 (skip-chars-backward " ")
649 (delete-region (point) (save-excursion (end-of-line) (point)))
650 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
651 ;; does not see an unterminated @multitable.
652 (let (texinfo-stack) ; nil
653 (texinfo-format-scan))
654 (let (fill-prefix) ; no fill prefix
655 (fill-region (point-min) (point-max)))
656 (setq table-entry-height
657 (max table-entry-height (count-lines (point-min) (point-max))))
658 ;; 3. Move point to end of bottom line, and pad that line to fill column.
659 (goto-char (point-min))
660 (forward-line (1- table-entry-height))
661 (let* ((beg (point)) ; beginning of line
662 ;; add one more space for inter-column spacing
666 (progn (end-of-line) (current-column)))))) ; end of existing line
668 (if (> needed-whitespace 0) needed-whitespace 1)
670 ;; now, put formatted cell into a rectangle
671 (set (intern (concat texinfo-multitable-rectangle-name
672 (int-to-string table-column)))
673 (extract-rectangle (point-min) (point)))
674 (delete-region (point-min) (point))
675 (goto-char (point-max))
676 (setq table-column (1+ table-column))
678 ;; 4. Add extra lines to rectangles so all are of same height
679 (let ((total-number-of-columns table-column)
682 (while (> table-column 0)
683 (let ((this-rectangle (int-to-string table-column)))
684 (while (< (length this-rectangle) table-entry-height)
685 (setq this-rectangle (append this-rectangle '("")))))
686 (setq table-column (1- table-column)))
687 ;; 5. Insert formatted rectangles in original buffer
688 (switch-to-buffer original-buffer)
689 (open-line table-entry-height)
690 (while (< column-number total-number-of-columns)
694 (concat texinfo-multitable-rectangle-name
695 (int-to-string column-number)))))
698 (setq column-number (1+ column-number))))
699 (kill-buffer texinfo-multitable-buffer-name)
700 (setq fill-column existing-fill-column)))
702 ;;; ptexinfmt.el ends here