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