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