New project to translate the Gnus Info manuals into Japanese.
[elisp/gnus-doc-ja.git] / ptexinfmt.el
1 ;;; ptexinfmt.el -- portable Texinfo formatter.
2
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>
7
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
14
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.
19
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.
24
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., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
29
30 ;;; Commentary:
31
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;;      makeinfo.el (gnujdoc project)
34
35 ;; Support texinfmt.el 2.32 or later.
36
37 ;; Modified by Yamaoka not to use APEL functions.
38
39 ;; Unimplemented command:
40 ;;  @abbr
41 ;;  @float, @caption, @shortcaption, @listoffloats
42 ;;  @deftypecv[x]
43 ;;  @headitem
44 ;;  @comma{}
45 ;;  @quotation (optional arguments)
46 ;;  @acronym (optional argument)
47 ;;  @dofirstparagraphindent
48 ;;  @indent
49 ;;  @verbatiminclude
50 ;;  @\
51 ;;  @definfoenclose
52 ;;  @deftypeivar
53 ;;  @deftypeop
54
55 ;;; Code:
56
57 (require 'backquote)
58 (require 'texinfmt)
59
60 ;;; Broken
61 (defvar ptexinfmt-disable-broken-notice-flag t
62   "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
63 This is last argument in `ptexinfmt-broken-facility'.")
64
65 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
66 (defmacro ptexinfmt-broken-facility (facility docstring assertion
67                                               &optional dummy)
68   "Declare a symbol FACILITY is broken if ASSERTION is nil.
69 DOCSTRING will be printed if ASSERTION is nil and
70 `ptexinfmt-disable-broken-notice-flag' is nil."
71   (` (let ((facility '(, facility))
72            (docstring (, docstring))
73            (assertion (eval '(, assertion))))
74        (put facility 'broken (not assertion))
75        (if assertion
76            nil
77          (put facility 'broken-docstring docstring)
78          (if ptexinfmt-disable-broken-notice-flag
79              nil
80            (message "BROKEN FACILITY DETECTED: %s" docstring))))))
81
82 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
83 (defmacro ptexinfmt-defun-if-broken (&rest args)
84   "Redefine a function just like `defun' if it is considered broken."
85   (let ((name (list 'quote (car args))))
86     (setq args (cdr args))
87     (` (prog1
88            (, name)
89          (if (get (, name) 'broken)
90              (defalias (, name)
91                (function (lambda (,@ args)))))))))
92
93 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
94 (defmacro ptexinfmt-defun-if-void (&rest args)
95   "Define a function just like `defun' unless it is already defined."
96   (let ((name (list 'quote (car args))))
97     (setq args (cdr args))
98     (` (prog1
99            (, name)
100          (if (fboundp (, name))
101              nil
102            (defalias (, name)
103              (function (lambda (,@ args)))))))))
104
105 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
106 (defmacro ptexinfmt-defvar-if-void (&rest args)
107   "Define a variable just like `defvar' unless it is already defined."
108   (let ((name (car args)))
109     (setq args (cdr args))
110     (` (prog1
111            (defvar (, name))
112          (if (boundp '(, name))
113              nil
114            (defvar (, name) (,@ args)))))))
115
116 ;; sort -fd
117 (ptexinfmt-broken-facility texinfo-format-printindex
118   "Can't sort on Mule for Windows."
119   t)
120
121 ;; @var
122 (ptexinfmt-broken-facility texinfo-format-var
123   "Don't perse @var argument."
124   (condition-case nil
125       (with-temp-buffer
126         (let (texinfo-enclosure-list texinfo-alias-list)
127           (texinfo-mode)
128           (insert "@var{@asis{foo}}\n")
129           (texinfo-format-expand-region (point-min) (point-max))
130           t))
131     (error nil)))
132
133 ;; @xref
134 (ptexinfmt-broken-facility texinfo-format-xref
135   "Can't format @xref, 1st argument is empty."
136   (condition-case nil
137       (with-temp-buffer
138         (let (texinfo-enclosure-list texinfo-alias-list)
139           (texinfo-mode)
140           (insert "@xref{, xref, , file}\n")
141           (texinfo-format-expand-region (point-min) (point-max))
142           t))
143     (error nil)))
144
145 ;; @uref
146 (ptexinfmt-broken-facility texinfo-format-uref
147   "Parse twice @uref argument."
148   (condition-case nil
149       (with-temp-buffer
150         (let (texinfo-enclosure-list texinfo-alias-list)
151           (texinfo-mode)
152           (insert "@uref{mailto:foo@@noncommand.example.com}\n")
153           (texinfo-format-expand-region (point-min) (point-max))
154           t))
155     (error nil)))
156
157 ;; @multitable
158 (ptexinfmt-broken-facility texinfo-multitable-widths
159   "`texinfo-multitable-widths' unsupport wide-char."
160   (if (fboundp 'texinfo-multitable-widths)
161       (with-temp-buffer
162         (let ((str "\e$BI}9-J8;z\e(B"))
163           (texinfo-mode)
164           (insert (format " {%s}\n" str))
165           (goto-char (point-min))
166           (if (= (car (texinfo-multitable-widths)) (length str))
167               t
168             nil)))
169     ;; function definition is void
170     nil))
171
172 (ptexinfmt-broken-facility texinfo-multitable-item
173   "`texinfo-multitable-item' unsupport wide-char."
174   (not (get 'texinfo-multitable-widths 'broken)))
175
176
177 ;;; Hardcopy and HTML (discard)
178 ;; html
179 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
180 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
181 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
182
183 ;; size
184 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
185 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
186 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
187 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
188 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
189 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
190 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
191
192 ;; style
193 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
195
196 ;; flags
197 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
198 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
199 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
200
201 ;; head & foot
202 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
209
210 ;; misc
211 (put 'page 'texinfo-format 'texinfo-discard-line)
212 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
213
214 ;; @slanted{} (makeinfo 4.8 or later)
215 (put 'slanted 'texinfo-format 'texinfo-format-noop)
216
217 ;; @tie{} (makeinfo 4.3 or later)
218 (put 'tie 'texinfo-format 'texinfo-format-tie)
219 (ptexinfmt-defun-if-void texinfo-format-tie ()
220   (texinfo-parse-arg-discard)
221   (insert " "))
222
223 \f
224 ;;; Directory File
225 ;; @direcategory
226 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
227 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
228   (let ((str (texinfo-parse-arg-discard)))
229     (delete-region (point)
230                    (progn
231                      (skip-chars-forward " ")
232                      (point)))
233     (insert "INFO-DIR-SECTION " str "\n")))
234
235 ;; @direntry
236 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
237 (ptexinfmt-defun-if-void texinfo-format-direntry ()
238   (texinfo-push-stack 'direntry nil)
239   (texinfo-discard-line)
240   (insert "START-INFO-DIR-ENTRY\n"))
241
242 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
243 (ptexinfmt-defun-if-void texinfo-end-direntry ()
244   (texinfo-discard-command)
245   (insert "END-INFO-DIR-ENTRY\n\n")
246   (texinfo-pop-stack 'direntry))
247
248
249 ;;; Block Enclosing
250 ;; @detailmenu ... @end detailmenu
251 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
252 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
253
254 ;; @smalldisplay ... @end smalldisplay
255 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
256 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
257
258 ;; @smallformat ... @end smallformat
259 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
260 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
261
262 ;; @cartouche  ... @end cartouche
263 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
264 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
265
266
267 ;;; Conditional
268 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
269 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
270 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
271
272 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
273 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
274 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
275
276 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
277 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
278 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
279
280 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
281 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
282 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
283
284 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
285 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
286 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
287   (delete-region texinfo-command-start
288                  (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
289                         (point))))
290
291 ;; @html ... @end html (makeinfo 3.11 or later)
292 (put 'html 'texinfo-format 'texinfo-format-html)
293 (ptexinfmt-defun-if-void texinfo-format-html ()
294   (delete-region texinfo-command-start
295                  (progn (re-search-forward "@end html[ \t]*\n")
296                         (point))))
297
298 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
299 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
300 (ptexinfmt-defun-if-void texinfo-format-docbook ()
301   (delete-region texinfo-command-start
302                  (progn (re-search-forward "@end docbook[ \t]*\n")
303                         (point))))
304
305 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
306 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
307 (defun texinfo-format-ifhtml ()
308   (delete-region texinfo-command-start
309                  (progn (re-search-forward "@end ifhtml[ \t]*\n")
310                         (point))))
311
312 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
313 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
314 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
315   (delete-region texinfo-command-start
316                  (progn (re-search-forward "@end ifplaintext[ \t]*\n")
317                         (point))))
318
319 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
320 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
321 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
322   (delete-region texinfo-command-start
323                  (progn (re-search-forward "@end ifdocbook[ \t]*\n")
324                         (point))))
325
326 \f
327 ;;; Marking
328 ;; @indicateurl, @url, @env, @command, 
329 (put 'env 'texinfo-format 'texinfo-format-code)
330 (put 'command 'texinfo-format 'texinfo-format-code)
331
332 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
333 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
334
335 ;; @acronym
336 (put 'acronym 'texinfo-format 'texinfo-format-var)
337
338 (ptexinfmt-defun-if-broken texinfo-format-var ()
339   (let ((arg (texinfo-parse-expanded-arg)))
340     (texinfo-discard-command)
341     (insert (upcase arg))))
342
343 ;; @key
344 (put 'key 'texinfo-format 'texinfo-format-key)
345 (ptexinfmt-defun-if-void texinfo-format-key ()
346   (insert (texinfo-parse-arg-discard))
347   (goto-char texinfo-command-start))
348
349 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
350 (put 'email 'texinfo-format 'texinfo-format-email)
351 (ptexinfmt-defun-if-void texinfo-format-email ()
352   "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
353 Insert < ... > around EMAIL-ADDRESS."
354   (let ((args (texinfo-format-parse-args)))
355   (texinfo-discard-command)
356     ;; if displayed-text
357     (if (nth 1 args)
358         (insert (nth 1 args) " <" (nth 0 args) ">")
359       (insert "<" (nth 0 args) ">"))))
360
361 ;; @option
362 (put 'option 'texinfo-format 'texinfo-format-option)
363 (ptexinfmt-defun-if-void texinfo-format-option ()
364   "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
365   ;; `looking-at-backward' not available in v. 18.57, 20.2
366   ;; searched-for character is a control-H
367   (if (not (search-backward "\010"
368                             (save-excursion (beginning-of-line) (point))
369                             t))
370       (insert "`" (texinfo-parse-arg-discard) "'")
371     (insert (texinfo-parse-arg-discard)))
372   (goto-char texinfo-command-start))
373
374 ;; @verb{<char>TEXT<char>}  (makeinfo 4.1 or later)
375 (put 'verb 'texinfo-format 'texinfo-format-verb)
376 (ptexinfmt-defun-if-void texinfo-format-verb ()
377   "Format text between non-quoted unique delimiter characters verbatim.
378 Enclose the verbatim text, including the delimiters, in braces.  Print
379 text exactly as written (but not the delimiters) in a fixed-width.
380
381 For example, @verb\{|@|\} results in @ and
382 @verb\{+@'e?`!`+} results in @'e?`!`."
383
384   (let ((delimiter (buffer-substring-no-properties
385                     (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
386     (unless (looking-at "{")
387       (error "Not found: @verb start brace"))
388     (delete-region texinfo-command-start (+ 2 texinfo-command-end))
389     (search-forward  delimiter))
390   (delete-backward-char 1)
391   (unless (looking-at "}")
392     (error "Not found: @verb end brace"))
393   (delete-char 1))
394
395 \f
396 ;;; @LaTeX, @registeredsymbol{}
397 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
398 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
399   (texinfo-parse-arg-discard)
400   (insert "LaTeX"))
401
402 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
403 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
404   (texinfo-parse-arg-discard)
405   (insert "(R)"))
406
407 ;;; Accents and Special characters
408 ;; @pounds{}    ==>     #       Pounds Sterling
409 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
410 (ptexinfmt-defun-if-void texinfo-format-pounds ()
411   (texinfo-parse-arg-discard)
412   (insert "#"))
413
414 ;; @ordf{}      ==>     a       Spanish feminine
415 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
416 (ptexinfmt-defun-if-void texinfo-format-ordf ()
417   (texinfo-parse-arg-discard)
418   (insert "o"))
419
420 ;; @ordm{}      ==>     o       Spanish masculine
421 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
422 (ptexinfmt-defun-if-void texinfo-format-ordm ()
423   (texinfo-parse-arg-discard)
424   (insert "o"))
425
426 ;; @OE{}        ==>     OE      French-OE-ligature
427 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
428 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
429   (insert "OE" (texinfo-parse-arg-discard))
430   (goto-char texinfo-command-start))
431
432 ;; @oe{}        ==>     oe
433 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
434 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
435   (insert "oe" (texinfo-parse-arg-discard))
436   (goto-char texinfo-command-start))
437
438 ;; @AA{}        ==>     AA      Scandinavian-A-with-circle
439 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
440 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
441   (insert "AA" (texinfo-parse-arg-discard))
442   (goto-char texinfo-command-start))
443
444 ;; @aa{}        ==>     aa
445 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
446 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
447   (insert "aa" (texinfo-parse-arg-discard))
448   (goto-char texinfo-command-start))
449
450 ;; @AE{}        ==>     AE      Latin-Scandinavian-AE
451 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
452 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
453   (insert "AE" (texinfo-parse-arg-discard))
454   (goto-char texinfo-command-start))
455
456 ;; @ae{}        ==>     ae
457 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
458 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
459   (insert "ae" (texinfo-parse-arg-discard))
460   (goto-char texinfo-command-start))
461
462 ;; @ss{}        ==>     ss      German-sharp-S
463 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
464 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
465   (insert "ss" (texinfo-parse-arg-discard))
466   (goto-char texinfo-command-start))
467
468 ;; @questiondown{}      ==>     ?       upside-down-question-mark
469 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
470 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
471   (insert "?" (texinfo-parse-arg-discard))
472   (goto-char texinfo-command-start))
473
474 ;; @exclamdown{}        ==>     !       upside-down-exclamation-mark
475 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
476 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
477   (insert "!" (texinfo-parse-arg-discard))
478   (goto-char texinfo-command-start))
479
480 ;; @L{}         ==>     L/      Polish suppressed-L (Lslash)
481 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
482 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
483   (insert (texinfo-parse-arg-discard) "/L")
484   (goto-char texinfo-command-start))
485
486 ;; @l{}         ==>     l/      Polish suppressed-L (Lslash) (lower case)
487 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
488 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
489   (insert (texinfo-parse-arg-discard) "/l")
490   (goto-char texinfo-command-start))
491
492 ;; @O{}         ==>     O/      Scandinavian O-with-slash
493 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
494 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
495   (insert (texinfo-parse-arg-discard) "O/")
496   (goto-char texinfo-command-start))
497
498 ;; @o{}         ==>     o/      Scandinavian O-with-slash (lower case)
499 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
500 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
501   (insert (texinfo-parse-arg-discard) "o/")
502   (goto-char texinfo-command-start))
503
504 ;; @,{c}        ==>     c,      cedilla accent
505 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
506 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
507   (insert (texinfo-parse-arg-discard) ",")
508   (goto-char texinfo-command-start))
509
510
511 ;; @dotaccent{o}        ==>     .o      overdot-accent
512 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
513 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
514   (insert "." (texinfo-parse-arg-discard))
515   (goto-char texinfo-command-start))
516
517 ;; @ubaraccent{o}       ==>     _o      underbar-accent
518 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
519 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
520   (insert "_" (texinfo-parse-arg-discard))
521   (goto-char texinfo-command-start))
522
523 ;; @udotaccent{o}       ==>     o-.     underdot-accent
524 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
525 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
526   (insert (texinfo-parse-arg-discard) "-.")
527   (goto-char texinfo-command-start))
528
529 ;; @H{o}        ==>     ""o     long Hungarian umlaut
530 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
531 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
532   (insert "\"\"" (texinfo-parse-arg-discard))
533   (goto-char texinfo-command-start))
534
535 ;; @ringaccent{o}       ==>     *o      ring accent
536 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
537 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
538   (insert "*" (texinfo-parse-arg-discard))
539   (goto-char texinfo-command-start))
540
541 ;; @tieaccent{oo}       ==>     [oo     tie after accent
542 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
543 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
544   (insert "[" (texinfo-parse-arg-discard))
545   (goto-char texinfo-command-start))
546
547 ;; @u{o}        ==>     (o      breve accent
548 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
549 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
550   (insert "(" (texinfo-parse-arg-discard))
551   (goto-char texinfo-command-start))
552
553 ;; @v{o}        ==>     <o      hacek accent
554 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
555 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
556   (insert "<" (texinfo-parse-arg-discard))
557   (goto-char texinfo-command-start))
558
559 ;; @dotless{i}  ==>     i       dotless i and dotless j
560 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
561 (ptexinfmt-defun-if-void texinfo-format-dotless ()
562   (insert (texinfo-parse-arg-discard))
563   (goto-char texinfo-command-start))
564
565 ;; @.
566 (put '\. 'texinfo-format 'texinfo-format-\.)
567 (ptexinfmt-defun-if-void texinfo-format-\. ()
568   (texinfo-discard-command)
569   (insert "."))
570
571 ;; @:
572 (put '\: 'texinfo-format 'texinfo-format-\:)
573 (ptexinfmt-defun-if-void texinfo-format-\: ()
574   (texinfo-discard-command))
575
576 ;; @-
577 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
578 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
579   (texinfo-discard-command))
580
581 ;; @/
582 (put '\/ 'texinfo-format 'texinfo-format-\/)
583 (ptexinfmt-defun-if-void texinfo-format-\/ ()
584   (texinfo-discard-command))
585
586 \f
587 ;;; Cross References
588 ;; @ref, @xref
589 (put 'ref 'texinfo-format 'texinfo-format-xref)
590
591 (ptexinfmt-defun-if-broken texinfo-format-xref ()
592   (let ((args (texinfo-format-parse-args)))
593     (texinfo-discard-command)
594     (insert "*Note ")
595     (let ((fname (or (nth 1 args) (nth 2 args))))
596       (if (null (or fname (nth 3 args)))
597           (insert (nth 0 args) "::")
598         (insert (or fname (nth 0 args)) ": ")
599         (if (nth 3 args)
600             (insert "(" (nth 3 args) ")"))
601         (unless (null (nth 0 args))
602           (insert (nth 0 args)))))))
603
604 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
605 (put 'uref 'texinfo-format 'texinfo-format-uref)
606 (ptexinfmt-defun-if-broken texinfo-format-uref ()
607   "Format URL and optional URL-TITLE.
608 Insert ` ... ' around URL if no URL-TITLE argument;
609 otherwise, insert URL-TITLE followed by URL in parentheses."
610   (let ((args (texinfo-format-parse-args)))
611     (texinfo-discard-command)
612     ;; if url-title
613     (if (nth 1 args)
614         (insert  (nth 1 args) " (" (nth 0 args) ")")
615       (insert "`" (nth 0 args) "'"))))
616
617 ;; @inforef
618 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
619 (ptexinfmt-defun-if-void texinfo-format-inforef ()
620   (let ((args (texinfo-format-parse-args)))
621     (texinfo-discard-command)
622     (if (nth 1 args)
623         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
624       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
625
626
627 ;; @anchor
628 ;; don't emulation
629 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
630 ;;  - Info-tagify suport @anthor-*-refill.
631 ;;  - info.el support Ref in Tag table.
632 (unless (get 'anchor 'texinfo-format)
633   (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
634
635
636 \f
637 ;;; New command definition
638 ;; @alias NEW=EXISTING
639 (put 'alias 'texinfo-format 'texinfo-alias)
640 (ptexinfmt-defun-if-void texinfo-alias ()
641   (let ((start (1- (point)))
642         args)
643     (skip-chars-forward " ")
644     (save-excursion (end-of-line) (setq texinfo-command-end (point)))
645     (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
646         (error "Invalid alias command")
647       (setq texinfo-alias-list
648             (cons
649              (cons
650               (buffer-substring (match-beginning 1) (match-end 1))
651               (buffer-substring (match-beginning 2) (match-end 2)))
652              texinfo-alias-list))
653       (texinfo-discard-command))))
654
655 \f
656 ;;; Indent
657 ;; @exampleindent INDENT  (makeinfo 4.0 or later)
658
659 ;; @paragraphindent INDENT  (makeinfo 4.0 or later)
660 ;; INDENT: asis, 0, n
661
662 ;; @firstparagraphindent WORD   (makeinfo 4.6 or later)
663 ;; WORD: none, insert
664
665
666 \f
667 ;;; Special
668 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
669 (put 'image 'texinfo-format 'texinfo-format-image)
670 (ptexinfmt-defun-if-void texinfo-format-image ()
671   ;; I don't know makeinfo parse FILENAME.
672   (let ((args (texinfo-format-parse-args))
673         filename)
674     (when (null (nth 0 args))
675       (error "Invalid image command"))
676     (texinfo-discard-command)
677     ;; makeinfo uses FILENAME.txt
678     (setq filename (format "%s.txt" (nth 0 args)))
679     (message "Reading included file: %s" filename)
680     ;; verbatim for Info output
681     (goto-char (+ (point) (cadr (insert-file-contents filename))))
682     (message "Reading included file: %s...done" filename)))
683
684 ;; @hyphenation command discards an argument within braces
685 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
686 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
687   "Discard both @-command and its argument in braces."
688   (goto-char texinfo-command-end)
689   (forward-list 1)
690   (setq texinfo-command-end (point))
691   (delete-region texinfo-command-start texinfo-command-end))
692
693 \f
694 ;;; @multitable ... @end multitable
695 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
696   "*Number of extra spaces between entries (columns) in @multitable.")
697
698 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
699   "*multitable-temporary-buffer*")
700 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
701   "texinfo-multitable-temp-")
702
703 ;; These commands are defined in texinfo.tex for printed output.
704 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
705 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
706 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
707 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
708
709 (put 'multitable 'texinfo-format 'texinfo-multitable)
710
711 (ptexinfmt-defun-if-void texinfo-multitable ()
712   "Produce multi-column tables."
713
714 ;; This function pushes information onto the `texinfo-stack'.
715 ;; A stack element consists of:
716 ;;   - type-of-command, i.e., multitable
717 ;;   - the information about column widths, and
718 ;;   - the position of texinfo-command-start.
719 ;; e.g., ('multitable (1 2 3 4) 123)
720 ;; The command line is then deleted.
721   (texinfo-push-stack
722    'multitable
723    ;; push width information on stack
724    (texinfo-multitable-widths))
725   (texinfo-discard-line-with-args))
726
727 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
728 (ptexinfmt-defun-if-void texinfo-end-multitable ()
729   "Discard the @end multitable line and pop the stack of multitable."
730   (texinfo-discard-command)
731   (texinfo-pop-stack 'multitable))
732
733 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
734   "Return list of widths of each column in a multi-column table."
735   (let (texinfo-multitable-width-list)
736     ;; Fractions format:
737     ;;  @multitable @columnfractions .25 .3 .45
738     ;;
739     ;; Template format:
740     ;;  @multitable {Column 1 template} {Column 2} {Column 3 example}
741     ;; Place point before first argument
742     (skip-chars-forward " \t")
743     (cond
744      ;; Check for common misspelling
745      ((looking-at "@columnfraction ")
746       (error "In @multitable, @columnfractions misspelled"))
747      ;; Case 1: @columnfractions .25 .3 .45
748      ((looking-at "@columnfractions")
749       (forward-word 1)
750       (while (not (eolp))
751         (setq texinfo-multitable-width-list
752               (cons
753                (truncate
754                 (1-
755                  (* fill-column (read (get-buffer (current-buffer))))))
756                texinfo-multitable-width-list))))
757      ;;
758      ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
759      ((looking-at "{")
760       (let ((start-of-templates (point)))
761         (while (not (eolp))
762           (skip-chars-forward " \t")
763           (let* ((start-of-template (1+ (point)))
764                  (end-of-template
765                   ;; forward-sexp works with braces in Texinfo mode
766                   (progn (forward-sexp 1) (1- (point)))))
767             (setq texinfo-multitable-width-list
768                   (cons (- (progn
769                              (goto-char end-of-template)
770                              (current-column))
771                            (progn
772                              (goto-char start-of-template)
773                              (current-column)))
774                         texinfo-multitable-width-list))
775             ;; Remove carriage return from within a template, if any.
776             ;; This helps those those who want to use more than
777             ;; one line's worth of words in @multitable line.
778             (narrow-to-region start-of-template end-of-template)
779             (goto-char (point-min))
780             (while (search-forward "\n" nil t)
781               (delete-char -1))
782             (goto-char (point-max))
783             (widen)
784             (forward-char 1)))))
785      ;;
786      ;; Case 3: Trouble
787      (t
788       (error "\
789 You probably need to specify column widths for @multitable correctly")))
790     ;; Check whether columns fit on page.
791     (let ((desired-columns
792            (+
793             ;; between column spaces
794             (length texinfo-multitable-width-list)
795             ;; additional between column spaces, if any
796             texinfo-extra-inter-column-width
797             ;; sum of spaces for each entry
798             (apply '+ texinfo-multitable-width-list))))
799       (if (> desired-columns fill-column)
800           (error (format "\
801 Multi-column table width, %d chars, is greater than page width, %d chars."
802                          desired-columns fill-column))))
803     texinfo-multitable-width-list))
804
805 ;; @item  A1  @tab  A2  @tab  A3
806 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
807   "Return multitable row, as a string.
808 End of row is beginning of next @item or beginning of @end.
809 Cells within rows are separated by @tab."
810   (skip-chars-forward " \t")
811   (let* ((start (point))
812          (end (progn
813                 (re-search-forward "@item\\|@end")
814                 (match-beginning 0)))
815          (row (progn (goto-char end)
816                      (skip-chars-backward " ")
817                      ;; remove whitespace at end of argument
818                      (delete-region (point) end)
819                      (buffer-substring start (point)))))
820     (delete-region texinfo-command-start end)
821     row))
822
823 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
824 (ptexinfmt-defun-if-void texinfo-multitable-item ()
825   "Format a row within a multicolumn table.
826 Cells in row are separated by @tab.
827 Widths of cells are specified by the arguments in the @multitable line.
828 All cells are made to be the same height.
829 This command is executed when texinfmt sees @item inside @multitable."
830   (let ((original-buffer (current-buffer))
831         (table-widths (reverse (car (cdr (car texinfo-stack)))))
832         (existing-fill-column fill-column)
833         start
834         end
835         (table-column       0)
836         (table-entry-height 0)
837         ;; unformatted row looks like:  A1  @tab  A2  @tab  A3
838         ;; extract-row command deletes the source line in the table.
839         (unformated-row (texinfo-multitable-extract-row)))
840     ;; Use a temporary buffer
841     (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
842     (delete-region (point-min) (point-max))
843     (insert unformated-row)
844     (goto-char (point-min))
845 ;; 1. Check for correct number of @tab in line.
846     (let ((tab-number 1)) ;; one @tab between two columns
847       (while (search-forward "@tab" nil t)
848         (setq tab-number (1+ tab-number)))
849       (if (/= tab-number (length table-widths))
850           (error "Wrong number of @tab's in a @multitable row")))
851     (goto-char (point-min))
852 ;; 2. Format each cell, and copy to a rectangle
853     ;; buffer looks like this:    A1  @tab  A2  @tab  A3
854     ;; Cell #1: format up to @tab
855     ;; Cell #2: format up to @tab
856     ;; Cell #3: format up to eob
857     (while (not (eobp))
858       (setq start (point))
859       (setq end (save-excursion
860                   (if (search-forward "@tab" nil 'move)
861                       ;; Delete the @tab command, including the @-sign
862                       (delete-region
863                        (point)
864                        (progn (forward-word -1) (1- (point)))))
865                   (point)))
866       ;; Set fill-column *wider* than needed to produce inter-column space
867       (setq fill-column (+ 1
868                            texinfo-extra-inter-column-width
869                            (nth table-column table-widths)))
870       (narrow-to-region start end)
871       ;; Remove whitespace before and after entry.
872       (skip-chars-forward " ")
873       (delete-region (point) (save-excursion (beginning-of-line) (point)))
874       (goto-char (point-max))
875       (skip-chars-backward " ")
876       (delete-region (point) (save-excursion (end-of-line) (point)))
877       ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
878       ;; does not see an unterminated @multitable.
879       (let (texinfo-stack) ;; nil
880         (texinfo-format-scan))
881       (let (fill-prefix) ;; no fill prefix
882         (fill-region (point-min) (point-max)))
883       (setq table-entry-height
884             (max table-entry-height (count-lines (point-min) (point-max))))
885 ;; 3. Move point to end of bottom line, and pad that line to fill column.
886       (goto-char (point-min))
887       (forward-line (1- table-entry-height))
888       (let* ((beg (point)) ;; beginning of line
889              ;; add one more space for inter-column spacing
890              (needed-whitespace
891               (1+
892                (- fill-column
893                   (progn
894                     (end-of-line)
895                     (current-column)))))) ;; end of existing line
896         (insert (make-string
897                  (if (> needed-whitespace 0) needed-whitespace 1)
898                  ? )))
899       ;; now, put formatted cell into a rectangle
900       (set (intern (concat texinfo-multitable-rectangle-name
901                            (int-to-string table-column)))
902            (extract-rectangle (point-min) (point)))
903       (delete-region (point-min) (point))
904       (goto-char (point-max))
905       (setq table-column (1+ table-column))
906       (widen))
907 ;; 4. Add extra lines to rectangles so all are of same height
908     (let ((total-number-of-columns table-column)
909           (column-number 0)
910           here)
911       (while (> table-column 0)
912         (let ((this-rectangle (int-to-string table-column)))
913           (while (< (length this-rectangle) table-entry-height)
914             (setq this-rectangle (append this-rectangle '("")))))
915         (setq table-column (1- table-column)))
916 ;; 5. Insert formatted rectangles in original buffer
917       (switch-to-buffer original-buffer)
918       (open-line table-entry-height)
919       (while (< column-number total-number-of-columns)
920         (setq here (point))
921         (insert-rectangle
922          (eval (intern
923                 (concat texinfo-multitable-rectangle-name
924                         (int-to-string column-number)))))
925         (goto-char here)
926         (end-of-line)
927         (setq column-number (1+ column-number))))
928     (kill-buffer texinfo-multitable-buffer-name)
929     (setq fill-column existing-fill-column)))
930
931 \f
932 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
933   (let ((indexelts (symbol-value
934                     (cdr (assoc (texinfo-parse-arg-discard)
935                                 texinfo-indexvar-alist))))
936         opoint)
937     (insert "\n* Menu:\n\n")
938     (setq opoint (point))
939     (texinfo-print-index nil indexelts)
940
941     (if (memq system-type '(vax-vms windows-nt ms-dos))
942         (texinfo-sort-region opoint (point))
943       (shell-command-on-region opoint (point) "sort -fd" 1))))
944
945 (provide 'ptexinfmt)
946
947 ;;; ptexinfmt.el ends here