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