1 ;;; ptexinfmt.el -- portable Texinfo formatter.
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>
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
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.
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.
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.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
39 ;; Unimplemented command:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
61 (defvar ptexinfmt-disable-broken-notice-flag t
62 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
63 This is last argument in `ptexinfmt-broken-facility'.")
65 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
66 (defmacro ptexinfmt-broken-facility (facility docstring assertion
68 "Declare a symbol FACILITY is broken if ASSERTION is nil.
69 DOCSTRING will be printed if ASSERTION is nil and
70 `ptexinfmt-disable-broken-notice-flag' is nil."
71 (` (let ((facility '(, facility))
72 (docstring (, docstring))
73 (assertion (eval '(, assertion))))
74 (put facility 'broken (not assertion))
77 (put facility 'broken-docstring docstring)
78 (if ptexinfmt-disable-broken-notice-flag
80 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
82 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
83 (defmacro ptexinfmt-defun-if-broken (&rest args)
84 "Redefine a function just like `defun' if it is considered broken."
85 (let ((name (list 'quote (car args))))
86 (setq args (cdr args))
89 (if (get (, name) 'broken)
91 (function (lambda (,@ args)))))))))
93 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
94 (defmacro ptexinfmt-defun-if-void (&rest args)
95 "Define a function just like `defun' unless it is already defined."
96 (let ((name (list 'quote (car args))))
97 (setq args (cdr args))
100 (if (fboundp (, name))
103 (function (lambda (,@ args)))))))))
105 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
106 (defmacro ptexinfmt-defvar-if-void (&rest args)
107 "Define a variable just like `defvar' unless it is already defined."
108 (let ((name (car args)))
109 (setq args (cdr args))
112 (if (boundp '(, name))
114 (defvar (, name) (,@ args)))))))
117 (ptexinfmt-broken-facility texinfo-format-printindex
118 "Can't sort on Mule for Windows."
122 (ptexinfmt-broken-facility texinfo-format-var
123 "Don't perse @var argument."
126 (let (texinfo-enclosure-list texinfo-alias-list)
128 (insert "@var{@asis{foo}}\n")
129 (texinfo-format-expand-region (point-min) (point-max))
134 (ptexinfmt-broken-facility texinfo-format-xref
135 "Can't format @xref, 1st argument is empty."
138 (let (texinfo-enclosure-list texinfo-alias-list)
140 (insert "@xref{, xref, , file}\n")
141 (texinfo-format-expand-region (point-min) (point-max))
146 (ptexinfmt-broken-facility texinfo-format-uref
147 "Parse twice @uref argument."
150 (let (texinfo-enclosure-list texinfo-alias-list)
152 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
153 (texinfo-format-expand-region (point-min) (point-max))
158 (ptexinfmt-broken-facility texinfo-multitable-widths
159 "`texinfo-multitable-widths' unsupport wide-char."
160 (if (fboundp 'texinfo-multitable-widths)
162 (let ((str "
\e$BI}9-J8;z
\e(B"))
164 (insert (format " {%s}\n" str))
165 (goto-char (point-min))
166 (if (= (car (texinfo-multitable-widths)) (length str))
169 ;; function definition is void
172 (ptexinfmt-broken-facility texinfo-multitable-item
173 "`texinfo-multitable-item' unsupport wide-char."
174 (not (get 'texinfo-multitable-widths 'broken)))
177 ;;; Hardcopy and HTML (discard)
179 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
180 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
181 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
184 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
185 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
186 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
187 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
188 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
189 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
190 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
193 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
197 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
198 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
199 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
202 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'page 'texinfo-format 'texinfo-discard-line)
212 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
214 ;; @slanted{} (makeinfo 4.8 or later)
215 (put 'slanted 'texinfo-format 'texinfo-format-noop)
217 ;; @tie{} (makeinfo 4.3 or later)
218 (put 'tie 'texinfo-format 'texinfo-format-tie)
219 (ptexinfmt-defun-if-void texinfo-format-tie ()
220 (texinfo-parse-arg-discard)
226 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
227 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
228 (let ((str (texinfo-parse-arg-discard)))
229 (delete-region (point)
231 (skip-chars-forward " ")
233 (insert "INFO-DIR-SECTION " str "\n")))
236 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
237 (ptexinfmt-defun-if-void texinfo-format-direntry ()
238 (texinfo-push-stack 'direntry nil)
239 (texinfo-discard-line)
240 (insert "START-INFO-DIR-ENTRY\n"))
242 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
243 (ptexinfmt-defun-if-void texinfo-end-direntry ()
244 (texinfo-discard-command)
245 (insert "END-INFO-DIR-ENTRY\n\n")
246 (texinfo-pop-stack 'direntry))
250 ;; @detailmenu ... @end detailmenu
251 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
252 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
254 ;; @smalldisplay ... @end smalldisplay
255 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
256 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
258 ;; @smallformat ... @end smallformat
259 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
260 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
262 ;; @cartouche ... @end cartouche
263 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
264 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
268 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
269 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
270 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
272 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
273 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
274 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
276 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
277 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
278 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
280 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
281 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
282 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
284 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
285 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
286 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
287 (delete-region texinfo-command-start
288 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
291 ;; @html ... @end html (makeinfo 3.11 or later)
292 (put 'html 'texinfo-format 'texinfo-format-html)
293 (ptexinfmt-defun-if-void texinfo-format-html ()
294 (delete-region texinfo-command-start
295 (progn (re-search-forward "@end html[ \t]*\n")
298 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
299 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
300 (ptexinfmt-defun-if-void texinfo-format-docbook ()
301 (delete-region texinfo-command-start
302 (progn (re-search-forward "@end docbook[ \t]*\n")
305 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
306 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
307 (defun texinfo-format-ifhtml ()
308 (delete-region texinfo-command-start
309 (progn (re-search-forward "@end ifhtml[ \t]*\n")
312 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
313 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
314 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
315 (delete-region texinfo-command-start
316 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
319 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
320 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
321 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
322 (delete-region texinfo-command-start
323 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
328 ;; @indicateurl, @url, @env, @command,
329 (put 'env 'texinfo-format 'texinfo-format-code)
330 (put 'command 'texinfo-format 'texinfo-format-code)
332 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
333 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
336 (put 'acronym 'texinfo-format 'texinfo-format-var)
338 (ptexinfmt-defun-if-broken texinfo-format-var ()
339 (let ((arg (texinfo-parse-expanded-arg)))
340 (texinfo-discard-command)
341 (insert (upcase arg))))
344 (put 'key 'texinfo-format 'texinfo-format-key)
345 (ptexinfmt-defun-if-void texinfo-format-key ()
346 (insert (texinfo-parse-arg-discard))
347 (goto-char texinfo-command-start))
349 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
350 (put 'email 'texinfo-format 'texinfo-format-email)
351 (ptexinfmt-defun-if-void texinfo-format-email ()
352 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
353 Insert < ... > around EMAIL-ADDRESS."
354 (let ((args (texinfo-format-parse-args)))
355 (texinfo-discard-command)
358 (insert (nth 1 args) " <" (nth 0 args) ">")
359 (insert "<" (nth 0 args) ">"))))
362 (put 'option 'texinfo-format 'texinfo-format-option)
363 (ptexinfmt-defun-if-void texinfo-format-option ()
364 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
365 ;; `looking-at-backward' not available in v. 18.57, 20.2
366 ;; searched-for character is a control-H
367 (if (not (search-backward "\010"
368 (save-excursion (beginning-of-line) (point))
370 (insert "`" (texinfo-parse-arg-discard) "'")
371 (insert (texinfo-parse-arg-discard)))
372 (goto-char texinfo-command-start))
374 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
375 (put 'verb 'texinfo-format 'texinfo-format-verb)
376 (ptexinfmt-defun-if-void texinfo-format-verb ()
377 "Format text between non-quoted unique delimiter characters verbatim.
378 Enclose the verbatim text, including the delimiters, in braces. Print
379 text exactly as written (but not the delimiters) in a fixed-width.
381 For example, @verb\{|@|\} results in @ and
382 @verb\{+@'e?`!`+} results in @'e?`!`."
384 (let ((delimiter (buffer-substring-no-properties
385 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
386 (unless (looking-at "{")
387 (error "Not found: @verb start brace"))
388 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
389 (search-forward delimiter))
390 (delete-backward-char 1)
391 (unless (looking-at "}")
392 (error "Not found: @verb end brace"))
396 ;;; @LaTeX, @registeredsymbol{}
397 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
398 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
399 (texinfo-parse-arg-discard)
402 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
403 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
404 (texinfo-parse-arg-discard)
407 ;;; Accents and Special characters
408 ;; @pounds{} ==> # Pounds Sterling
409 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
410 (ptexinfmt-defun-if-void texinfo-format-pounds ()
411 (texinfo-parse-arg-discard)
414 ;; @ordf{} ==> a Spanish feminine
415 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
416 (ptexinfmt-defun-if-void texinfo-format-ordf ()
417 (texinfo-parse-arg-discard)
420 ;; @ordm{} ==> o Spanish masculine
421 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
422 (ptexinfmt-defun-if-void texinfo-format-ordm ()
423 (texinfo-parse-arg-discard)
426 ;; @OE{} ==> OE French-OE-ligature
427 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
428 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
429 (insert "OE" (texinfo-parse-arg-discard))
430 (goto-char texinfo-command-start))
433 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
434 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
435 (insert "oe" (texinfo-parse-arg-discard))
436 (goto-char texinfo-command-start))
438 ;; @AA{} ==> AA Scandinavian-A-with-circle
439 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
440 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
441 (insert "AA" (texinfo-parse-arg-discard))
442 (goto-char texinfo-command-start))
445 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
446 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
447 (insert "aa" (texinfo-parse-arg-discard))
448 (goto-char texinfo-command-start))
450 ;; @AE{} ==> AE Latin-Scandinavian-AE
451 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
452 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
453 (insert "AE" (texinfo-parse-arg-discard))
454 (goto-char texinfo-command-start))
457 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
458 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
459 (insert "ae" (texinfo-parse-arg-discard))
460 (goto-char texinfo-command-start))
462 ;; @ss{} ==> ss German-sharp-S
463 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
464 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
465 (insert "ss" (texinfo-parse-arg-discard))
466 (goto-char texinfo-command-start))
468 ;; @questiondown{} ==> ? upside-down-question-mark
469 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
470 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
471 (insert "?" (texinfo-parse-arg-discard))
472 (goto-char texinfo-command-start))
474 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
475 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
476 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
477 (insert "!" (texinfo-parse-arg-discard))
478 (goto-char texinfo-command-start))
480 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
481 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
482 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
483 (insert (texinfo-parse-arg-discard) "/L")
484 (goto-char texinfo-command-start))
486 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
487 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
488 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
489 (insert (texinfo-parse-arg-discard) "/l")
490 (goto-char texinfo-command-start))
492 ;; @O{} ==> O/ Scandinavian O-with-slash
493 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
494 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
495 (insert (texinfo-parse-arg-discard) "O/")
496 (goto-char texinfo-command-start))
498 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
499 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
500 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
501 (insert (texinfo-parse-arg-discard) "o/")
502 (goto-char texinfo-command-start))
504 ;; @,{c} ==> c, cedilla accent
505 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
506 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
507 (insert (texinfo-parse-arg-discard) ",")
508 (goto-char texinfo-command-start))
511 ;; @dotaccent{o} ==> .o overdot-accent
512 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
513 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
514 (insert "." (texinfo-parse-arg-discard))
515 (goto-char texinfo-command-start))
517 ;; @ubaraccent{o} ==> _o underbar-accent
518 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
519 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
520 (insert "_" (texinfo-parse-arg-discard))
521 (goto-char texinfo-command-start))
523 ;; @udotaccent{o} ==> o-. underdot-accent
524 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
525 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
526 (insert (texinfo-parse-arg-discard) "-.")
527 (goto-char texinfo-command-start))
529 ;; @H{o} ==> ""o long Hungarian umlaut
530 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
531 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
532 (insert "\"\"" (texinfo-parse-arg-discard))
533 (goto-char texinfo-command-start))
535 ;; @ringaccent{o} ==> *o ring accent
536 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
537 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
538 (insert "*" (texinfo-parse-arg-discard))
539 (goto-char texinfo-command-start))
541 ;; @tieaccent{oo} ==> [oo tie after accent
542 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
543 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
544 (insert "[" (texinfo-parse-arg-discard))
545 (goto-char texinfo-command-start))
547 ;; @u{o} ==> (o breve accent
548 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
549 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
550 (insert "(" (texinfo-parse-arg-discard))
551 (goto-char texinfo-command-start))
553 ;; @v{o} ==> <o hacek accent
554 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
555 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
556 (insert "<" (texinfo-parse-arg-discard))
557 (goto-char texinfo-command-start))
559 ;; @dotless{i} ==> i dotless i and dotless j
560 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
561 (ptexinfmt-defun-if-void texinfo-format-dotless ()
562 (insert (texinfo-parse-arg-discard))
563 (goto-char texinfo-command-start))
566 (put '\. 'texinfo-format 'texinfo-format-\.)
567 (ptexinfmt-defun-if-void texinfo-format-\. ()
568 (texinfo-discard-command)
572 (put '\: 'texinfo-format 'texinfo-format-\:)
573 (ptexinfmt-defun-if-void texinfo-format-\: ()
574 (texinfo-discard-command))
577 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
578 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
579 (texinfo-discard-command))
582 (put '\/ 'texinfo-format 'texinfo-format-\/)
583 (ptexinfmt-defun-if-void texinfo-format-\/ ()
584 (texinfo-discard-command))
589 (put 'ref 'texinfo-format 'texinfo-format-xref)
591 (ptexinfmt-defun-if-broken texinfo-format-xref ()
592 (let ((args (texinfo-format-parse-args)))
593 (texinfo-discard-command)
595 (let ((fname (or (nth 1 args) (nth 2 args))))
596 (if (null (or fname (nth 3 args)))
597 (insert (nth 0 args) "::")
598 (insert (or fname (nth 0 args)) ": ")
600 (insert "(" (nth 3 args) ")"))
601 (unless (null (nth 0 args))
602 (insert (nth 0 args)))))))
604 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
605 (put 'uref 'texinfo-format 'texinfo-format-uref)
606 (ptexinfmt-defun-if-broken texinfo-format-uref ()
607 "Format URL and optional URL-TITLE.
608 Insert ` ... ' around URL if no URL-TITLE argument;
609 otherwise, insert URL-TITLE followed by URL in parentheses."
610 (let ((args (texinfo-format-parse-args)))
611 (texinfo-discard-command)
614 (insert (nth 1 args) " (" (nth 0 args) ")")
615 (insert "`" (nth 0 args) "'"))))
618 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
619 (ptexinfmt-defun-if-void texinfo-format-inforef ()
620 (let ((args (texinfo-format-parse-args)))
621 (texinfo-discard-command)
623 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
624 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
629 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
630 ;; - Info-tagify suport @anthor-*-refill.
631 ;; - info.el support Ref in Tag table.
632 (unless (get 'anchor 'texinfo-format)
633 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
637 ;;; New command definition
638 ;; @alias NEW=EXISTING
639 (put 'alias 'texinfo-format 'texinfo-alias)
640 (ptexinfmt-defun-if-void texinfo-alias ()
641 (let ((start (1- (point)))
643 (skip-chars-forward " ")
644 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
645 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
646 (error "Invalid alias command")
647 (setq texinfo-alias-list
650 (buffer-substring (match-beginning 1) (match-end 1))
651 (buffer-substring (match-beginning 2) (match-end 2)))
653 (texinfo-discard-command))))
657 ;; @exampleindent INDENT (makeinfo 4.0 or later)
659 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
660 ;; INDENT: asis, 0, n
662 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
663 ;; WORD: none, insert
668 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
669 (put 'image 'texinfo-format 'texinfo-format-image)
670 (ptexinfmt-defun-if-void texinfo-format-image ()
671 ;; I don't know makeinfo parse FILENAME.
672 (let ((args (texinfo-format-parse-args))
674 (when (null (nth 0 args))
675 (error "Invalid image command"))
676 (texinfo-discard-command)
677 ;; makeinfo uses FILENAME.txt
678 (setq filename (format "%s.txt" (nth 0 args)))
679 (message "Reading included file: %s" filename)
680 ;; verbatim for Info output
681 (goto-char (+ (point) (cadr (insert-file-contents filename))))
682 (message "Reading included file: %s...done" filename)))
684 ;; @hyphenation command discards an argument within braces
685 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
686 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
687 "Discard both @-command and its argument in braces."
688 (goto-char texinfo-command-end)
690 (setq texinfo-command-end (point))
691 (delete-region texinfo-command-start texinfo-command-end))
694 ;;; @multitable ... @end multitable
695 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
696 "*Number of extra spaces between entries (columns) in @multitable.")
698 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
699 "*multitable-temporary-buffer*")
700 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
701 "texinfo-multitable-temp-")
703 ;; These commands are defined in texinfo.tex for printed output.
704 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
705 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
706 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
707 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
709 (put 'multitable 'texinfo-format 'texinfo-multitable)
711 (ptexinfmt-defun-if-void texinfo-multitable ()
712 "Produce multi-column tables."
714 ;; This function pushes information onto the `texinfo-stack'.
715 ;; A stack element consists of:
716 ;; - type-of-command, i.e., multitable
717 ;; - the information about column widths, and
718 ;; - the position of texinfo-command-start.
719 ;; e.g., ('multitable (1 2 3 4) 123)
720 ;; The command line is then deleted.
723 ;; push width information on stack
724 (texinfo-multitable-widths))
725 (texinfo-discard-line-with-args))
727 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
728 (ptexinfmt-defun-if-void texinfo-end-multitable ()
729 "Discard the @end multitable line and pop the stack of multitable."
730 (texinfo-discard-command)
731 (texinfo-pop-stack 'multitable))
733 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
734 "Return list of widths of each column in a multi-column table."
735 (let (texinfo-multitable-width-list)
737 ;; @multitable @columnfractions .25 .3 .45
740 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
741 ;; Place point before first argument
742 (skip-chars-forward " \t")
744 ;; Check for common misspelling
745 ((looking-at "@columnfraction ")
746 (error "In @multitable, @columnfractions misspelled"))
747 ;; Case 1: @columnfractions .25 .3 .45
748 ((looking-at "@columnfractions")
751 (setq texinfo-multitable-width-list
755 (* fill-column (read (get-buffer (current-buffer))))))
756 texinfo-multitable-width-list))))
758 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
760 (let ((start-of-templates (point)))
762 (skip-chars-forward " \t")
763 (let* ((start-of-template (1+ (point)))
765 ;; forward-sexp works with braces in Texinfo mode
766 (progn (forward-sexp 1) (1- (point)))))
767 (setq texinfo-multitable-width-list
769 (goto-char end-of-template)
772 (goto-char start-of-template)
774 texinfo-multitable-width-list))
775 ;; Remove carriage return from within a template, if any.
776 ;; This helps those those who want to use more than
777 ;; one line's worth of words in @multitable line.
778 (narrow-to-region start-of-template end-of-template)
779 (goto-char (point-min))
780 (while (search-forward "\n" nil t)
782 (goto-char (point-max))
789 You probably need to specify column widths for @multitable correctly")))
790 ;; Check whether columns fit on page.
791 (let ((desired-columns
793 ;; between column spaces
794 (length texinfo-multitable-width-list)
795 ;; additional between column spaces, if any
796 texinfo-extra-inter-column-width
797 ;; sum of spaces for each entry
798 (apply '+ texinfo-multitable-width-list))))
799 (if (> desired-columns fill-column)
801 Multi-column table width, %d chars, is greater than page width, %d chars."
802 desired-columns fill-column))))
803 texinfo-multitable-width-list))
805 ;; @item A1 @tab A2 @tab A3
806 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
807 "Return multitable row, as a string.
808 End of row is beginning of next @item or beginning of @end.
809 Cells within rows are separated by @tab."
810 (skip-chars-forward " \t")
811 (let* ((start (point))
813 (re-search-forward "@item\\|@end")
814 (match-beginning 0)))
815 (row (progn (goto-char end)
816 (skip-chars-backward " ")
817 ;; remove whitespace at end of argument
818 (delete-region (point) end)
819 (buffer-substring start (point)))))
820 (delete-region texinfo-command-start end)
823 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
824 (ptexinfmt-defun-if-void texinfo-multitable-item ()
825 "Format a row within a multicolumn table.
826 Cells in row are separated by @tab.
827 Widths of cells are specified by the arguments in the @multitable line.
828 All cells are made to be the same height.
829 This command is executed when texinfmt sees @item inside @multitable."
830 (let ((original-buffer (current-buffer))
831 (table-widths (reverse (car (cdr (car texinfo-stack)))))
832 (existing-fill-column fill-column)
836 (table-entry-height 0)
837 ;; unformatted row looks like: A1 @tab A2 @tab A3
838 ;; extract-row command deletes the source line in the table.
839 (unformated-row (texinfo-multitable-extract-row)))
840 ;; Use a temporary buffer
841 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
842 (delete-region (point-min) (point-max))
843 (insert unformated-row)
844 (goto-char (point-min))
845 ;; 1. Check for correct number of @tab in line.
846 (let ((tab-number 1)) ;; one @tab between two columns
847 (while (search-forward "@tab" nil t)
848 (setq tab-number (1+ tab-number)))
849 (if (/= tab-number (length table-widths))
850 (error "Wrong number of @tab's in a @multitable row")))
851 (goto-char (point-min))
852 ;; 2. Format each cell, and copy to a rectangle
853 ;; buffer looks like this: A1 @tab A2 @tab A3
854 ;; Cell #1: format up to @tab
855 ;; Cell #2: format up to @tab
856 ;; Cell #3: format up to eob
859 (setq end (save-excursion
860 (if (search-forward "@tab" nil 'move)
861 ;; Delete the @tab command, including the @-sign
864 (progn (forward-word -1) (1- (point)))))
866 ;; Set fill-column *wider* than needed to produce inter-column space
867 (setq fill-column (+ 1
868 texinfo-extra-inter-column-width
869 (nth table-column table-widths)))
870 (narrow-to-region start end)
871 ;; Remove whitespace before and after entry.
872 (skip-chars-forward " ")
873 (delete-region (point) (save-excursion (beginning-of-line) (point)))
874 (goto-char (point-max))
875 (skip-chars-backward " ")
876 (delete-region (point) (save-excursion (end-of-line) (point)))
877 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
878 ;; does not see an unterminated @multitable.
879 (let (texinfo-stack) ;; nil
880 (texinfo-format-scan))
881 (let (fill-prefix) ;; no fill prefix
882 (fill-region (point-min) (point-max)))
883 (setq table-entry-height
884 (max table-entry-height (count-lines (point-min) (point-max))))
885 ;; 3. Move point to end of bottom line, and pad that line to fill column.
886 (goto-char (point-min))
887 (forward-line (1- table-entry-height))
888 (let* ((beg (point)) ;; beginning of line
889 ;; add one more space for inter-column spacing
895 (current-column)))))) ;; end of existing line
897 (if (> needed-whitespace 0) needed-whitespace 1)
899 ;; now, put formatted cell into a rectangle
900 (set (intern (concat texinfo-multitable-rectangle-name
901 (int-to-string table-column)))
902 (extract-rectangle (point-min) (point)))
903 (delete-region (point-min) (point))
904 (goto-char (point-max))
905 (setq table-column (1+ table-column))
907 ;; 4. Add extra lines to rectangles so all are of same height
908 (let ((total-number-of-columns table-column)
911 (while (> table-column 0)
912 (let ((this-rectangle (int-to-string table-column)))
913 (while (< (length this-rectangle) table-entry-height)
914 (setq this-rectangle (append this-rectangle '("")))))
915 (setq table-column (1- table-column)))
916 ;; 5. Insert formatted rectangles in original buffer
917 (switch-to-buffer original-buffer)
918 (open-line table-entry-height)
919 (while (< column-number total-number-of-columns)
923 (concat texinfo-multitable-rectangle-name
924 (int-to-string column-number)))))
927 (setq column-number (1+ column-number))))
928 (kill-buffer texinfo-multitable-buffer-name)
929 (setq fill-column existing-fill-column)))
932 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
933 (let ((indexelts (symbol-value
934 (cdr (assoc (texinfo-parse-arg-discard)
935 texinfo-indexvar-alist))))
937 (insert "\n* Menu:\n\n")
938 (setq opoint (point))
939 (texinfo-print-index nil indexelts)
941 (if (memq system-type '(vax-vms windows-nt ms-dos))
942 (texinfo-sort-region opoint (point))
943 (shell-command-on-region opoint (point) "sort -fd" 1))))
947 ;;; ptexinfmt.el ends here