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