Update the default value of riece-url-regexp.
[riece] / doc / 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 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   (if (and (memq system-type '(windows-nt ms-dos))
125 ;;; I don't know version threshold.
126 ;;;        (string< texinfmt-version "2.37 of 24 May 1997")
127            (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
128       nil
129     t))
130
131 ;; @var{METASYNTACTIC-VARIABLE}
132 (ptexinfmt-broken-facility texinfo-format-var
133   "Don't perse @var argument."
134   (condition-case nil
135       (with-temp-buffer
136         (let (texinfo-enclosure-list texinfo-alias-list)
137           (texinfo-mode)
138           (insert "@var{@asis{foo}}\n")
139           (texinfo-format-expand-region (point-min) (point-max))
140           t))
141     (error nil)))
142
143 ;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
144 ;;     INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
145 (ptexinfmt-broken-facility texinfo-format-xref
146   "Can't format @xref, 1st argument is empty."
147   (condition-case nil
148       (with-temp-buffer
149         (let (texinfo-enclosure-list texinfo-alias-list)
150           (texinfo-mode)
151           (insert "@xref{, xref, , file}\n")
152           (texinfo-format-expand-region (point-min) (point-max))
153           t))
154     (error nil)))
155
156 ;; @uref{URL[, TEXT][, REPLACEMENT]}
157 (ptexinfmt-broken-facility texinfo-format-uref
158   "Parse twice @uref argument."
159   (condition-case nil
160       (with-temp-buffer
161         (let (texinfo-enclosure-list texinfo-alias-list)
162           (texinfo-mode)
163           (insert "@uref{mailto:foo@@noncommand.example.com}\n")
164           (texinfo-format-expand-region (point-min) (point-max))
165           t))
166     (error nil)))
167
168 ;; @multitable
169 (ptexinfmt-broken-facility texinfo-multitable-widths
170   "`texinfo-multitable-widths' unsupport wide-char."
171   (if (fboundp 'texinfo-multitable-widths)
172       (with-temp-buffer
173         (let ((str (string (make-char 'japanese-jisx0208 73 125)
174                            (make-char 'japanese-jisx0208 57 45)
175                            (make-char 'japanese-jisx0208 74 56)
176                            (make-char 'japanese-jisx0208 59 122))))
177           (texinfo-mode)
178           (insert (format " {%s}\n" str))
179           (goto-char (point-min))
180           (if (= (car (texinfo-multitable-widths)) (length str))
181               t
182             nil)))
183     ;; function definition is void
184     nil))
185
186 (ptexinfmt-broken-facility texinfo-multitable-item
187   "`texinfo-multitable-item' unsupport wide-char."
188   (not (get 'texinfo-multitable-widths 'broken)))
189
190
191 ;;; Hardcopy and HTML (discard)
192 ;; html
193 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
195 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
196
197 ;; size
198 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
199 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
200 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
201 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
202 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
203 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
204 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
206
207 ;; style
208 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
209 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
210
211 ;; flags
212 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
213 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
214 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
216
217 ;; head & foot
218 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
219 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
220 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
221 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
222 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
223 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
224 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
225
226 ;; misc
227 (put 'page 'texinfo-format 'texinfo-discard-line)
228 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
229
230 ;; @slanted{TEXT} (makeinfo 4.8 or later)
231 (put 'slanted 'texinfo-format 'texinfo-format-noop)
232
233 ;; @sansserif{TEXT} (makeinfo 4.8 or later)
234 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
235
236 ;; @tie{} (makeinfo 4.3 or later)
237 (put 'tie 'texinfo-format 'texinfo-format-tie)
238 (ptexinfmt-defun-if-void texinfo-format-tie ()
239   (texinfo-parse-arg-discard)
240   (insert " "))
241
242 \f
243 ;;; Directory File
244 ;; @direcategory DIRPART
245 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
246 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
247   (let ((str (texinfo-parse-arg-discard)))
248     (delete-region (point)
249                    (progn
250                      (skip-chars-forward " ")
251                      (point)))
252     (insert "INFO-DIR-SECTION " str "\n")))
253
254 ;; @direntry ... @end direntry
255 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
256 (ptexinfmt-defun-if-void texinfo-format-direntry ()
257   (texinfo-push-stack 'direntry nil)
258   (texinfo-discard-line)
259   (insert "START-INFO-DIR-ENTRY\n"))
260
261 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
262 (ptexinfmt-defun-if-void texinfo-end-direntry ()
263   (texinfo-discard-command)
264   (insert "END-INFO-DIR-ENTRY\n\n")
265   (texinfo-pop-stack 'direntry))
266
267
268 ;;; Block Enclosing
269 ;; @detailmenu ... @end detailmenu
270 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
271 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
272
273 ;; @smalldisplay ... @end smalldisplay
274 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
275 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
276
277 ;; @smallformat ... @end smallformat
278 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
279 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
280
281 ;; @cartouche  ... @end cartouche
282 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
283 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
284
285
286 ;;; Conditional
287 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
288 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
289 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
290
291 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
292 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
293 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
294
295 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
296 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
297 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
298
299 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
300 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
301 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
302
303 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
304 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
305 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
306   (delete-region texinfo-command-start
307                  (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
308                         (point))))
309
310 ;; @html ... @end html (makeinfo 3.11 or later)
311 (put 'html 'texinfo-format 'texinfo-format-html)
312 (ptexinfmt-defun-if-void texinfo-format-html ()
313   (delete-region texinfo-command-start
314                  (progn (re-search-forward "@end html[ \t]*\n")
315                         (point))))
316
317 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
318 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
319 (ptexinfmt-defun-if-void texinfo-format-docbook ()
320   (delete-region texinfo-command-start
321                  (progn (re-search-forward "@end docbook[ \t]*\n")
322                         (point))))
323
324 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
325 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
326 (defun texinfo-format-ifhtml ()
327   (delete-region texinfo-command-start
328                  (progn (re-search-forward "@end ifhtml[ \t]*\n")
329                         (point))))
330
331 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
332 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
333 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
334   (delete-region texinfo-command-start
335                  (progn (re-search-forward "@end ifplaintext[ \t]*\n")
336                         (point))))
337
338 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
339 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
340 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
341   (delete-region texinfo-command-start
342                  (progn (re-search-forward "@end ifdocbook[ \t]*\n")
343                         (point))))
344
345 \f
346 ;;; Marking
347 ;; @env{ENVIRONMENT-VARIABLE}
348 (put 'env 'texinfo-format 'texinfo-format-code)
349
350 ;; @command{COMMAND-NAME}
351 (put 'command 'texinfo-format 'texinfo-format-code)
352
353 ;; @indicateurl{INDICATEURL}
354 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
355
356 ;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
357 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
358
359 ;; @acronym{ACRONYM}
360 (put 'acronym 'texinfo-format 'texinfo-format-var)
361
362 ;; @var{METASYNTACTIC-VARIABLE}
363 (ptexinfmt-defun-if-broken texinfo-format-var ()
364   (let ((arg (texinfo-parse-expanded-arg)))
365     (texinfo-discard-command)
366     (insert (upcase arg))))
367
368 ;; @key{KEY-NAME}
369 (put 'key 'texinfo-format 'texinfo-format-key)
370 (ptexinfmt-defun-if-void texinfo-format-key ()
371   (insert (texinfo-parse-arg-discard))
372   (goto-char texinfo-command-start))
373
374 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
375 (put 'email 'texinfo-format 'texinfo-format-email)
376 (ptexinfmt-defun-if-void texinfo-format-email ()
377   "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
378 Insert < ... > around EMAIL-ADDRESS."
379   (let ((args (texinfo-format-parse-args)))
380   (texinfo-discard-command)
381     ;; if displayed-text
382     (if (nth 1 args)
383         (insert (nth 1 args) " <" (nth 0 args) ">")
384       (insert "<" (nth 0 args) ">"))))
385
386 ;; @option{OPTION-NAME}
387 (put 'option 'texinfo-format 'texinfo-format-option)
388 (ptexinfmt-defun-if-void texinfo-format-option ()
389   "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
390   ;; `looking-at-backward' not available in v. 18.57, 20.2
391   ;; searched-for character is a control-H
392   (if (not (search-backward "\010"
393                             (save-excursion (beginning-of-line) (point))
394                             t))
395       (insert "`" (texinfo-parse-arg-discard) "'")
396     (insert (texinfo-parse-arg-discard)))
397   (goto-char texinfo-command-start))
398
399 ;; @verb{<char>TEXT<char>}  (makeinfo 4.1 or later)
400 (put 'verb 'texinfo-format 'texinfo-format-verb)
401 (ptexinfmt-defun-if-void texinfo-format-verb ()
402   "Format text between non-quoted unique delimiter characters verbatim.
403 Enclose the verbatim text, including the delimiters, in braces.  Print
404 text exactly as written (but not the delimiters) in a fixed-width.
405
406 For example, @verb\{|@|\} results in @ and
407 @verb\{+@'e?`!`+} results in @'e?`!`."
408
409   (let ((delimiter (buffer-substring-no-properties
410                     (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
411     (unless (looking-at "{")
412       (error "Not found: @verb start brace"))
413     (delete-region texinfo-command-start (+ 2 texinfo-command-end))
414     (search-forward  delimiter))
415   (delete-char -1)
416   (unless (looking-at "}")
417     (error "Not found: @verb end brace"))
418   (delete-char 1))
419
420 \f
421 ;; @LaTeX{}
422 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
423 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
424   (texinfo-parse-arg-discard)
425   (insert "LaTeX"))
426
427 ;; @registeredsymbol{}
428 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
429 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
430   (texinfo-parse-arg-discard)
431   (insert "(R)"))
432
433 ;;; Accents and Special characters
434 ;; @euro{}      ==>     Euro
435 (put 'euro 'texinfo-format 'texinfo-format-euro)
436 (ptexinfmt-defun-if-void texinfo-format-euro ()
437   (texinfo-parse-arg-discard)
438   (insert "Euro "))
439
440 ;; @pounds{}    ==>     #       Pounds Sterling
441 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
442 (ptexinfmt-defun-if-void texinfo-format-pounds ()
443   (texinfo-parse-arg-discard)
444   (insert "#"))
445
446 ;; @ordf{}      ==>     a       Spanish feminine
447 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
448 (ptexinfmt-defun-if-void texinfo-format-ordf ()
449   (texinfo-parse-arg-discard)
450   (insert "a"))
451
452 ;; @ordm{}      ==>     o       Spanish masculine
453 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
454 (ptexinfmt-defun-if-void texinfo-format-ordm ()
455   (texinfo-parse-arg-discard)
456   (insert "o"))
457
458 ;; @OE{}        ==>     OE      French-OE-ligature
459 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
460 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
461   (insert "OE" (texinfo-parse-arg-discard))
462   (goto-char texinfo-command-start))
463
464 ;; @oe{}        ==>     oe
465 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
466 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
467   (insert "oe" (texinfo-parse-arg-discard))
468   (goto-char texinfo-command-start))
469
470 ;; @AA{}        ==>     AA      Scandinavian-A-with-circle
471 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
472 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
473   (insert "AA" (texinfo-parse-arg-discard))
474   (goto-char texinfo-command-start))
475
476 ;; @aa{}        ==>     aa
477 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
478 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
479   (insert "aa" (texinfo-parse-arg-discard))
480   (goto-char texinfo-command-start))
481
482 ;; @AE{}        ==>     AE      Latin-Scandinavian-AE
483 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
484 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
485   (insert "AE" (texinfo-parse-arg-discard))
486   (goto-char texinfo-command-start))
487
488 ;; @ae{}        ==>     ae
489 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
490 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
491   (insert "ae" (texinfo-parse-arg-discard))
492   (goto-char texinfo-command-start))
493
494 ;; @ss{}        ==>     ss      German-sharp-S
495 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
496 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
497   (insert "ss" (texinfo-parse-arg-discard))
498   (goto-char texinfo-command-start))
499
500 ;; @questiondown{}      ==>     ?       upside-down-question-mark
501 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
502 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
503   (insert "?" (texinfo-parse-arg-discard))
504   (goto-char texinfo-command-start))
505
506 ;; @exclamdown{}        ==>     !       upside-down-exclamation-mark
507 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
508 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
509   (insert "!" (texinfo-parse-arg-discard))
510   (goto-char texinfo-command-start))
511
512 ;; @L{}         ==>     L/      Polish suppressed-L (Lslash)
513 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
514 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
515   (insert (texinfo-parse-arg-discard) "/L")
516   (goto-char texinfo-command-start))
517
518 ;; @l{}         ==>     l/      Polish suppressed-L (Lslash) (lower case)
519 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
520 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
521   (insert (texinfo-parse-arg-discard) "/l")
522   (goto-char texinfo-command-start))
523
524 ;; @O{}         ==>     O/      Scandinavian O-with-slash
525 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
526 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
527   (insert (texinfo-parse-arg-discard) "O/")
528   (goto-char texinfo-command-start))
529
530 ;; @o{}         ==>     o/      Scandinavian O-with-slash (lower case)
531 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
532 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
533   (insert (texinfo-parse-arg-discard) "o/")
534   (goto-char texinfo-command-start))
535
536 ;; @,{c}        ==>     c,      cedilla accent
537 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
538 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
539   (insert (texinfo-parse-arg-discard) ",")
540   (goto-char texinfo-command-start))
541
542
543 ;; @dotaccent{o}        ==>     .o      overdot-accent
544 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
545 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
546   (insert "." (texinfo-parse-arg-discard))
547   (goto-char texinfo-command-start))
548
549 ;; @ubaraccent{o}       ==>     _o      underbar-accent
550 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
551 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
552   (insert "_" (texinfo-parse-arg-discard))
553   (goto-char texinfo-command-start))
554
555 ;; @udotaccent{o}       ==>     o-.     underdot-accent
556 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
557 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
558   (insert (texinfo-parse-arg-discard) "-.")
559   (goto-char texinfo-command-start))
560
561 ;; @H{o}        ==>     ""o     long Hungarian umlaut
562 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
563 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
564   (insert "\"\"" (texinfo-parse-arg-discard))
565   (goto-char texinfo-command-start))
566
567 ;; @ringaccent{o}       ==>     *o      ring accent
568 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
569 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
570   (insert "*" (texinfo-parse-arg-discard))
571   (goto-char texinfo-command-start))
572
573 ;; @tieaccent{oo}       ==>     [oo     tie after accent
574 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
575 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
576   (insert "[" (texinfo-parse-arg-discard))
577   (goto-char texinfo-command-start))
578
579 ;; @u{o}        ==>     (o      breve accent
580 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
581 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
582   (insert "(" (texinfo-parse-arg-discard))
583   (goto-char texinfo-command-start))
584
585 ;; @v{o}        ==>     <o      hacek accent
586 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
587 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
588   (insert "<" (texinfo-parse-arg-discard))
589   (goto-char texinfo-command-start))
590
591 ;; @dotless{i}  ==>     i       dotless i and dotless j
592 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
593 (ptexinfmt-defun-if-void texinfo-format-dotless ()
594   (insert (texinfo-parse-arg-discard))
595   (goto-char texinfo-command-start))
596
597 ;; @.
598 (put '\. 'texinfo-format 'texinfo-format-\.)
599 (ptexinfmt-defun-if-void texinfo-format-\. ()
600   (texinfo-discard-command)
601   (insert "."))
602
603 ;; @:
604 (put '\: 'texinfo-format 'texinfo-format-\:)
605 (ptexinfmt-defun-if-void texinfo-format-\: ()
606   (texinfo-discard-command))
607
608 ;; @-
609 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
610 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
611   (texinfo-discard-command))
612
613 ;; @/
614 (put '\/ 'texinfo-format 'texinfo-format-\/)
615 (ptexinfmt-defun-if-void texinfo-format-\/ ()
616   (texinfo-discard-command))
617
618 ;; @textdegree{}
619 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
620 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
621   (insert "o" (texinfo-parse-arg-discard))
622   (goto-char texinfo-command-start))
623
624 ;; @geq{}
625 (put 'geq 'texinfo-format 'texinfo-format-geq)
626 (ptexinfmt-defun-if-void texinfo-format-geq ()
627   (insert ">=" (texinfo-parse-arg-discard))
628   (goto-char texinfo-command-start))
629
630 ;; @leq{}
631 (put 'leq 'texinfo-format 'texinfo-format-leq)
632 (ptexinfmt-defun-if-void texinfo-format-leq ()
633   (insert "<=" (texinfo-parse-arg-discard))
634   (goto-char texinfo-command-start))
635
636 \f
637 ;;; Cross References
638 ;; @ref{NODE-NAME, ...}
639 ;; @xref{NODE-NAME, ...}
640 (put 'ref 'texinfo-format 'texinfo-format-xref)
641
642 (ptexinfmt-defun-if-broken texinfo-format-xref ()
643   (let ((args (texinfo-format-parse-args)))
644     (texinfo-discard-command)
645     (insert "*Note ")
646     (let ((fname (or (nth 1 args) (nth 2 args))))
647       (if (null (or fname (nth 3 args)))
648           (insert (nth 0 args) "::")
649         (insert (or fname (nth 0 args)) ": ")
650         (if (nth 3 args)
651             (insert "(" (nth 3 args) ")"))
652         (unless (null (nth 0 args))
653           (insert (nth 0 args)))))))
654
655 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
656 (put 'uref 'texinfo-format 'texinfo-format-uref)
657 (ptexinfmt-defun-if-broken texinfo-format-uref ()
658   "Format URL and optional URL-TITLE.
659 Insert ` ... ' around URL if no URL-TITLE argument;
660 otherwise, insert URL-TITLE followed by URL in parentheses."
661   (let ((args (texinfo-format-parse-args)))
662     (texinfo-discard-command)
663     ;; if url-title
664     (if (nth 1 args)
665         (insert  (nth 1 args) " (" (nth 0 args) ")")
666       (insert "`" (nth 0 args) "'"))))
667
668 ;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
669 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
670 (ptexinfmt-defun-if-void texinfo-format-inforef ()
671   (let ((args (texinfo-format-parse-args)))
672     (texinfo-discard-command)
673     (if (nth 1 args)
674         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
675       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
676
677
678 ;; @anchor{NAME}
679 ;; don't emulation
680 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
681 ;;  - Info-tagify suport @anthor-*-refill.
682 ;;  - info.el support Ref in Tag table.
683 (unless (get 'anchor 'texinfo-format)
684   (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
685
686
687 \f
688 ;;; New command definition
689 ;; @alias NEW=EXISTING
690 (put 'alias 'texinfo-format 'texinfo-alias)
691 (ptexinfmt-defun-if-void texinfo-alias ()
692   (let ((start (1- (point)))
693         args)
694     (skip-chars-forward " ")
695     (save-excursion (end-of-line) (setq texinfo-command-end (point)))
696     (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
697         (error "Invalid alias command")
698       (setq texinfo-alias-list
699             (cons
700              (cons
701               (buffer-substring (match-beginning 1) (match-end 1))
702               (buffer-substring (match-beginning 2) (match-end 2)))
703              texinfo-alias-list))
704       (texinfo-discard-command))))
705
706 \f
707 ;;; Indent
708 ;; @exampleindent INDENT  (makeinfo 4.0 or later)
709
710 ;; @paragraphindent INDENT  (makeinfo 4.0 or later)
711 ;; INDENT: asis, 0, n
712
713 ;; @firstparagraphindent WORD   (makeinfo 4.6 or later)
714 ;; WORD: none, insert
715
716
717 \f
718 ;;; Special
719 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
720 (put 'image 'texinfo-format 'texinfo-format-image)
721 (ptexinfmt-defun-if-void texinfo-format-image ()
722   ;; I don't know makeinfo parse FILENAME.
723   (let ((args (texinfo-format-parse-args))
724         filename)
725     (when (null (nth 0 args))
726       (error "Invalid image command"))
727     (texinfo-discard-command)
728     ;; makeinfo uses FILENAME.txt
729     (setq filename (format "%s.txt" (nth 0 args)))
730     (message "Reading included file: %s" filename)
731     ;; verbatim for Info output
732     (goto-char (+ (point) (cadr (insert-file-contents filename))))
733     (message "Reading included file: %s...done" filename)))
734
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