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, 2001, 2002 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.
42 (defvar ptexinfmt-disable-broken-notice-flag t
43 "If non-nil disable notice, when call `broken-facility'.
44 This is NO-NOTICE argument in `broken-facility'.")
47 (broken-facility texinfo-format-printindex
48 "Can't sort on Mule for Windows."
49 (if (and (memq system-type '(windows-nt ms-dos))
50 ;;; I don't know version threshold.
51 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
52 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
55 ptexinfmt-disable-broken-notice-flag)
58 (broken-facility texinfo-format-var
59 "Don't perse @var argument."
62 (let (texinfo-enclosure-list texinfo-alias-list)
64 (insert "@var{@asis{foo}}\n")
65 (texinfo-format-expand-region (point-min) (point-max))
68 ptexinfmt-disable-broken-notice-flag)
71 (broken-facility texinfo-format-xref
72 "Can't format @xref, 1st argument is empty."
75 (let (texinfo-enclosure-list texinfo-alias-list)
77 (insert "@xref{, xref, , file}\n")
78 (texinfo-format-expand-region (point-min) (point-max))
81 ptexinfmt-disable-broken-notice-flag)
84 (broken-facility texinfo-format-uref
85 "Parse twice @uref argument."
88 (let (texinfo-enclosure-list texinfo-alias-list)
90 (insert "@uref{mailto:foo@@bar.com}\n")
91 (texinfo-format-expand-region (point-min) (point-max))
94 ptexinfmt-disable-broken-notice-flag)
97 (broken-facility texinfo-multitable-widths
98 "`texinfo-multitable-widths' unsupport wide-char."
99 (if (fboundp 'texinfo-multitable-widths)
101 (let ((str "
\e$BI}9-J8;z
\e(B"))
103 (insert (format " {%s}\n" str))
104 (goto-char (point-min))
105 (if (= (car (texinfo-multitable-widths)) (length str))
108 ;; function definition is void
110 ptexinfmt-disable-broken-notice-flag)
112 (broken-facility texinfo-multitable-item
113 "`texinfo-multitable-item' unsupport wide-char."
114 (if-broken texinfo-multitable-widths nil t)
115 ptexinfmt-disable-broken-notice-flag)
118 ;;; Hardcopy and HTML (discard)
120 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
121 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
122 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
125 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
126 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
127 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
128 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
129 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
130 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
131 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
134 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
135 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
138 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
139 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
140 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
143 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
144 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
145 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
146 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
147 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
148 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
149 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
152 (put 'page 'texinfo-format 'texinfo-discard-line)
153 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
159 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
160 (defun-maybe texinfo-format-dircategory ()
161 (let ((str (texinfo-parse-arg-discard)))
162 (delete-region (point)
164 (skip-chars-forward " ")
166 (insert "INFO-DIR-SECTION " str "\n")))
169 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
170 (defun-maybe texinfo-format-direntry ()
171 (texinfo-push-stack 'direntry nil)
172 (texinfo-discard-line)
173 (insert "START-INFO-DIR-ENTRY\n"))
175 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
176 (defun-maybe texinfo-end-direntry ()
177 (texinfo-discard-command)
178 (insert "END-INFO-DIR-ENTRY\n\n")
179 (texinfo-pop-stack 'direntry))
183 ;; @detailmenu ... @end detailmenu
184 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
185 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
187 ;; @smalldisplay ... @end smalldisplay
188 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
189 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
191 ;; @smallformat ... @end smallformat
192 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
193 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
195 ;; @cartouche ... @end cartouche
196 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
197 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
201 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
202 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
203 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
205 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
206 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
207 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
209 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
210 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
211 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
214 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
215 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
216 (defun-maybe texinfo-format-ifnotinfo ()
217 (delete-region texinfo-command-start
218 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
221 ;; @html ... @end html (makeinfo 3.11 or later)
222 (put 'html 'texinfo-format 'texinfo-format-html)
223 (defun-maybe texinfo-format-html ()
224 (delete-region texinfo-command-start
225 (progn (re-search-forward "@end html[ \t]*\n")
228 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
229 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
230 (defun texinfo-format-ifhtml ()
231 (delete-region texinfo-command-start
232 (progn (re-search-forward "@end ifhtml[ \t]*\n")
235 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
236 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
237 (defun-maybe texinfo-format-ifplaintext ()
238 (delete-region texinfo-command-start
239 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
245 ;; @url, @env, @command
246 (put 'url 'texinfo-format 'texinfo-format-code)
247 (put 'env 'texinfo-format 'texinfo-format-code)
248 (put 'command 'texinfo-format 'texinfo-format-code)
251 (put 'acronym 'texinfo-format 'texinfo-format-var)
253 (when-broken texinfo-format-var
254 (fmakunbound 'texinfo-format-var))
255 (defun-maybe texinfo-format-var ()
256 (let ((arg (texinfo-parse-expanded-arg)))
257 (texinfo-discard-command)
258 (insert (upcase arg))))
261 (put 'key 'texinfo-format 'texinfo-format-key)
262 (defun-maybe texinfo-format-key ()
263 (insert (texinfo-parse-arg-discard))
264 (goto-char texinfo-command-start))
266 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
267 (put 'email 'texinfo-format 'texinfo-format-email)
268 (defun-maybe texinfo-format-email ()
269 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
270 Insert < ... > around EMAIL-ADDRESS."
271 (let ((args (texinfo-format-parse-args)))
272 (texinfo-discard-command)
275 (insert (nth 1 args) " <" (nth 0 args) ">")
276 (insert "<" (nth 0 args) ">"))))
279 (put 'option 'texinfo-format 'texinfo-format-option)
280 (defun texinfo-format-option ()
281 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
282 ;; `looking-at-backward' not available in v. 18.57, 20.2
283 ;; searched-for character is a control-H
284 (if (not (search-backward "\010"
285 (save-excursion (beginning-of-line) (point))
287 (insert "`" (texinfo-parse-arg-discard) "'")
288 (insert (texinfo-parse-arg-discard)))
289 (goto-char texinfo-command-start))
293 ;;; Accents and Special characters
294 ;; @pounds{} ==> # Pounds Sterling
295 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
296 (defun-maybe texinfo-format-pounds ()
297 (texinfo-parse-arg-discard)
300 ;; @OE{} ==> OE French-OE-ligature
301 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
302 (defun-maybe texinfo-format-French-OE-ligature ()
303 (insert "OE" (texinfo-parse-arg-discard))
304 (goto-char texinfo-command-start))
307 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
308 (defun-maybe texinfo-format-French-oe-ligature () ; lower case
309 (insert "oe" (texinfo-parse-arg-discard))
310 (goto-char texinfo-command-start))
312 ;; @AA{} ==> AA Scandinavian-A-with-circle
313 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
314 (defun-maybe texinfo-format-Scandinavian-A-with-circle ()
315 (insert "AA" (texinfo-parse-arg-discard))
316 (goto-char texinfo-command-start))
319 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
320 (defun-maybe texinfo-format-Scandinavian-a-with-circle () ; lower case
321 (insert "aa" (texinfo-parse-arg-discard))
322 (goto-char texinfo-command-start))
324 ;; @AE{} ==> AE Latin-Scandinavian-AE
325 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
326 (defun-maybe texinfo-format-Latin-Scandinavian-AE ()
327 (insert "AE" (texinfo-parse-arg-discard))
328 (goto-char texinfo-command-start))
331 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
332 (defun-maybe texinfo-format-Latin-Scandinavian-ae () ; lower case
333 (insert "ae" (texinfo-parse-arg-discard))
334 (goto-char texinfo-command-start))
336 ;; @ss{} ==> ss German-sharp-S
337 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
338 (defun-maybe texinfo-format-German-sharp-S ()
339 (insert "ss" (texinfo-parse-arg-discard))
340 (goto-char texinfo-command-start))
342 ;; @questiondown{} ==> ? upside-down-question-mark
343 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
344 (defun-maybe texinfo-format-upside-down-question-mark ()
345 (insert "?" (texinfo-parse-arg-discard))
346 (goto-char texinfo-command-start))
348 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
349 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
350 (defun-maybe texinfo-format-upside-down-exclamation-mark ()
351 (insert "!" (texinfo-parse-arg-discard))
352 (goto-char texinfo-command-start))
354 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
355 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
356 (defun-maybe texinfo-format-Polish-suppressed-L ()
357 (insert (texinfo-parse-arg-discard) "/L")
358 (goto-char texinfo-command-start))
360 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
361 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
362 (defun-maybe texinfo-format-Polish-suppressed-l-lower-case ()
363 (insert (texinfo-parse-arg-discard) "/l")
364 (goto-char texinfo-command-start))
366 ;; @O{} ==> O/ Scandinavian O-with-slash
367 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
368 (defun-maybe texinfo-format-Scandinavian-O-with-slash ()
369 (insert (texinfo-parse-arg-discard) "O/")
370 (goto-char texinfo-command-start))
372 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
373 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
374 (defun-maybe texinfo-format-Scandinavian-o-with-slash-lower-case ()
375 (insert (texinfo-parse-arg-discard) "o/")
376 (goto-char texinfo-command-start))
378 ;; @,{c} ==> c, cedilla accent
379 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
380 (defun-maybe texinfo-format-cedilla-accent ()
381 (insert (texinfo-parse-arg-discard) ",")
382 (goto-char texinfo-command-start))
385 ;; @dotaccent{o} ==> .o overdot-accent
386 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
387 (defun-maybe texinfo-format-overdot-accent ()
388 (insert "." (texinfo-parse-arg-discard))
389 (goto-char texinfo-command-start))
391 ;; @ubaraccent{o} ==> _o underbar-accent
392 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
393 (defun-maybe texinfo-format-underbar-accent ()
394 (insert "_" (texinfo-parse-arg-discard))
395 (goto-char texinfo-command-start))
397 ;; @udotaccent{o} ==> o-. underdot-accent
398 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
399 (defun-maybe texinfo-format-underdot-accent ()
400 (insert (texinfo-parse-arg-discard) "-.")
401 (goto-char texinfo-command-start))
403 ;; @H{o} ==> ""o long Hungarian umlaut
404 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
405 (defun-maybe texinfo-format-long-Hungarian-umlaut ()
406 (insert "\"\"" (texinfo-parse-arg-discard))
407 (goto-char texinfo-command-start))
409 ;; @ringaccent{o} ==> *o ring accent
410 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
411 (defun-maybe texinfo-format-ring-accent ()
412 (insert "*" (texinfo-parse-arg-discard))
413 (goto-char texinfo-command-start))
415 ;; @tieaccent{oo} ==> [oo tie after accent
416 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
417 (defun-maybe texinfo-format-tie-after-accent ()
418 (insert "[" (texinfo-parse-arg-discard))
419 (goto-char texinfo-command-start))
421 ;; @u{o} ==> (o breve accent
422 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
423 (defun-maybe texinfo-format-breve-accent ()
424 (insert "(" (texinfo-parse-arg-discard))
425 (goto-char texinfo-command-start))
427 ;; @v{o} ==> <o hacek accent
428 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
429 (defun-maybe texinfo-format-hacek-accent ()
430 (insert "<" (texinfo-parse-arg-discard))
431 (goto-char texinfo-command-start))
433 ;; @dotless{i} ==> i dotless i and dotless j
434 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
435 (defun-maybe texinfo-format-dotless ()
436 (insert (texinfo-parse-arg-discard))
437 (goto-char texinfo-command-start))
440 (put '\. 'texinfo-format 'texinfo-format-\.)
441 (defun-maybe texinfo-format-\. ()
442 (texinfo-discard-command)
446 (put '\: 'texinfo-format 'texinfo-format-\:)
447 (defun-maybe texinfo-format-\: ()
448 (texinfo-discard-command))
451 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
452 (defun-maybe texinfo-format-soft-hyphen ()
453 (texinfo-discard-command))
458 (put 'ref 'texinfo-format 'texinfo-format-xref)
460 (when-broken texinfo-format-xref
461 (fmakunbound 'texinfo-format-xref))
462 (defun-maybe texinfo-format-xref ()
463 (let ((args (texinfo-format-parse-args)))
464 (texinfo-discard-command)
466 (let ((fname (or (nth 1 args) (nth 2 args))))
467 (if (null (or fname (nth 3 args)))
468 (insert (nth 0 args) "::")
469 (insert (or fname (nth 0 args)) ": ")
471 (insert "(" (nth 3 args) ")"))
472 (unless (null (nth 0 args))
473 (insert (nth 0 args)))))))
476 (put 'uref 'texinfo-format 'texinfo-format-uref)
477 (when-broken texinfo-format-uref
478 (fmakunbound 'texinfo-format-uref))
479 (defun-maybe texinfo-format-uref ()
480 "Format URL and optional URL-TITLE.
481 Insert ` ... ' around URL if no URL-TITLE argument;
482 otherwise, insert URL-TITLE followed by URL in parentheses."
483 (let ((args (texinfo-format-parse-args)))
484 (texinfo-discard-command)
487 (insert (nth 1 args) " (" (nth 0 args) ")")
488 (insert "`" (nth 0 args) "'"))))
491 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
492 (defun-maybe texinfo-format-inforef ()
493 (let ((args (texinfo-format-parse-args)))
494 (texinfo-discard-command)
496 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
497 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
502 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
503 ;; - Info-tagify suport @anthor-*-refill.
504 ;; - info.el support Ref in Tag table.
505 (unless (get 'anchor 'texinfo-format)
506 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
510 ;;; New command definition
511 ;; @alias NEW=EXISTING
512 (put 'alias 'texinfo-format 'texinfo-alias)
513 (defun-maybe texinfo-alias ()
514 (let ((start (1- (point)))
516 (skip-chars-forward " ")
517 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
518 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
519 (error "Invalid alias command")
520 (setq texinfo-alias-list
523 (buffer-substring (match-beginning 1) (match-end 1))
524 (buffer-substring (match-beginning 2) (match-end 2)))
526 (texinfo-discard-command))))
530 ;; @image{FILENAME, [WIDTH], [HEIGHT]}
531 (put 'image 'texinfo-format 'texinfo-format-image)
532 (defun-maybe texinfo-format-image ()
533 ;; I don't know makeinfo parse FILENAME.
534 (let ((args (texinfo-format-parse-args))
536 (when (null (nth 0 args))
537 (error "Invalid image command"))
538 (texinfo-discard-command)
539 ;; makeinfo uses FILENAME.txt
540 (setq filename (format "%s.txt" (nth 0 args)))
541 (message "Reading included file: %s" filename)
542 ;; verbatim for Info output
543 (goto-char (+ (point) (cadr (insert-file-contents filename))))
544 (message "Reading included file: %s...done" filename)))
551 ;;; @multitable ... @end multitable
552 (defvar-maybe texinfo-extra-inter-column-width 0
553 "*Number of extra spaces between entries (columns) in @multitable.")
555 (defvar-maybe texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
556 (defvar-maybe texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
558 ;; These commands are defined in texinfo.tex for printed output.
559 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
560 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
561 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
562 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
564 (put 'multitable 'texinfo-format 'texinfo-multitable)
566 (defun-maybe texinfo-multitable ()
567 "Produce multi-column tables."
569 ;; This function pushes information onto the `texinfo-stack'.
570 ;; A stack element consists of:
571 ;; - type-of-command, i.e., multitable
572 ;; - the information about column widths, and
573 ;; - the position of texinfo-command-start.
574 ;; e.g., ('multitable (1 2 3 4) 123)
575 ;; The command line is then deleted.
578 ;; push width information on stack
579 (texinfo-multitable-widths))
580 (texinfo-discard-line-with-args))
582 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
583 (defun-maybe texinfo-end-multitable ()
584 "Discard the @end multitable line and pop the stack of multitable."
585 (texinfo-discard-command)
586 (texinfo-pop-stack 'multitable))
588 (when-broken texinfo-multitable-widths
589 (fmakunbound 'texinfo-multitable-widths))
591 (defun-maybe texinfo-multitable-widths ()
592 "Return list of widths of each column in a multi-column table."
593 (let (texinfo-multitable-width-list)
595 ;; @multitable @columnfractions .25 .3 .45
598 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
599 ;; Place point before first argument
600 (skip-chars-forward " \t")
602 ;; Check for common misspelling
603 ((looking-at "@columnfraction ")
604 (error "In @multitable, @columnfractions misspelled"))
605 ;; Case 1: @columnfractions .25 .3 .45
606 ((looking-at "@columnfractions")
609 (setq texinfo-multitable-width-list
613 (* fill-column (read (get-buffer (current-buffer))))))
614 texinfo-multitable-width-list))))
616 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
618 (let ((start-of-templates (point)))
620 (skip-chars-forward " \t")
621 (let* ((start-of-template (1+ (point)))
623 ;; forward-sexp works with braces in Texinfo mode
624 (progn (forward-sexp 1) (1- (point)))))
625 (setq texinfo-multitable-width-list
626 (cons (- (progn (goto-char end-of-template) (current-column))
627 (progn (goto-char start-of-template) (current-column)))
628 texinfo-multitable-width-list))
629 ;; Remove carriage return from within a template, if any.
630 ;; This helps those those who want to use more than
631 ;; one line's worth of words in @multitable line.
632 (narrow-to-region start-of-template end-of-template)
633 (goto-char (point-min))
634 (while (search-forward "
637 (goto-char (point-max))
644 "You probably need to specify column widths for @multitable correctly")))
645 ;; Check whether columns fit on page.
646 (let ((desired-columns
648 ;; between column spaces
649 (length texinfo-multitable-width-list)
650 ;; additional between column spaces, if any
651 texinfo-extra-inter-column-width
652 ;; sum of spaces for each entry
653 (apply '+ texinfo-multitable-width-list))))
654 (if (> desired-columns fill-column)
657 "Multi-column table width, %d chars, is greater than page width, %d chars."
658 desired-columns fill-column))))
659 texinfo-multitable-width-list))
661 ;; @item A1 @tab A2 @tab A3
662 (defun-maybe texinfo-multitable-extract-row ()
663 "Return multitable row, as a string.
664 End of row is beginning of next @item or beginning of @end.
665 Cells within rows are separated by @tab."
666 (skip-chars-forward " \t")
667 (let* ((start (point))
669 (re-search-forward "@item\\|@end")
670 (match-beginning 0)))
671 (row (progn (goto-char end)
672 (skip-chars-backward " ")
673 ;; remove whitespace at end of argument
674 (delete-region (point) end)
675 (buffer-substring start (point)))))
676 (delete-region texinfo-command-start end)
679 (when-broken texinfo-multitable-item
680 (fmakunbound 'texinfo-multitable-item))
682 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
683 (defun-maybe texinfo-multitable-item ()
684 "Format a row within a multicolumn table.
685 Cells in row are separated by @tab.
686 Widths of cells are specified by the arguments in the @multitable line.
687 All cells are made to be the same height.
688 This command is executed when texinfmt sees @item inside @multitable."
689 (let ((original-buffer (current-buffer))
690 (table-widths (reverse (car (cdr (car texinfo-stack)))))
691 (existing-fill-column fill-column)
695 (table-entry-height 0)
696 ;; unformatted row looks like: A1 @tab A2 @tab A3
697 ;; extract-row command deletes the source line in the table.
698 (unformated-row (texinfo-multitable-extract-row)))
699 ;; Use a temporary buffer
700 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
701 (delete-region (point-min) (point-max))
702 (insert unformated-row)
703 (goto-char (point-min))
704 ;; 1. Check for correct number of @tab in line.
705 (let ((tab-number 1)) ; one @tab between two columns
706 (while (search-forward "@tab" nil t)
707 (setq tab-number (1+ tab-number)))
708 (if (/= tab-number (length table-widths))
709 (error "Wrong number of @tab's in a @multitable row")))
710 (goto-char (point-min))
711 ;; 2. Format each cell, and copy to a rectangle
712 ;; buffer looks like this: A1 @tab A2 @tab A3
713 ;; Cell #1: format up to @tab
714 ;; Cell #2: format up to @tab
715 ;; Cell #3: format up to eob
718 (setq end (save-excursion
719 (if (search-forward "@tab" nil 'move)
720 ;; Delete the @tab command, including the @-sign
723 (progn (forward-word -1) (1- (point)))))
725 ;; Set fill-column *wider* than needed to produce inter-column space
726 (setq fill-column (+ 1
727 texinfo-extra-inter-column-width
728 (nth table-column table-widths)))
729 (narrow-to-region start end)
730 ;; Remove whitespace before and after entry.
731 (skip-chars-forward " ")
732 (delete-region (point) (save-excursion (beginning-of-line) (point)))
733 (goto-char (point-max))
734 (skip-chars-backward " ")
735 (delete-region (point) (save-excursion (end-of-line) (point)))
736 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
737 ;; does not see an unterminated @multitable.
738 (let (texinfo-stack) ; nil
739 (texinfo-format-scan))
740 (let (fill-prefix) ; no fill prefix
741 (fill-region (point-min) (point-max)))
742 (setq table-entry-height
743 (max table-entry-height (count-lines (point-min) (point-max))))
744 ;; 3. Move point to end of bottom line, and pad that line to fill column.
745 (goto-char (point-min))
746 (forward-line (1- table-entry-height))
747 (let* ((beg (point)) ; beginning of line
748 ;; add one more space for inter-column spacing
752 (progn (end-of-line) (current-column)))))) ; end of existing line
754 (if (> needed-whitespace 0) needed-whitespace 1)
756 ;; now, put formatted cell into a rectangle
757 (set (intern (concat texinfo-multitable-rectangle-name
758 (int-to-string table-column)))
759 (extract-rectangle (point-min) (point)))
760 (delete-region (point-min) (point))
761 (goto-char (point-max))
762 (setq table-column (1+ table-column))
764 ;; 4. Add extra lines to rectangles so all are of same height
765 (let ((total-number-of-columns table-column)
768 (while (> table-column 0)
769 (let ((this-rectangle (int-to-string table-column)))
770 (while (< (length this-rectangle) table-entry-height)
771 (setq this-rectangle (append this-rectangle '("")))))
772 (setq table-column (1- table-column)))
773 ;; 5. Insert formatted rectangles in original buffer
774 (switch-to-buffer original-buffer)
775 (open-line table-entry-height)
776 (while (< column-number total-number-of-columns)
780 (concat texinfo-multitable-rectangle-name
781 (int-to-string column-number)))))
784 (setq column-number (1+ column-number))))
785 (kill-buffer texinfo-multitable-buffer-name)
786 (setq fill-column existing-fill-column)))
789 (when-broken texinfo-format-printindex
790 (fmakunbound 'texinfo-format-printindex))
792 (defun-maybe texinfo-format-printindex ()
793 (let ((indexelts (symbol-value
794 (cdr (assoc (texinfo-parse-arg-discard)
795 texinfo-indexvar-alist))))
797 (insert "\n* Menu:\n\n")
798 (setq opoint (point))
799 (texinfo-print-index nil indexelts)
801 (if (memq system-type '(vax-vms windows-nt ms-dos))
802 (texinfo-sort-region opoint (point))
803 (shell-command-on-region opoint (point) "sort -fd" 1))))
807 ;;; ptexinfmt.el ends here