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