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:
40 ;; @float, @caption, @shortcaption, @listoffloats
44 ;; @quotation (optional arguments)
45 ;; @acronym (optional argument)
46 ;; @dofirstparagraphindent
60 (defvar ptexinfmt-disable-broken-notice-flag t
61 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
62 This is last argument in `ptexinfmt-broken-facility'.")
64 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
65 (defmacro ptexinfmt-broken-facility (facility docstring assertion
67 "Declare a symbol FACILITY is broken if ASSERTION is nil.
68 DOCSTRING will be printed if ASSERTION is nil and
69 `ptexinfmt-disable-broken-notice-flag' is nil."
70 (` (let ((facility '(, facility))
71 (docstring (, docstring))
72 (assertion (eval '(, assertion))))
73 (put facility 'broken (not assertion))
76 (put facility 'broken-docstring docstring)
77 (if ptexinfmt-disable-broken-notice-flag
79 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
81 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
82 (defmacro ptexinfmt-defun-if-broken (&rest args)
83 "Redefine a function just like `defun' if it is considered broken."
84 (let ((name (list 'quote (car args))))
85 (setq args (cdr args))
88 (if (get (, name) 'broken)
90 (function (lambda (,@ args)))))))))
92 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
93 (defmacro ptexinfmt-defun-if-void (&rest args)
94 "Define a function just like `defun' unless it is already defined."
95 (let ((name (list 'quote (car args))))
96 (setq args (cdr args))
99 (if (fboundp (, name))
102 (function (lambda (,@ args)))))))))
104 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
105 (defmacro ptexinfmt-defvar-if-void (&rest args)
106 "Define a variable just like `defvar' unless it is already defined."
107 (let ((name (car args)))
108 (setq args (cdr args))
111 (if (boundp '(, name))
113 (defvar (, name) (,@ args)))))))
116 (ptexinfmt-broken-facility texinfo-format-printindex
117 "Can't sort on Mule for Windows."
121 (ptexinfmt-broken-facility texinfo-format-var
122 "Don't perse @var argument."
125 (let (texinfo-enclosure-list texinfo-alias-list)
127 (insert "@var{@asis{foo}}\n")
128 (texinfo-format-expand-region (point-min) (point-max))
133 (ptexinfmt-broken-facility texinfo-format-xref
134 "Can't format @xref, 1st argument is empty."
137 (let (texinfo-enclosure-list texinfo-alias-list)
139 (insert "@xref{, xref, , file}\n")
140 (texinfo-format-expand-region (point-min) (point-max))
145 (ptexinfmt-broken-facility texinfo-format-uref
146 "Parse twice @uref argument."
149 (let (texinfo-enclosure-list texinfo-alias-list)
151 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
152 (texinfo-format-expand-region (point-min) (point-max))
157 (ptexinfmt-broken-facility texinfo-multitable-widths
158 "`texinfo-multitable-widths' unsupport wide-char."
159 (if (fboundp 'texinfo-multitable-widths)
161 (let ((str "
\e$BI}9-J8;z
\e(B"))
163 (insert (format " {%s}\n" str))
164 (goto-char (point-min))
165 (if (= (car (texinfo-multitable-widths)) (length str))
168 ;; function definition is void
171 (ptexinfmt-broken-facility texinfo-multitable-item
172 "`texinfo-multitable-item' unsupport wide-char."
173 (not (get 'texinfo-multitable-widths 'broken)))
176 ;;; Hardcopy and HTML (discard)
178 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
179 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
180 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
183 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
184 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
185 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
186 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
187 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
188 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
189 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
192 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
193 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
196 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
197 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
198 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
202 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'page 'texinfo-format 'texinfo-discard-line)
211 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
213 ;; @s{} (makeinfo 4.8 or later)
214 (put 's 'texinfo-format 'texinfo-format-noop)
216 ;; @tie{} (makeinfo 4.3 or later)
217 (put 'tie 'texinfo-format 'texinfo-format-tie)
218 (ptexinfmt-defun-if-void texinfo-format-tie ()
219 (texinfo-parse-arg-discard)
225 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
226 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
227 (let ((str (texinfo-parse-arg-discard)))
228 (delete-region (point)
230 (skip-chars-forward " ")
232 (insert "INFO-DIR-SECTION " str "\n")))
235 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
236 (ptexinfmt-defun-if-void texinfo-format-direntry ()
237 (texinfo-push-stack 'direntry nil)
238 (texinfo-discard-line)
239 (insert "START-INFO-DIR-ENTRY\n"))
241 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
242 (ptexinfmt-defun-if-void texinfo-end-direntry ()
243 (texinfo-discard-command)
244 (insert "END-INFO-DIR-ENTRY\n\n")
245 (texinfo-pop-stack 'direntry))
249 ;; @detailmenu ... @end detailmenu
250 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
251 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
253 ;; @smalldisplay ... @end smalldisplay
254 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
255 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
257 ;; @smallformat ... @end smallformat
258 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
259 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
261 ;; @cartouche ... @end cartouche
262 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
263 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
267 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
268 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
269 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
271 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
272 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
273 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
275 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
276 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
277 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
279 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
280 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
281 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
283 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
284 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
285 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
286 (delete-region texinfo-command-start
287 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
290 ;; @html ... @end html (makeinfo 3.11 or later)
291 (put 'html 'texinfo-format 'texinfo-format-html)
292 (ptexinfmt-defun-if-void texinfo-format-html ()
293 (delete-region texinfo-command-start
294 (progn (re-search-forward "@end html[ \t]*\n")
297 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
298 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
299 (ptexinfmt-defun-if-void texinfo-format-docbook ()
300 (delete-region texinfo-command-start
301 (progn (re-search-forward "@end docbook[ \t]*\n")
304 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
305 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
306 (defun texinfo-format-ifhtml ()
307 (delete-region texinfo-command-start
308 (progn (re-search-forward "@end ifhtml[ \t]*\n")
311 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
312 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
313 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
314 (delete-region texinfo-command-start
315 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
318 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
319 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
320 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
321 (delete-region texinfo-command-start
322 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
327 ;; @indicateurl, @url, @env, @command,
328 (put 'env 'texinfo-format 'texinfo-format-code)
329 (put 'command 'texinfo-format 'texinfo-format-code)
331 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
332 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
335 (put 'acronym 'texinfo-format 'texinfo-format-var)
337 (ptexinfmt-defun-if-broken texinfo-format-var ()
338 (let ((arg (texinfo-parse-expanded-arg)))
339 (texinfo-discard-command)
340 (insert (upcase arg))))
343 (put 'key 'texinfo-format 'texinfo-format-key)
344 (ptexinfmt-defun-if-void texinfo-format-key ()
345 (insert (texinfo-parse-arg-discard))
346 (goto-char texinfo-command-start))
348 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
349 (put 'email 'texinfo-format 'texinfo-format-email)
350 (ptexinfmt-defun-if-void texinfo-format-email ()
351 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
352 Insert < ... > around EMAIL-ADDRESS."
353 (let ((args (texinfo-format-parse-args)))
354 (texinfo-discard-command)
357 (insert (nth 1 args) " <" (nth 0 args) ">")
358 (insert "<" (nth 0 args) ">"))))
361 (put 'option 'texinfo-format 'texinfo-format-option)
362 (ptexinfmt-defun-if-void texinfo-format-option ()
363 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
364 ;; `looking-at-backward' not available in v. 18.57, 20.2
365 ;; searched-for character is a control-H
366 (if (not (search-backward "\010"
367 (save-excursion (beginning-of-line) (point))
369 (insert "`" (texinfo-parse-arg-discard) "'")
370 (insert (texinfo-parse-arg-discard)))
371 (goto-char texinfo-command-start))
373 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
374 (put 'verb 'texinfo-format 'texinfo-format-verb)
375 (ptexinfmt-defun-if-void texinfo-format-verb ()
376 "Format text between non-quoted unique delimiter characters verbatim.
377 Enclose the verbatim text, including the delimiters, in braces. Print
378 text exactly as written (but not the delimiters) in a fixed-width.
380 For example, @verb\{|@|\} results in @ and
381 @verb\{+@'e?`!`+} results in @'e?`!`."
383 (let ((delimiter (buffer-substring-no-properties
384 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
385 (unless (looking-at "{")
386 (error "Not found: @verb start brace"))
387 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
388 (search-forward delimiter))
389 (delete-backward-char 1)
390 (unless (looking-at "}")
391 (error "Not found: @verb end brace"))
395 ;;; @LaTeX, @registeredsymbol{}
396 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
397 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
398 (texinfo-parse-arg-discard)
401 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
402 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
403 (texinfo-parse-arg-discard)
406 ;;; Accents and Special characters
407 ;; @pounds{} ==> # Pounds Sterling
408 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
409 (ptexinfmt-defun-if-void texinfo-format-pounds ()
410 (texinfo-parse-arg-discard)
413 ;; @ordf{} ==> a Spanish feminine
414 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
415 (ptexinfmt-defun-if-void texinfo-format-ordf ()
416 (texinfo-parse-arg-discard)
419 ;; @ordm{} ==> o Spanish masculine
420 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
421 (ptexinfmt-defun-if-void texinfo-format-ordm ()
422 (texinfo-parse-arg-discard)
425 ;; @OE{} ==> OE French-OE-ligature
426 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
427 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
428 (insert "OE" (texinfo-parse-arg-discard))
429 (goto-char texinfo-command-start))
432 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
433 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
434 (insert "oe" (texinfo-parse-arg-discard))
435 (goto-char texinfo-command-start))
437 ;; @AA{} ==> AA Scandinavian-A-with-circle
438 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
439 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
440 (insert "AA" (texinfo-parse-arg-discard))
441 (goto-char texinfo-command-start))
444 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
445 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
446 (insert "aa" (texinfo-parse-arg-discard))
447 (goto-char texinfo-command-start))
449 ;; @AE{} ==> AE Latin-Scandinavian-AE
450 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
451 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
452 (insert "AE" (texinfo-parse-arg-discard))
453 (goto-char texinfo-command-start))
456 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
457 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
458 (insert "ae" (texinfo-parse-arg-discard))
459 (goto-char texinfo-command-start))
461 ;; @ss{} ==> ss German-sharp-S
462 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
463 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
464 (insert "ss" (texinfo-parse-arg-discard))
465 (goto-char texinfo-command-start))
467 ;; @questiondown{} ==> ? upside-down-question-mark
468 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
469 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
470 (insert "?" (texinfo-parse-arg-discard))
471 (goto-char texinfo-command-start))
473 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
474 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
475 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
476 (insert "!" (texinfo-parse-arg-discard))
477 (goto-char texinfo-command-start))
479 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
480 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
481 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
482 (insert (texinfo-parse-arg-discard) "/L")
483 (goto-char texinfo-command-start))
485 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
486 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
487 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
488 (insert (texinfo-parse-arg-discard) "/l")
489 (goto-char texinfo-command-start))
491 ;; @O{} ==> O/ Scandinavian O-with-slash
492 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
493 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
494 (insert (texinfo-parse-arg-discard) "O/")
495 (goto-char texinfo-command-start))
497 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
498 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
499 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
500 (insert (texinfo-parse-arg-discard) "o/")
501 (goto-char texinfo-command-start))
503 ;; @,{c} ==> c, cedilla accent
504 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
505 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
506 (insert (texinfo-parse-arg-discard) ",")
507 (goto-char texinfo-command-start))
510 ;; @dotaccent{o} ==> .o overdot-accent
511 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
512 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
513 (insert "." (texinfo-parse-arg-discard))
514 (goto-char texinfo-command-start))
516 ;; @ubaraccent{o} ==> _o underbar-accent
517 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
518 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
519 (insert "_" (texinfo-parse-arg-discard))
520 (goto-char texinfo-command-start))
522 ;; @udotaccent{o} ==> o-. underdot-accent
523 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
524 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
525 (insert (texinfo-parse-arg-discard) "-.")
526 (goto-char texinfo-command-start))
528 ;; @H{o} ==> ""o long Hungarian umlaut
529 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
530 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
531 (insert "\"\"" (texinfo-parse-arg-discard))
532 (goto-char texinfo-command-start))
534 ;; @ringaccent{o} ==> *o ring accent
535 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
536 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
537 (insert "*" (texinfo-parse-arg-discard))
538 (goto-char texinfo-command-start))
540 ;; @tieaccent{oo} ==> [oo tie after accent
541 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
542 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
543 (insert "[" (texinfo-parse-arg-discard))
544 (goto-char texinfo-command-start))
546 ;; @u{o} ==> (o breve accent
547 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
548 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
549 (insert "(" (texinfo-parse-arg-discard))
550 (goto-char texinfo-command-start))
552 ;; @v{o} ==> <o hacek accent
553 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
554 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
555 (insert "<" (texinfo-parse-arg-discard))
556 (goto-char texinfo-command-start))
558 ;; @dotless{i} ==> i dotless i and dotless j
559 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
560 (ptexinfmt-defun-if-void texinfo-format-dotless ()
561 (insert (texinfo-parse-arg-discard))
562 (goto-char texinfo-command-start))
565 (put '\. 'texinfo-format 'texinfo-format-\.)
566 (ptexinfmt-defun-if-void texinfo-format-\. ()
567 (texinfo-discard-command)
571 (put '\: 'texinfo-format 'texinfo-format-\:)
572 (ptexinfmt-defun-if-void texinfo-format-\: ()
573 (texinfo-discard-command))
576 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
577 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
578 (texinfo-discard-command))
581 (put '\/ 'texinfo-format 'texinfo-format-\/)
582 (ptexinfmt-defun-if-void texinfo-format-\/ ()
583 (texinfo-discard-command))
588 (put 'ref 'texinfo-format 'texinfo-format-xref)
590 (ptexinfmt-defun-if-broken texinfo-format-xref ()
591 (let ((args (texinfo-format-parse-args)))
592 (texinfo-discard-command)
594 (let ((fname (or (nth 1 args) (nth 2 args))))
595 (if (null (or fname (nth 3 args)))
596 (insert (nth 0 args) "::")
597 (insert (or fname (nth 0 args)) ": ")
599 (insert "(" (nth 3 args) ")"))
600 (unless (null (nth 0 args))
601 (insert (nth 0 args)))))))
603 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
604 (put 'uref 'texinfo-format 'texinfo-format-uref)
605 (ptexinfmt-defun-if-broken texinfo-format-uref ()
606 "Format URL and optional URL-TITLE.
607 Insert ` ... ' around URL if no URL-TITLE argument;
608 otherwise, insert URL-TITLE followed by URL in parentheses."
609 (let ((args (texinfo-format-parse-args)))
610 (texinfo-discard-command)
613 (insert (nth 1 args) " (" (nth 0 args) ")")
614 (insert "`" (nth 0 args) "'"))))
617 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
618 (ptexinfmt-defun-if-void texinfo-format-inforef ()
619 (let ((args (texinfo-format-parse-args)))
620 (texinfo-discard-command)
622 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
623 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
628 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
629 ;; - Info-tagify suport @anthor-*-refill.
630 ;; - info.el support Ref in Tag table.
631 (unless (get 'anchor 'texinfo-format)
632 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
636 ;;; New command definition
637 ;; @alias NEW=EXISTING
638 (put 'alias 'texinfo-format 'texinfo-alias)
639 (ptexinfmt-defun-if-void texinfo-alias ()
640 (let ((start (1- (point)))
642 (skip-chars-forward " ")
643 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
644 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
645 (error "Invalid alias command")
646 (setq texinfo-alias-list
649 (buffer-substring (match-beginning 1) (match-end 1))
650 (buffer-substring (match-beginning 2) (match-end 2)))
652 (texinfo-discard-command))))
656 ;; @exampleindent INDENT (makeinfo 4.0 or later)
658 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
659 ;; INDENT: asis, 0, n
661 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
662 ;; WORD: none, insert
667 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
668 (put 'image 'texinfo-format 'texinfo-format-image)
669 (ptexinfmt-defun-if-void texinfo-format-image ()
670 ;; I don't know makeinfo parse FILENAME.
671 (let ((args (texinfo-format-parse-args))
673 (when (null (nth 0 args))
674 (error "Invalid image command"))
675 (texinfo-discard-command)
676 ;; makeinfo uses FILENAME.txt
677 (setq filename (format "%s.txt" (nth 0 args)))
678 (message "Reading included file: %s" filename)
679 ;; verbatim for Info output
680 (goto-char (+ (point) (cadr (insert-file-contents filename))))
681 (message "Reading included file: %s...done" filename)))
683 ;; @hyphenation command discards an argument within braces
684 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
685 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
686 "Discard both @-command and its argument in braces."
687 (goto-char texinfo-command-end)
689 (setq texinfo-command-end (point))
690 (delete-region texinfo-command-start texinfo-command-end))
693 ;;; @multitable ... @end multitable
694 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
695 "*Number of extra spaces between entries (columns) in @multitable.")
697 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
698 "*multitable-temporary-buffer*")
699 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
700 "texinfo-multitable-temp-")
702 ;; These commands are defined in texinfo.tex for printed output.
703 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
704 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
705 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
706 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
708 (put 'multitable 'texinfo-format 'texinfo-multitable)
710 (ptexinfmt-defun-if-void texinfo-multitable ()
711 "Produce multi-column tables."
713 ;; This function pushes information onto the `texinfo-stack'.
714 ;; A stack element consists of:
715 ;; - type-of-command, i.e., multitable
716 ;; - the information about column widths, and
717 ;; - the position of texinfo-command-start.
718 ;; e.g., ('multitable (1 2 3 4) 123)
719 ;; The command line is then deleted.
722 ;; push width information on stack
723 (texinfo-multitable-widths))
724 (texinfo-discard-line-with-args))
726 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
727 (ptexinfmt-defun-if-void texinfo-end-multitable ()
728 "Discard the @end multitable line and pop the stack of multitable."
729 (texinfo-discard-command)
730 (texinfo-pop-stack 'multitable))
732 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
733 "Return list of widths of each column in a multi-column table."
734 (let (texinfo-multitable-width-list)
736 ;; @multitable @columnfractions .25 .3 .45
739 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
740 ;; Place point before first argument
741 (skip-chars-forward " \t")
743 ;; Check for common misspelling
744 ((looking-at "@columnfraction ")
745 (error "In @multitable, @columnfractions misspelled"))
746 ;; Case 1: @columnfractions .25 .3 .45
747 ((looking-at "@columnfractions")
750 (setq texinfo-multitable-width-list
754 (* fill-column (read (get-buffer (current-buffer))))))
755 texinfo-multitable-width-list))))
757 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
759 (let ((start-of-templates (point)))
761 (skip-chars-forward " \t")
762 (let* ((start-of-template (1+ (point)))
764 ;; forward-sexp works with braces in Texinfo mode
765 (progn (forward-sexp 1) (1- (point)))))
766 (setq texinfo-multitable-width-list
768 (goto-char end-of-template)
771 (goto-char start-of-template)
773 texinfo-multitable-width-list))
774 ;; Remove carriage return from within a template, if any.
775 ;; This helps those those who want to use more than
776 ;; one line's worth of words in @multitable line.
777 (narrow-to-region start-of-template end-of-template)
778 (goto-char (point-min))
779 (while (search-forward "\n" nil t)
781 (goto-char (point-max))
788 You probably need to specify column widths for @multitable correctly")))
789 ;; Check whether columns fit on page.
790 (let ((desired-columns
792 ;; between column spaces
793 (length texinfo-multitable-width-list)
794 ;; additional between column spaces, if any
795 texinfo-extra-inter-column-width
796 ;; sum of spaces for each entry
797 (apply '+ texinfo-multitable-width-list))))
798 (if (> desired-columns fill-column)
800 Multi-column table width, %d chars, is greater than page width, %d chars."
801 desired-columns fill-column))))
802 texinfo-multitable-width-list))
804 ;; @item A1 @tab A2 @tab A3
805 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
806 "Return multitable row, as a string.
807 End of row is beginning of next @item or beginning of @end.
808 Cells within rows are separated by @tab."
809 (skip-chars-forward " \t")
810 (let* ((start (point))
812 (re-search-forward "@item\\|@end")
813 (match-beginning 0)))
814 (row (progn (goto-char end)
815 (skip-chars-backward " ")
816 ;; remove whitespace at end of argument
817 (delete-region (point) end)
818 (buffer-substring start (point)))))
819 (delete-region texinfo-command-start end)
822 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
823 (ptexinfmt-defun-if-void texinfo-multitable-item ()
824 "Format a row within a multicolumn table.
825 Cells in row are separated by @tab.
826 Widths of cells are specified by the arguments in the @multitable line.
827 All cells are made to be the same height.
828 This command is executed when texinfmt sees @item inside @multitable."
829 (let ((original-buffer (current-buffer))
830 (table-widths (reverse (car (cdr (car texinfo-stack)))))
831 (existing-fill-column fill-column)
835 (table-entry-height 0)
836 ;; unformatted row looks like: A1 @tab A2 @tab A3
837 ;; extract-row command deletes the source line in the table.
838 (unformated-row (texinfo-multitable-extract-row)))
839 ;; Use a temporary buffer
840 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
841 (delete-region (point-min) (point-max))
842 (insert unformated-row)
843 (goto-char (point-min))
844 ;; 1. Check for correct number of @tab in line.
845 (let ((tab-number 1)) ;; one @tab between two columns
846 (while (search-forward "@tab" nil t)
847 (setq tab-number (1+ tab-number)))
848 (if (/= tab-number (length table-widths))
849 (error "Wrong number of @tab's in a @multitable row")))
850 (goto-char (point-min))
851 ;; 2. Format each cell, and copy to a rectangle
852 ;; buffer looks like this: A1 @tab A2 @tab A3
853 ;; Cell #1: format up to @tab
854 ;; Cell #2: format up to @tab
855 ;; Cell #3: format up to eob
858 (setq end (save-excursion
859 (if (search-forward "@tab" nil 'move)
860 ;; Delete the @tab command, including the @-sign
863 (progn (forward-word -1) (1- (point)))))
865 ;; Set fill-column *wider* than needed to produce inter-column space
866 (setq fill-column (+ 1
867 texinfo-extra-inter-column-width
868 (nth table-column table-widths)))
869 (narrow-to-region start end)
870 ;; Remove whitespace before and after entry.
871 (skip-chars-forward " ")
872 (delete-region (point) (save-excursion (beginning-of-line) (point)))
873 (goto-char (point-max))
874 (skip-chars-backward " ")
875 (delete-region (point) (save-excursion (end-of-line) (point)))
876 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
877 ;; does not see an unterminated @multitable.
878 (let (texinfo-stack) ;; nil
879 (texinfo-format-scan))
880 (let (fill-prefix) ;; no fill prefix
881 (fill-region (point-min) (point-max)))
882 (setq table-entry-height
883 (max table-entry-height (count-lines (point-min) (point-max))))
884 ;; 3. Move point to end of bottom line, and pad that line to fill column.
885 (goto-char (point-min))
886 (forward-line (1- table-entry-height))
887 (let* ((beg (point)) ;; beginning of line
888 ;; add one more space for inter-column spacing
894 (current-column)))))) ;; end of existing line
896 (if (> needed-whitespace 0) needed-whitespace 1)
898 ;; now, put formatted cell into a rectangle
899 (set (intern (concat texinfo-multitable-rectangle-name
900 (int-to-string table-column)))
901 (extract-rectangle (point-min) (point)))
902 (delete-region (point-min) (point))
903 (goto-char (point-max))
904 (setq table-column (1+ table-column))
906 ;; 4. Add extra lines to rectangles so all are of same height
907 (let ((total-number-of-columns table-column)
910 (while (> table-column 0)
911 (let ((this-rectangle (int-to-string table-column)))
912 (while (< (length this-rectangle) table-entry-height)
913 (setq this-rectangle (append this-rectangle '("")))))
914 (setq table-column (1- table-column)))
915 ;; 5. Insert formatted rectangles in original buffer
916 (switch-to-buffer original-buffer)
917 (open-line table-entry-height)
918 (while (< column-number total-number-of-columns)
922 (concat texinfo-multitable-rectangle-name
923 (int-to-string column-number)))))
926 (setq column-number (1+ column-number))))
927 (kill-buffer texinfo-multitable-buffer-name)
928 (setq fill-column existing-fill-column)))
931 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
932 (let ((indexelts (symbol-value
933 (cdr (assoc (texinfo-parse-arg-discard)
934 texinfo-indexvar-alist))))
936 (insert "\n* Menu:\n\n")
937 (setq opoint (point))
938 (texinfo-print-index nil indexelts)
940 (if (memq system-type '(vax-vms windows-nt ms-dos))
941 (texinfo-sort-region opoint (point))
942 (shell-command-on-region opoint (point) "sort -fd" 1))))
946 ;;; ptexinfmt.el ends here