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