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 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Maintainer: TAKAHASHI Kaoru <kaoru@kaisei.org>
12 ;; Created: 7 Jul 2000
13 ;; Keywords: maint, tex, docs, emulation, compatibility
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
45 (defvar ptexinfmt-disable-broken-notice-flag t
46 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
47 This is NO-NOTICE argument in `ptexinfmt-broken-facility'.")
49 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
50 (defmacro ptexinfmt-broken-facility (facility docstring assertion
52 "Declare a symbol FACILITY is broken if ASSERTION is nil.
53 DOCSTRING will be printed if ASSERTION is nil and NO-NOTICE is nil."
54 (` (let ((facility '(, facility))
55 (docstring (, docstring))
56 (assertion (eval '(, assertion))))
57 (put facility 'broken (not assertion))
60 (put facility 'broken-docstring docstring)
63 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
65 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
66 (defmacro ptexinfmt-defun-if-broken (&rest args)
67 "Redefine a function just like `defun' if it is considered broken."
68 (let ((name (list 'quote (car args))))
69 (setq args (cdr args))
72 (if (get (, name) 'broken)
74 (function (lambda (,@ args)))))))))
76 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
77 (defmacro ptexinfmt-defun-if-void (&rest args)
78 "Define a function just like `defun' unless it is already defined."
79 (let ((name (list 'quote (car args))))
80 (setq args (cdr args))
83 (if (fboundp (, name))
86 (function (lambda (,@ args)))))))))
88 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
89 (defmacro ptexinfmt-defvar-if-void (&rest args)
90 "Define a variable just like `defvar' unless it is already defined."
91 (let ((name (car args)))
92 (setq args (cdr args))
95 (if (boundp '(, name))
97 (defvar (, name) (,@ args)))))))
100 (ptexinfmt-broken-facility texinfo-format-printindex
101 "Can't sort on Mule for Windows."
102 (if (and (memq system-type '(windows-nt ms-dos))
103 ;;; I don't know version threshold.
104 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
105 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
108 ptexinfmt-disable-broken-notice-flag)
111 (ptexinfmt-broken-facility texinfo-format-var
112 "Don't perse @var argument."
115 (let (texinfo-enclosure-list texinfo-alias-list)
117 (insert "@var{@asis{foo}}\n")
118 (texinfo-format-expand-region (point-min) (point-max))
121 ptexinfmt-disable-broken-notice-flag)
124 (ptexinfmt-broken-facility texinfo-format-xref
125 "Can't format @xref, 1st argument is empty."
128 (let (texinfo-enclosure-list texinfo-alias-list)
130 (insert "@xref{, xref, , file}\n")
131 (texinfo-format-expand-region (point-min) (point-max))
134 ptexinfmt-disable-broken-notice-flag)
137 (ptexinfmt-broken-facility texinfo-format-uref
138 "Parse twice @uref argument."
141 (let (texinfo-enclosure-list texinfo-alias-list)
143 (insert "@uref{mailto:foo@@bar.com}\n")
144 (texinfo-format-expand-region (point-min) (point-max))
147 ptexinfmt-disable-broken-notice-flag)
150 (ptexinfmt-broken-facility texinfo-multitable-widths
151 "`texinfo-multitable-widths' unsupport wide-char."
152 (if (fboundp 'texinfo-multitable-widths)
154 (let ((str "
\e$BI}9-J8;z
\e(B"))
156 (insert (format " {%s}\n" str))
157 (goto-char (point-min))
158 (if (= (car (texinfo-multitable-widths)) (length str))
161 ;; function definition is void
163 ptexinfmt-disable-broken-notice-flag)
165 (ptexinfmt-broken-facility texinfo-multitable-item
166 "`texinfo-multitable-item' unsupport wide-char."
167 (not (get 'texinfo-multitable-widths 'broken))
168 ptexinfmt-disable-broken-notice-flag)
171 ;;; Hardcopy and HTML (discard)
173 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
174 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
175 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
178 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
179 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
180 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
181 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
182 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
183 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
184 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
187 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
188 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
191 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
192 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
193 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
196 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
197 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
198 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
199 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
202 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'page 'texinfo-format 'texinfo-discard-line)
206 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
212 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
213 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
214 (let ((str (texinfo-parse-arg-discard)))
215 (delete-region (point)
217 (skip-chars-forward " ")
219 (insert "INFO-DIR-SECTION " str "\n")))
222 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
223 (ptexinfmt-defun-if-void texinfo-format-direntry ()
224 (texinfo-push-stack 'direntry nil)
225 (texinfo-discard-line)
226 (insert "START-INFO-DIR-ENTRY\n"))
228 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
229 (ptexinfmt-defun-if-void texinfo-end-direntry ()
230 (texinfo-discard-command)
231 (insert "END-INFO-DIR-ENTRY\n\n")
232 (texinfo-pop-stack 'direntry))
236 ;; @detailmenu ... @end detailmenu
237 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
238 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
240 ;; @smalldisplay ... @end smalldisplay
241 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
242 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
244 ;; @smallformat ... @end smallformat
245 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
246 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
248 ;; @cartouche ... @end cartouche
249 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
250 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
254 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
255 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
256 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
258 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
259 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
260 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
262 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
263 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
264 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
267 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
268 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
269 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
270 (delete-region texinfo-command-start
271 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
274 ;; @html ... @end html (makeinfo 3.11 or later)
275 (put 'html 'texinfo-format 'texinfo-format-html)
276 (ptexinfmt-defun-if-void texinfo-format-html ()
277 (delete-region texinfo-command-start
278 (progn (re-search-forward "@end html[ \t]*\n")
281 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
282 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
283 (defun texinfo-format-ifhtml ()
284 (delete-region texinfo-command-start
285 (progn (re-search-forward "@end ifhtml[ \t]*\n")
288 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
289 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
290 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
291 (delete-region texinfo-command-start
292 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
298 ;; @url, @env, @command
299 (put 'url 'texinfo-format 'texinfo-format-code)
300 (put 'env 'texinfo-format 'texinfo-format-code)
301 (put 'command 'texinfo-format 'texinfo-format-code)
304 (put 'acronym 'texinfo-format 'texinfo-format-var)
306 (ptexinfmt-defun-if-broken texinfo-format-var ()
307 (let ((arg (texinfo-parse-expanded-arg)))
308 (texinfo-discard-command)
309 (insert (upcase arg))))
312 (put 'key 'texinfo-format 'texinfo-format-key)
313 (ptexinfmt-defun-if-void texinfo-format-key ()
314 (insert (texinfo-parse-arg-discard))
315 (goto-char texinfo-command-start))
317 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
318 (put 'email 'texinfo-format 'texinfo-format-email)
319 (ptexinfmt-defun-if-void texinfo-format-email ()
320 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
321 Insert < ... > around EMAIL-ADDRESS."
322 (let ((args (texinfo-format-parse-args)))
323 (texinfo-discard-command)
326 (insert (nth 1 args) " <" (nth 0 args) ">")
327 (insert "<" (nth 0 args) ">"))))
330 (put 'option 'texinfo-format 'texinfo-format-option)
331 (defun texinfo-format-option ()
332 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
333 ;; `looking-at-backward' not available in v. 18.57, 20.2
334 ;; searched-for character is a control-H
335 (if (not (search-backward "\010"
336 (save-excursion (beginning-of-line) (point))
338 (insert "`" (texinfo-parse-arg-discard) "'")
339 (insert (texinfo-parse-arg-discard)))
340 (goto-char texinfo-command-start))
344 ;;; Accents and Special characters
345 ;; @pounds{} ==> # Pounds Sterling
346 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
347 (ptexinfmt-defun-if-void texinfo-format-pounds ()
348 (texinfo-parse-arg-discard)
351 ;; @OE{} ==> OE French-OE-ligature
352 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
353 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
354 (insert "OE" (texinfo-parse-arg-discard))
355 (goto-char texinfo-command-start))
358 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
359 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
360 (insert "oe" (texinfo-parse-arg-discard))
361 (goto-char texinfo-command-start))
363 ;; @AA{} ==> AA Scandinavian-A-with-circle
364 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
365 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
366 (insert "AA" (texinfo-parse-arg-discard))
367 (goto-char texinfo-command-start))
370 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
371 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
372 (insert "aa" (texinfo-parse-arg-discard))
373 (goto-char texinfo-command-start))
375 ;; @AE{} ==> AE Latin-Scandinavian-AE
376 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
377 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
378 (insert "AE" (texinfo-parse-arg-discard))
379 (goto-char texinfo-command-start))
382 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
383 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
384 (insert "ae" (texinfo-parse-arg-discard))
385 (goto-char texinfo-command-start))
387 ;; @ss{} ==> ss German-sharp-S
388 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
389 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
390 (insert "ss" (texinfo-parse-arg-discard))
391 (goto-char texinfo-command-start))
393 ;; @questiondown{} ==> ? upside-down-question-mark
394 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
395 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
396 (insert "?" (texinfo-parse-arg-discard))
397 (goto-char texinfo-command-start))
399 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
400 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
401 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
402 (insert "!" (texinfo-parse-arg-discard))
403 (goto-char texinfo-command-start))
405 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
406 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
407 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
408 (insert (texinfo-parse-arg-discard) "/L")
409 (goto-char texinfo-command-start))
411 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
412 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
413 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
414 (insert (texinfo-parse-arg-discard) "/l")
415 (goto-char texinfo-command-start))
417 ;; @O{} ==> O/ Scandinavian O-with-slash
418 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
419 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
420 (insert (texinfo-parse-arg-discard) "O/")
421 (goto-char texinfo-command-start))
423 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
424 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
425 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
426 (insert (texinfo-parse-arg-discard) "o/")
427 (goto-char texinfo-command-start))
429 ;; @,{c} ==> c, cedilla accent
430 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
431 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
432 (insert (texinfo-parse-arg-discard) ",")
433 (goto-char texinfo-command-start))
436 ;; @dotaccent{o} ==> .o overdot-accent
437 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
438 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
439 (insert "." (texinfo-parse-arg-discard))
440 (goto-char texinfo-command-start))
442 ;; @ubaraccent{o} ==> _o underbar-accent
443 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
444 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
445 (insert "_" (texinfo-parse-arg-discard))
446 (goto-char texinfo-command-start))
448 ;; @udotaccent{o} ==> o-. underdot-accent
449 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
450 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
451 (insert (texinfo-parse-arg-discard) "-.")
452 (goto-char texinfo-command-start))
454 ;; @H{o} ==> ""o long Hungarian umlaut
455 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
456 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
457 (insert "\"\"" (texinfo-parse-arg-discard))
458 (goto-char texinfo-command-start))
460 ;; @ringaccent{o} ==> *o ring accent
461 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
462 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
463 (insert "*" (texinfo-parse-arg-discard))
464 (goto-char texinfo-command-start))
466 ;; @tieaccent{oo} ==> [oo tie after accent
467 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
468 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
469 (insert "[" (texinfo-parse-arg-discard))
470 (goto-char texinfo-command-start))
472 ;; @u{o} ==> (o breve accent
473 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
474 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
475 (insert "(" (texinfo-parse-arg-discard))
476 (goto-char texinfo-command-start))
478 ;; @v{o} ==> <o hacek accent
479 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
480 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
481 (insert "<" (texinfo-parse-arg-discard))
482 (goto-char texinfo-command-start))
484 ;; @dotless{i} ==> i dotless i and dotless j
485 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
486 (ptexinfmt-defun-if-void texinfo-format-dotless ()
487 (insert (texinfo-parse-arg-discard))
488 (goto-char texinfo-command-start))
491 (put '\. 'texinfo-format 'texinfo-format-\.)
492 (ptexinfmt-defun-if-void texinfo-format-\. ()
493 (texinfo-discard-command)
497 (put '\: 'texinfo-format 'texinfo-format-\:)
498 (ptexinfmt-defun-if-void texinfo-format-\: ()
499 (texinfo-discard-command))
502 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
503 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
504 (texinfo-discard-command))
509 (put 'ref 'texinfo-format 'texinfo-format-xref)
511 (ptexinfmt-defun-if-broken texinfo-format-xref ()
512 (let ((args (texinfo-format-parse-args)))
513 (texinfo-discard-command)
515 (let ((fname (or (nth 1 args) (nth 2 args))))
516 (if (null (or fname (nth 3 args)))
517 (insert (nth 0 args) "::")
518 (insert (or fname (nth 0 args)) ": ")
520 (insert "(" (nth 3 args) ")"))
521 (unless (null (nth 0 args))
522 (insert (nth 0 args)))))))
525 (put 'uref 'texinfo-format 'texinfo-format-uref)
526 (ptexinfmt-defun-if-broken texinfo-format-uref ()
527 "Format URL and optional URL-TITLE.
528 Insert ` ... ' around URL if no URL-TITLE argument;
529 otherwise, insert URL-TITLE followed by URL in parentheses."
530 (let ((args (texinfo-format-parse-args)))
531 (texinfo-discard-command)
534 (insert (nth 1 args) " (" (nth 0 args) ")")
535 (insert "`" (nth 0 args) "'"))))
538 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
539 (ptexinfmt-defun-if-void texinfo-format-inforef ()
540 (let ((args (texinfo-format-parse-args)))
541 (texinfo-discard-command)
543 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
544 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
549 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
550 ;; - Info-tagify suport @anthor-*-refill.
551 ;; - info.el support Ref in Tag table.
552 (unless (get 'anchor 'texinfo-format)
553 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
557 ;;; New command definition
558 ;; @alias NEW=EXISTING
559 (put 'alias 'texinfo-format 'texinfo-alias)
560 (ptexinfmt-defun-if-void texinfo-alias ()
561 (let ((start (1- (point)))
563 (skip-chars-forward " ")
564 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
565 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
566 (error "Invalid alias command")
567 (setq texinfo-alias-list
570 (buffer-substring (match-beginning 1) (match-end 1))
571 (buffer-substring (match-beginning 2) (match-end 2)))
573 (texinfo-discard-command))))
577 ;; @image{FILENAME, [WIDTH], [HEIGHT]}
578 (put 'image 'texinfo-format 'texinfo-format-image)
579 (ptexinfmt-defun-if-void texinfo-format-image ()
580 ;; I don't know makeinfo parse FILENAME.
581 (let ((args (texinfo-format-parse-args))
583 (when (null (nth 0 args))
584 (error "Invalid image command"))
585 (texinfo-discard-command)
586 ;; makeinfo uses FILENAME.txt
587 (setq filename (format "%s.txt" (nth 0 args)))
588 (message "Reading included file: %s" filename)
589 ;; verbatim for Info output
590 (goto-char (+ (point) (cadr (insert-file-contents filename))))
591 (message "Reading included file: %s...done" filename)))
598 ;;; @multitable ... @end multitable
599 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
600 "*Number of extra spaces between entries (columns) in @multitable.")
602 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
603 "*multitable-temporary-buffer*")
604 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
605 "texinfo-multitable-temp-")
607 ;; These commands are defined in texinfo.tex for printed output.
608 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
609 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
610 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
611 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
613 (put 'multitable 'texinfo-format 'texinfo-multitable)
615 (ptexinfmt-defun-if-void texinfo-multitable ()
616 "Produce multi-column tables."
618 ;; This function pushes information onto the `texinfo-stack'.
619 ;; A stack element consists of:
620 ;; - type-of-command, i.e., multitable
621 ;; - the information about column widths, and
622 ;; - the position of texinfo-command-start.
623 ;; e.g., ('multitable (1 2 3 4) 123)
624 ;; The command line is then deleted.
627 ;; push width information on stack
628 (texinfo-multitable-widths))
629 (texinfo-discard-line-with-args))
631 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
632 (ptexinfmt-defun-if-void texinfo-end-multitable ()
633 "Discard the @end multitable line and pop the stack of multitable."
634 (texinfo-discard-command)
635 (texinfo-pop-stack 'multitable))
637 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
638 "Return list of widths of each column in a multi-column table."
639 (let (texinfo-multitable-width-list)
641 ;; @multitable @columnfractions .25 .3 .45
644 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
645 ;; Place point before first argument
646 (skip-chars-forward " \t")
648 ;; Check for common misspelling
649 ((looking-at "@columnfraction ")
650 (error "In @multitable, @columnfractions misspelled"))
651 ;; Case 1: @columnfractions .25 .3 .45
652 ((looking-at "@columnfractions")
655 (setq texinfo-multitable-width-list
659 (* fill-column (read (get-buffer (current-buffer))))))
660 texinfo-multitable-width-list))))
662 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
664 (let ((start-of-templates (point)))
666 (skip-chars-forward " \t")
667 (let* ((start-of-template (1+ (point)))
669 ;; forward-sexp works with braces in Texinfo mode
670 (progn (forward-sexp 1) (1- (point)))))
671 (setq texinfo-multitable-width-list
673 (goto-char end-of-template)
676 (goto-char start-of-template)
678 texinfo-multitable-width-list))
679 ;; Remove carriage return from within a template, if any.
680 ;; This helps those those who want to use more than
681 ;; one line's worth of words in @multitable line.
682 (narrow-to-region start-of-template end-of-template)
683 (goto-char (point-min))
684 (while (search-forward "\n" nil t)
686 (goto-char (point-max))
693 You probably need to specify column widths for @multitable correctly")))
694 ;; Check whether columns fit on page.
695 (let ((desired-columns
697 ;; between column spaces
698 (length texinfo-multitable-width-list)
699 ;; additional between column spaces, if any
700 texinfo-extra-inter-column-width
701 ;; sum of spaces for each entry
702 (apply '+ texinfo-multitable-width-list))))
703 (if (> desired-columns fill-column)
705 Multi-column table width, %d chars, is greater than page width, %d chars."
706 desired-columns fill-column))))
707 texinfo-multitable-width-list))
709 ;; @item A1 @tab A2 @tab A3
710 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
711 "Return multitable row, as a string.
712 End of row is beginning of next @item or beginning of @end.
713 Cells within rows are separated by @tab."
714 (skip-chars-forward " \t")
715 (let* ((start (point))
717 (re-search-forward "@item\\|@end")
718 (match-beginning 0)))
719 (row (progn (goto-char end)
720 (skip-chars-backward " ")
721 ;; remove whitespace at end of argument
722 (delete-region (point) end)
723 (buffer-substring start (point)))))
724 (delete-region texinfo-command-start end)
727 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
728 (ptexinfmt-defun-if-void texinfo-multitable-item ()
729 "Format a row within a multicolumn table.
730 Cells in row are separated by @tab.
731 Widths of cells are specified by the arguments in the @multitable line.
732 All cells are made to be the same height.
733 This command is executed when texinfmt sees @item inside @multitable."
734 (let ((original-buffer (current-buffer))
735 (table-widths (reverse (car (cdr (car texinfo-stack)))))
736 (existing-fill-column fill-column)
740 (table-entry-height 0)
741 ;; unformatted row looks like: A1 @tab A2 @tab A3
742 ;; extract-row command deletes the source line in the table.
743 (unformated-row (texinfo-multitable-extract-row)))
744 ;; Use a temporary buffer
745 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
746 (delete-region (point-min) (point-max))
747 (insert unformated-row)
748 (goto-char (point-min))
749 ;; 1. Check for correct number of @tab in line.
750 (let ((tab-number 1)) ;; one @tab between two columns
751 (while (search-forward "@tab" nil t)
752 (setq tab-number (1+ tab-number)))
753 (if (/= tab-number (length table-widths))
754 (error "Wrong number of @tab's in a @multitable row")))
755 (goto-char (point-min))
756 ;; 2. Format each cell, and copy to a rectangle
757 ;; buffer looks like this: A1 @tab A2 @tab A3
758 ;; Cell #1: format up to @tab
759 ;; Cell #2: format up to @tab
760 ;; Cell #3: format up to eob
763 (setq end (save-excursion
764 (if (search-forward "@tab" nil 'move)
765 ;; Delete the @tab command, including the @-sign
768 (progn (forward-word -1) (1- (point)))))
770 ;; Set fill-column *wider* than needed to produce inter-column space
771 (setq fill-column (+ 1
772 texinfo-extra-inter-column-width
773 (nth table-column table-widths)))
774 (narrow-to-region start end)
775 ;; Remove whitespace before and after entry.
776 (skip-chars-forward " ")
777 (delete-region (point) (save-excursion (beginning-of-line) (point)))
778 (goto-char (point-max))
779 (skip-chars-backward " ")
780 (delete-region (point) (save-excursion (end-of-line) (point)))
781 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
782 ;; does not see an unterminated @multitable.
783 (let (texinfo-stack) ;; nil
784 (texinfo-format-scan))
785 (let (fill-prefix) ;; no fill prefix
786 (fill-region (point-min) (point-max)))
787 (setq table-entry-height
788 (max table-entry-height (count-lines (point-min) (point-max))))
789 ;; 3. Move point to end of bottom line, and pad that line to fill column.
790 (goto-char (point-min))
791 (forward-line (1- table-entry-height))
792 (let* ((beg (point)) ;; beginning of line
793 ;; add one more space for inter-column spacing
799 (current-column)))))) ;; end of existing line
801 (if (> needed-whitespace 0) needed-whitespace 1)
803 ;; now, put formatted cell into a rectangle
804 (set (intern (concat texinfo-multitable-rectangle-name
805 (int-to-string table-column)))
806 (extract-rectangle (point-min) (point)))
807 (delete-region (point-min) (point))
808 (goto-char (point-max))
809 (setq table-column (1+ table-column))
811 ;; 4. Add extra lines to rectangles so all are of same height
812 (let ((total-number-of-columns table-column)
815 (while (> table-column 0)
816 (let ((this-rectangle (int-to-string table-column)))
817 (while (< (length this-rectangle) table-entry-height)
818 (setq this-rectangle (append this-rectangle '("")))))
819 (setq table-column (1- table-column)))
820 ;; 5. Insert formatted rectangles in original buffer
821 (switch-to-buffer original-buffer)
822 (open-line table-entry-height)
823 (while (< column-number total-number-of-columns)
827 (concat texinfo-multitable-rectangle-name
828 (int-to-string column-number)))))
831 (setq column-number (1+ column-number))))
832 (kill-buffer texinfo-multitable-buffer-name)
833 (setq fill-column existing-fill-column)))
836 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
837 (let ((indexelts (symbol-value
838 (cdr (assoc (texinfo-parse-arg-discard)
839 texinfo-indexvar-alist))))
841 (insert "\n* Menu:\n\n")
842 (setq opoint (point))
843 (texinfo-print-index nil indexelts)
845 (if (memq system-type '(vax-vms windows-nt ms-dos))
846 (texinfo-sort-region opoint (point))
847 (shell-command-on-region opoint (point) "sort -fd" 1))))
851 ;;; ptexinfmt.el ends here