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