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.
45 (defvar ptexinfmt-disable-broken-notice-flag t
46 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
47 This is last argument in `ptexinfmt-broken-facility'.")
49 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
50 (defmacro ptexinfmt-broken-facility (facility docstring assertion
52 "Declare a symbol FACILITY is broken if ASSERTION is nil.
53 DOCSTRING will be printed if ASSERTION is nil and
54 `ptexinfmt-disable-broken-notice-flag' is nil."
55 (` (let ((facility '(, facility))
56 (docstring (, docstring))
57 (assertion (eval '(, assertion))))
58 (put facility 'broken (not assertion))
61 (put facility 'broken-docstring docstring)
62 (if ptexinfmt-disable-broken-notice-flag
64 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
66 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
67 (defmacro ptexinfmt-defun-if-broken (&rest args)
68 "Redefine a function just like `defun' if it is considered broken."
69 (let ((name (list 'quote (car args))))
70 (setq args (cdr args))
73 (if (get (, name) 'broken)
75 (function (lambda (,@ args)))))))))
77 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
78 (defmacro ptexinfmt-defun-if-void (&rest args)
79 "Define a function just like `defun' unless it is already defined."
80 (let ((name (list 'quote (car args))))
81 (setq args (cdr args))
84 (if (fboundp (, name))
87 (function (lambda (,@ args)))))))))
89 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
90 (defmacro ptexinfmt-defvar-if-void (&rest args)
91 "Define a variable just like `defvar' unless it is already defined."
92 (let ((name (car args)))
93 (setq args (cdr args))
96 (if (boundp '(, name))
98 (defvar (, name) (,@ args)))))))
101 (ptexinfmt-broken-facility texinfo-format-printindex
102 "Can't sort on Mule for Windows."
103 (if (and (memq system-type '(windows-nt ms-dos))
104 ;;; I don't know version threshold.
105 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
106 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
111 (ptexinfmt-broken-facility texinfo-format-var
112 "Don't perse @var argument."
115 (let (texinfo-enclosure-list texinfo-alias-list)
117 (insert "@var{@asis{foo}}\n")
118 (texinfo-format-expand-region (point-min) (point-max))
123 (ptexinfmt-broken-facility texinfo-format-xref
124 "Can't format @xref, 1st argument is empty."
127 (let (texinfo-enclosure-list texinfo-alias-list)
129 (insert "@xref{, xref, , file}\n")
130 (texinfo-format-expand-region (point-min) (point-max))
135 (ptexinfmt-broken-facility texinfo-format-uref
136 "Parse twice @uref argument."
139 (let (texinfo-enclosure-list texinfo-alias-list)
141 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
142 (texinfo-format-expand-region (point-min) (point-max))
147 (ptexinfmt-broken-facility texinfo-multitable-widths
148 "`texinfo-multitable-widths' unsupport wide-char."
149 (if (fboundp 'texinfo-multitable-widths)
151 (let ((str "
\e$BI}9-J8;z
\e(B"))
153 (insert (format " {%s}\n" str))
154 (goto-char (point-min))
155 (if (= (car (texinfo-multitable-widths)) (length str))
158 ;; function definition is void
161 (ptexinfmt-broken-facility texinfo-multitable-item
162 "`texinfo-multitable-item' unsupport wide-char."
163 (not (get 'texinfo-multitable-widths 'broken)))
166 ;;; Hardcopy and HTML (discard)
168 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
169 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
170 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
173 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
174 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
175 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
176 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
177 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
178 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
179 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
182 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
183 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
186 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
187 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
188 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
191 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
192 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
193 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
195 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
196 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
197 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'page 'texinfo-format 'texinfo-discard-line)
201 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
203 ;; @tie{} (makeinfo 4.3 or later)
204 (put 'tie 'texinfo-format 'texinfo-format-tie)
205 (ptexinfmt-defun-if-void texinfo-format-tie ()
206 (texinfo-parse-arg-discard)
212 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
213 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
214 (let ((str (texinfo-parse-arg-discard)))
215 (delete-region (point)
217 (skip-chars-forward " ")
219 (insert "INFO-DIR-SECTION " str "\n")))
222 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
223 (ptexinfmt-defun-if-void texinfo-format-direntry ()
224 (texinfo-push-stack 'direntry nil)
225 (texinfo-discard-line)
226 (insert "START-INFO-DIR-ENTRY\n"))
228 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
229 (ptexinfmt-defun-if-void texinfo-end-direntry ()
230 (texinfo-discard-command)
231 (insert "END-INFO-DIR-ENTRY\n\n")
232 (texinfo-pop-stack 'direntry))
236 ;; @detailmenu ... @end detailmenu
237 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
238 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
240 ;; @smalldisplay ... @end smalldisplay
241 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
242 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
244 ;; @smallformat ... @end smallformat
245 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
246 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
248 ;; @cartouche ... @end cartouche
249 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
250 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
254 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
255 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
256 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
258 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
259 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
260 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
262 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
263 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
264 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
266 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
267 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
268 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
271 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
272 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
273 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
274 (delete-region texinfo-command-start
275 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
278 ;; @html ... @end html (makeinfo 3.11 or later)
279 (put 'html 'texinfo-format 'texinfo-format-html)
280 (ptexinfmt-defun-if-void texinfo-format-html ()
281 (delete-region texinfo-command-start
282 (progn (re-search-forward "@end html[ \t]*\n")
285 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
286 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
287 (ptexinfmt-defun-if-void texinfo-format-docbook ()
288 (delete-region texinfo-command-start
289 (progn (re-search-forward "@end docbook[ \t]*\n")
292 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
293 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
294 (defun texinfo-format-ifhtml ()
295 (delete-region texinfo-command-start
296 (progn (re-search-forward "@end ifhtml[ \t]*\n")
299 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
300 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
301 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
302 (delete-region texinfo-command-start
303 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
306 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
307 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
308 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
309 (delete-region texinfo-command-start
310 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
316 ;; @url, @env, @command
317 (put 'url 'texinfo-format 'texinfo-format-code)
318 (put 'env 'texinfo-format 'texinfo-format-code)
319 (put 'command 'texinfo-format 'texinfo-format-code)
322 (put 'acronym 'texinfo-format 'texinfo-format-var)
324 (ptexinfmt-defun-if-broken texinfo-format-var ()
325 (let ((arg (texinfo-parse-expanded-arg)))
326 (texinfo-discard-command)
327 (insert (upcase arg))))
330 (put 'key 'texinfo-format 'texinfo-format-key)
331 (ptexinfmt-defun-if-void texinfo-format-key ()
332 (insert (texinfo-parse-arg-discard))
333 (goto-char texinfo-command-start))
335 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
336 (put 'email 'texinfo-format 'texinfo-format-email)
337 (ptexinfmt-defun-if-void texinfo-format-email ()
338 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
339 Insert < ... > around EMAIL-ADDRESS."
340 (let ((args (texinfo-format-parse-args)))
341 (texinfo-discard-command)
344 (insert (nth 1 args) " <" (nth 0 args) ">")
345 (insert "<" (nth 0 args) ">"))))
348 (put 'option 'texinfo-format 'texinfo-format-option)
349 (ptexinfmt-defun-if-void texinfo-format-option ()
350 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
351 ;; `looking-at-backward' not available in v. 18.57, 20.2
352 ;; searched-for character is a control-H
353 (if (not (search-backward "\010"
354 (save-excursion (beginning-of-line) (point))
356 (insert "`" (texinfo-parse-arg-discard) "'")
357 (insert (texinfo-parse-arg-discard)))
358 (goto-char texinfo-command-start))
360 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
361 (put 'verb 'texinfo-format 'texinfo-format-verb)
362 (ptexinfmt-defun-if-void texinfo-format-verb ()
363 "Format text between non-quoted unique delimiter characters verbatim.
364 Enclose the verbatim text, including the delimiters, in braces. Print
365 text exactly as written (but not the delimiters) in a fixed-width.
367 For example, @verb\{|@|\} results in @ and
368 @verb\{+@'e?`!`+} results in @'e?`!`."
370 (let ((delimiter (buffer-substring-no-properties
371 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
372 (unless (looking-at "{")
373 (error "Not found: @verb start brace"))
374 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
375 (search-forward delimiter))
376 (delete-backward-char 1)
377 (unless (looking-at "}")
378 (error "Not found: @verb end brace"))
382 ;;; Accents and Special characters
383 ;; @registeredsymbol{} ==> (R)
384 (put 'pounds 'texinfo-format 'texinfo-format-registeredsymbol)
385 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
386 (texinfo-parse-arg-discard)
389 ;; @pounds{} ==> # Pounds Sterling
390 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
391 (ptexinfmt-defun-if-void texinfo-format-pounds ()
392 (texinfo-parse-arg-discard)
395 ;; @OE{} ==> OE French-OE-ligature
396 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
397 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
398 (insert "OE" (texinfo-parse-arg-discard))
399 (goto-char texinfo-command-start))
402 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
403 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
404 (insert "oe" (texinfo-parse-arg-discard))
405 (goto-char texinfo-command-start))
407 ;; @AA{} ==> AA Scandinavian-A-with-circle
408 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
409 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
410 (insert "AA" (texinfo-parse-arg-discard))
411 (goto-char texinfo-command-start))
414 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
415 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
416 (insert "aa" (texinfo-parse-arg-discard))
417 (goto-char texinfo-command-start))
419 ;; @AE{} ==> AE Latin-Scandinavian-AE
420 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
421 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
422 (insert "AE" (texinfo-parse-arg-discard))
423 (goto-char texinfo-command-start))
426 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
427 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
428 (insert "ae" (texinfo-parse-arg-discard))
429 (goto-char texinfo-command-start))
431 ;; @ss{} ==> ss German-sharp-S
432 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
433 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
434 (insert "ss" (texinfo-parse-arg-discard))
435 (goto-char texinfo-command-start))
437 ;; @questiondown{} ==> ? upside-down-question-mark
438 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
439 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
440 (insert "?" (texinfo-parse-arg-discard))
441 (goto-char texinfo-command-start))
443 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
444 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
445 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
446 (insert "!" (texinfo-parse-arg-discard))
447 (goto-char texinfo-command-start))
449 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
450 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
451 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
452 (insert (texinfo-parse-arg-discard) "/L")
453 (goto-char texinfo-command-start))
455 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
456 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
457 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
458 (insert (texinfo-parse-arg-discard) "/l")
459 (goto-char texinfo-command-start))
461 ;; @O{} ==> O/ Scandinavian O-with-slash
462 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
463 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
464 (insert (texinfo-parse-arg-discard) "O/")
465 (goto-char texinfo-command-start))
467 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
468 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
469 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
470 (insert (texinfo-parse-arg-discard) "o/")
471 (goto-char texinfo-command-start))
473 ;; @,{c} ==> c, cedilla accent
474 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
475 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
476 (insert (texinfo-parse-arg-discard) ",")
477 (goto-char texinfo-command-start))
480 ;; @dotaccent{o} ==> .o overdot-accent
481 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
482 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
483 (insert "." (texinfo-parse-arg-discard))
484 (goto-char texinfo-command-start))
486 ;; @ubaraccent{o} ==> _o underbar-accent
487 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
488 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
489 (insert "_" (texinfo-parse-arg-discard))
490 (goto-char texinfo-command-start))
492 ;; @udotaccent{o} ==> o-. underdot-accent
493 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
494 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
495 (insert (texinfo-parse-arg-discard) "-.")
496 (goto-char texinfo-command-start))
498 ;; @H{o} ==> ""o long Hungarian umlaut
499 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
500 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
501 (insert "\"\"" (texinfo-parse-arg-discard))
502 (goto-char texinfo-command-start))
504 ;; @ringaccent{o} ==> *o ring accent
505 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
506 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
507 (insert "*" (texinfo-parse-arg-discard))
508 (goto-char texinfo-command-start))
510 ;; @tieaccent{oo} ==> [oo tie after accent
511 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
512 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
513 (insert "[" (texinfo-parse-arg-discard))
514 (goto-char texinfo-command-start))
516 ;; @u{o} ==> (o breve accent
517 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
518 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
519 (insert "(" (texinfo-parse-arg-discard))
520 (goto-char texinfo-command-start))
522 ;; @v{o} ==> <o hacek accent
523 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
524 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
525 (insert "<" (texinfo-parse-arg-discard))
526 (goto-char texinfo-command-start))
528 ;; @dotless{i} ==> i dotless i and dotless j
529 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
530 (ptexinfmt-defun-if-void texinfo-format-dotless ()
531 (insert (texinfo-parse-arg-discard))
532 (goto-char texinfo-command-start))
535 (put '\. 'texinfo-format 'texinfo-format-\.)
536 (ptexinfmt-defun-if-void texinfo-format-\. ()
537 (texinfo-discard-command)
541 (put '\: 'texinfo-format 'texinfo-format-\:)
542 (ptexinfmt-defun-if-void texinfo-format-\: ()
543 (texinfo-discard-command))
546 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
547 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
548 (texinfo-discard-command))
551 (put '\/ 'texinfo-format 'texinfo-format-\/)
552 (ptexinfmt-defun-if-void texinfo-format-\/ ()
553 (texinfo-discard-command))
558 (put 'ref 'texinfo-format 'texinfo-format-xref)
560 (ptexinfmt-defun-if-broken texinfo-format-xref ()
561 (let ((args (texinfo-format-parse-args)))
562 (texinfo-discard-command)
564 (let ((fname (or (nth 1 args) (nth 2 args))))
565 (if (null (or fname (nth 3 args)))
566 (insert (nth 0 args) "::")
567 (insert (or fname (nth 0 args)) ": ")
569 (insert "(" (nth 3 args) ")"))
570 (unless (null (nth 0 args))
571 (insert (nth 0 args)))))))
573 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
574 (put 'uref 'texinfo-format 'texinfo-format-uref)
575 (ptexinfmt-defun-if-broken texinfo-format-uref ()
576 "Format URL and optional URL-TITLE.
577 Insert ` ... ' around URL if no URL-TITLE argument;
578 otherwise, insert URL-TITLE followed by URL in parentheses."
579 (let ((args (texinfo-format-parse-args)))
580 (texinfo-discard-command)
583 (insert (nth 1 args) " (" (nth 0 args) ")")
584 (insert "`" (nth 0 args) "'"))))
587 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
588 (ptexinfmt-defun-if-void texinfo-format-inforef ()
589 (let ((args (texinfo-format-parse-args)))
590 (texinfo-discard-command)
592 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
593 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
598 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
599 ;; - Info-tagify suport @anthor-*-refill.
600 ;; - info.el support Ref in Tag table.
601 (unless (get 'anchor 'texinfo-format)
602 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
606 ;;; New command definition
607 ;; @alias NEW=EXISTING
608 (put 'alias 'texinfo-format 'texinfo-alias)
609 (ptexinfmt-defun-if-void texinfo-alias ()
610 (let ((start (1- (point)))
612 (skip-chars-forward " ")
613 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
614 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
615 (error "Invalid alias command")
616 (setq texinfo-alias-list
619 (buffer-substring (match-beginning 1) (match-end 1))
620 (buffer-substring (match-beginning 2) (match-end 2)))
622 (texinfo-discard-command))))
626 ;; @exampleindent INDENT (makeinfo 4.0 or later)
628 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
629 ;; INDENT: asis, 0, n
631 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
632 ;; WORD: none, insert
637 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
638 (put 'image 'texinfo-format 'texinfo-format-image)
639 (ptexinfmt-defun-if-void texinfo-format-image ()
640 ;; I don't know makeinfo parse FILENAME.
641 (let ((args (texinfo-format-parse-args))
643 (when (null (nth 0 args))
644 (error "Invalid image command"))
645 (texinfo-discard-command)
646 ;; makeinfo uses FILENAME.txt
647 (setq filename (format "%s.txt" (nth 0 args)))
648 (message "Reading included file: %s" filename)
649 ;; verbatim for Info output
650 (goto-char (+ (point) (cadr (insert-file-contents filename))))
651 (message "Reading included file: %s...done" filename)))
655 ;;; @multitable ... @end multitable
656 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
657 "*Number of extra spaces between entries (columns) in @multitable.")
659 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
660 "*multitable-temporary-buffer*")
661 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
662 "texinfo-multitable-temp-")
664 ;; These commands are defined in texinfo.tex for printed output.
665 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
666 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
667 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
668 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
670 (put 'multitable 'texinfo-format 'texinfo-multitable)
672 (ptexinfmt-defun-if-void texinfo-multitable ()
673 "Produce multi-column tables."
675 ;; This function pushes information onto the `texinfo-stack'.
676 ;; A stack element consists of:
677 ;; - type-of-command, i.e., multitable
678 ;; - the information about column widths, and
679 ;; - the position of texinfo-command-start.
680 ;; e.g., ('multitable (1 2 3 4) 123)
681 ;; The command line is then deleted.
684 ;; push width information on stack
685 (texinfo-multitable-widths))
686 (texinfo-discard-line-with-args))
688 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
689 (ptexinfmt-defun-if-void texinfo-end-multitable ()
690 "Discard the @end multitable line and pop the stack of multitable."
691 (texinfo-discard-command)
692 (texinfo-pop-stack 'multitable))
694 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
695 "Return list of widths of each column in a multi-column table."
696 (let (texinfo-multitable-width-list)
698 ;; @multitable @columnfractions .25 .3 .45
701 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
702 ;; Place point before first argument
703 (skip-chars-forward " \t")
705 ;; Check for common misspelling
706 ((looking-at "@columnfraction ")
707 (error "In @multitable, @columnfractions misspelled"))
708 ;; Case 1: @columnfractions .25 .3 .45
709 ((looking-at "@columnfractions")
712 (setq texinfo-multitable-width-list
716 (* fill-column (read (get-buffer (current-buffer))))))
717 texinfo-multitable-width-list))))
719 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
721 (let ((start-of-templates (point)))
723 (skip-chars-forward " \t")
724 (let* ((start-of-template (1+ (point)))
726 ;; forward-sexp works with braces in Texinfo mode
727 (progn (forward-sexp 1) (1- (point)))))
728 (setq texinfo-multitable-width-list
730 (goto-char end-of-template)
733 (goto-char start-of-template)
735 texinfo-multitable-width-list))
736 ;; Remove carriage return from within a template, if any.
737 ;; This helps those those who want to use more than
738 ;; one line's worth of words in @multitable line.
739 (narrow-to-region start-of-template end-of-template)
740 (goto-char (point-min))
741 (while (search-forward "\n" nil t)
743 (goto-char (point-max))
750 You probably need to specify column widths for @multitable correctly")))
751 ;; Check whether columns fit on page.
752 (let ((desired-columns
754 ;; between column spaces
755 (length texinfo-multitable-width-list)
756 ;; additional between column spaces, if any
757 texinfo-extra-inter-column-width
758 ;; sum of spaces for each entry
759 (apply '+ texinfo-multitable-width-list))))
760 (if (> desired-columns fill-column)
762 Multi-column table width, %d chars, is greater than page width, %d chars."
763 desired-columns fill-column))))
764 texinfo-multitable-width-list))
766 ;; @item A1 @tab A2 @tab A3
767 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
768 "Return multitable row, as a string.
769 End of row is beginning of next @item or beginning of @end.
770 Cells within rows are separated by @tab."
771 (skip-chars-forward " \t")
772 (let* ((start (point))
774 (re-search-forward "@item\\|@end")
775 (match-beginning 0)))
776 (row (progn (goto-char end)
777 (skip-chars-backward " ")
778 ;; remove whitespace at end of argument
779 (delete-region (point) end)
780 (buffer-substring start (point)))))
781 (delete-region texinfo-command-start end)
784 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
785 (ptexinfmt-defun-if-void texinfo-multitable-item ()
786 "Format a row within a multicolumn table.
787 Cells in row are separated by @tab.
788 Widths of cells are specified by the arguments in the @multitable line.
789 All cells are made to be the same height.
790 This command is executed when texinfmt sees @item inside @multitable."
791 (let ((original-buffer (current-buffer))
792 (table-widths (reverse (car (cdr (car texinfo-stack)))))
793 (existing-fill-column fill-column)
797 (table-entry-height 0)
798 ;; unformatted row looks like: A1 @tab A2 @tab A3
799 ;; extract-row command deletes the source line in the table.
800 (unformated-row (texinfo-multitable-extract-row)))
801 ;; Use a temporary buffer
802 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
803 (delete-region (point-min) (point-max))
804 (insert unformated-row)
805 (goto-char (point-min))
806 ;; 1. Check for correct number of @tab in line.
807 (let ((tab-number 1)) ;; one @tab between two columns
808 (while (search-forward "@tab" nil t)
809 (setq tab-number (1+ tab-number)))
810 (if (/= tab-number (length table-widths))
811 (error "Wrong number of @tab's in a @multitable row")))
812 (goto-char (point-min))
813 ;; 2. Format each cell, and copy to a rectangle
814 ;; buffer looks like this: A1 @tab A2 @tab A3
815 ;; Cell #1: format up to @tab
816 ;; Cell #2: format up to @tab
817 ;; Cell #3: format up to eob
820 (setq end (save-excursion
821 (if (search-forward "@tab" nil 'move)
822 ;; Delete the @tab command, including the @-sign
825 (progn (forward-word -1) (1- (point)))))
827 ;; Set fill-column *wider* than needed to produce inter-column space
828 (setq fill-column (+ 1
829 texinfo-extra-inter-column-width
830 (nth table-column table-widths)))
831 (narrow-to-region start end)
832 ;; Remove whitespace before and after entry.
833 (skip-chars-forward " ")
834 (delete-region (point) (save-excursion (beginning-of-line) (point)))
835 (goto-char (point-max))
836 (skip-chars-backward " ")
837 (delete-region (point) (save-excursion (end-of-line) (point)))
838 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
839 ;; does not see an unterminated @multitable.
840 (let (texinfo-stack) ;; nil
841 (texinfo-format-scan))
842 (let (fill-prefix) ;; no fill prefix
843 (fill-region (point-min) (point-max)))
844 (setq table-entry-height
845 (max table-entry-height (count-lines (point-min) (point-max))))
846 ;; 3. Move point to end of bottom line, and pad that line to fill column.
847 (goto-char (point-min))
848 (forward-line (1- table-entry-height))
849 (let* ((beg (point)) ;; beginning of line
850 ;; add one more space for inter-column spacing
856 (current-column)))))) ;; end of existing line
858 (if (> needed-whitespace 0) needed-whitespace 1)
860 ;; now, put formatted cell into a rectangle
861 (set (intern (concat texinfo-multitable-rectangle-name
862 (int-to-string table-column)))
863 (extract-rectangle (point-min) (point)))
864 (delete-region (point-min) (point))
865 (goto-char (point-max))
866 (setq table-column (1+ table-column))
868 ;; 4. Add extra lines to rectangles so all are of same height
869 (let ((total-number-of-columns table-column)
872 (while (> table-column 0)
873 (let ((this-rectangle (int-to-string table-column)))
874 (while (< (length this-rectangle) table-entry-height)
875 (setq this-rectangle (append this-rectangle '("")))))
876 (setq table-column (1- table-column)))
877 ;; 5. Insert formatted rectangles in original buffer
878 (switch-to-buffer original-buffer)
879 (open-line table-entry-height)
880 (while (< column-number total-number-of-columns)
884 (concat texinfo-multitable-rectangle-name
885 (int-to-string column-number)))))
888 (setq column-number (1+ column-number))))
889 (kill-buffer texinfo-multitable-buffer-name)
890 (setq fill-column existing-fill-column)))
893 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
894 (let ((indexelts (symbol-value
895 (cdr (assoc (texinfo-parse-arg-discard)
896 texinfo-indexvar-alist))))
898 (insert "\n* Menu:\n\n")
899 (setq opoint (point))
900 (texinfo-print-index nil indexelts)
902 (if (memq system-type '(vax-vms windows-nt ms-dos))
903 (texinfo-sort-region opoint (point))
904 (shell-command-on-region opoint (point) "sort -fd" 1))))
908 ;;; ptexinfmt.el ends here