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