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)
267 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
268 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
269 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
270 (delete-region texinfo-command-start
271 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
274 ;; @html ... @end html (makeinfo 3.11 or later)
275 (put 'html 'texinfo-format 'texinfo-format-html)
276 (ptexinfmt-defun-if-void texinfo-format-html ()
277 (delete-region texinfo-command-start
278 (progn (re-search-forward "@end html[ \t]*\n")
281 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
282 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
283 (defun texinfo-format-ifhtml ()
284 (delete-region texinfo-command-start
285 (progn (re-search-forward "@end ifhtml[ \t]*\n")
288 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
289 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
290 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
291 (delete-region texinfo-command-start
292 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
298 ;; @url, @env, @command
299 (put 'url 'texinfo-format 'texinfo-format-code)
300 (put 'env 'texinfo-format 'texinfo-format-code)
301 (put 'command 'texinfo-format 'texinfo-format-code)
304 (put 'acronym 'texinfo-format 'texinfo-format-var)
306 (ptexinfmt-defun-if-broken texinfo-format-var ()
307 (let ((arg (texinfo-parse-expanded-arg)))
308 (texinfo-discard-command)
309 (insert (upcase arg))))
312 (put 'key 'texinfo-format 'texinfo-format-key)
313 (ptexinfmt-defun-if-void texinfo-format-key ()
314 (insert (texinfo-parse-arg-discard))
315 (goto-char texinfo-command-start))
317 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
318 (put 'email 'texinfo-format 'texinfo-format-email)
319 (ptexinfmt-defun-if-void texinfo-format-email ()
320 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
321 Insert < ... > around EMAIL-ADDRESS."
322 (let ((args (texinfo-format-parse-args)))
323 (texinfo-discard-command)
326 (insert (nth 1 args) " <" (nth 0 args) ">")
327 (insert "<" (nth 0 args) ">"))))
330 (put 'option 'texinfo-format 'texinfo-format-option)
331 (ptexinfmt-defun-if-void texinfo-format-option ()
332 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
333 ;; `looking-at-backward' not available in v. 18.57, 20.2
334 ;; searched-for character is a control-H
335 (if (not (search-backward "\010"
336 (save-excursion (beginning-of-line) (point))
338 (insert "`" (texinfo-parse-arg-discard) "'")
339 (insert (texinfo-parse-arg-discard)))
340 (goto-char texinfo-command-start))
342 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
343 (put 'verb 'texinfo-format 'texinfo-format-verb)
344 (ptexinfmt-defun-if-void texinfo-format-verb ()
345 "Format text between non-quoted unique delimiter characters verbatim.
346 Enclose the verbatim text, including the delimiters, in braces. Print
347 text exactly as written (but not the delimiters) in a fixed-width.
349 For example, @verb\{|@|\} results in @ and
350 @verb\{+@'e?`!`+} results in @'e?`!`."
352 (let ((delimiter (buffer-substring-no-properties
353 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
354 (unless (looking-at "{")
355 (error "Not found: @verb start brace"))
356 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
357 (search-forward delimiter))
358 (delete-backward-char 1)
359 (unless (looking-at "}")
360 (error "Not found: @verb end brace"))
364 ;;; Accents and Special characters
365 ;; @pounds{} ==> # Pounds Sterling
366 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
367 (ptexinfmt-defun-if-void texinfo-format-pounds ()
368 (texinfo-parse-arg-discard)
371 ;; @OE{} ==> OE French-OE-ligature
372 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
373 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
374 (insert "OE" (texinfo-parse-arg-discard))
375 (goto-char texinfo-command-start))
378 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
379 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
380 (insert "oe" (texinfo-parse-arg-discard))
381 (goto-char texinfo-command-start))
383 ;; @AA{} ==> AA Scandinavian-A-with-circle
384 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
385 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
386 (insert "AA" (texinfo-parse-arg-discard))
387 (goto-char texinfo-command-start))
390 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
391 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
392 (insert "aa" (texinfo-parse-arg-discard))
393 (goto-char texinfo-command-start))
395 ;; @AE{} ==> AE Latin-Scandinavian-AE
396 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
397 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
398 (insert "AE" (texinfo-parse-arg-discard))
399 (goto-char texinfo-command-start))
402 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
403 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
404 (insert "ae" (texinfo-parse-arg-discard))
405 (goto-char texinfo-command-start))
407 ;; @ss{} ==> ss German-sharp-S
408 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
409 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
410 (insert "ss" (texinfo-parse-arg-discard))
411 (goto-char texinfo-command-start))
413 ;; @questiondown{} ==> ? upside-down-question-mark
414 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
415 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
416 (insert "?" (texinfo-parse-arg-discard))
417 (goto-char texinfo-command-start))
419 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
420 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
421 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
422 (insert "!" (texinfo-parse-arg-discard))
423 (goto-char texinfo-command-start))
425 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
426 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
427 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
428 (insert (texinfo-parse-arg-discard) "/L")
429 (goto-char texinfo-command-start))
431 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
432 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
433 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
434 (insert (texinfo-parse-arg-discard) "/l")
435 (goto-char texinfo-command-start))
437 ;; @O{} ==> O/ Scandinavian O-with-slash
438 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
439 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
440 (insert (texinfo-parse-arg-discard) "O/")
441 (goto-char texinfo-command-start))
443 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
444 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
445 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
446 (insert (texinfo-parse-arg-discard) "o/")
447 (goto-char texinfo-command-start))
449 ;; @,{c} ==> c, cedilla accent
450 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
451 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
452 (insert (texinfo-parse-arg-discard) ",")
453 (goto-char texinfo-command-start))
456 ;; @dotaccent{o} ==> .o overdot-accent
457 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
458 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
459 (insert "." (texinfo-parse-arg-discard))
460 (goto-char texinfo-command-start))
462 ;; @ubaraccent{o} ==> _o underbar-accent
463 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
464 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
465 (insert "_" (texinfo-parse-arg-discard))
466 (goto-char texinfo-command-start))
468 ;; @udotaccent{o} ==> o-. underdot-accent
469 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
470 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
471 (insert (texinfo-parse-arg-discard) "-.")
472 (goto-char texinfo-command-start))
474 ;; @H{o} ==> ""o long Hungarian umlaut
475 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
476 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
477 (insert "\"\"" (texinfo-parse-arg-discard))
478 (goto-char texinfo-command-start))
480 ;; @ringaccent{o} ==> *o ring accent
481 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
482 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
483 (insert "*" (texinfo-parse-arg-discard))
484 (goto-char texinfo-command-start))
486 ;; @tieaccent{oo} ==> [oo tie after accent
487 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
488 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
489 (insert "[" (texinfo-parse-arg-discard))
490 (goto-char texinfo-command-start))
492 ;; @u{o} ==> (o breve accent
493 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
494 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
495 (insert "(" (texinfo-parse-arg-discard))
496 (goto-char texinfo-command-start))
498 ;; @v{o} ==> <o hacek accent
499 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
500 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
501 (insert "<" (texinfo-parse-arg-discard))
502 (goto-char texinfo-command-start))
504 ;; @dotless{i} ==> i dotless i and dotless j
505 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
506 (ptexinfmt-defun-if-void texinfo-format-dotless ()
507 (insert (texinfo-parse-arg-discard))
508 (goto-char texinfo-command-start))
511 (put '\. 'texinfo-format 'texinfo-format-\.)
512 (ptexinfmt-defun-if-void texinfo-format-\. ()
513 (texinfo-discard-command)
517 (put '\: 'texinfo-format 'texinfo-format-\:)
518 (ptexinfmt-defun-if-void texinfo-format-\: ()
519 (texinfo-discard-command))
522 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
523 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
524 (texinfo-discard-command))
527 (put '\/ 'texinfo-format 'texinfo-format-\/)
528 (ptexinfmt-defun-if-void texinfo-format-\/ ()
529 (texinfo-discard-command))
534 (put 'ref 'texinfo-format 'texinfo-format-xref)
536 (ptexinfmt-defun-if-broken texinfo-format-xref ()
537 (let ((args (texinfo-format-parse-args)))
538 (texinfo-discard-command)
540 (let ((fname (or (nth 1 args) (nth 2 args))))
541 (if (null (or fname (nth 3 args)))
542 (insert (nth 0 args) "::")
543 (insert (or fname (nth 0 args)) ": ")
545 (insert "(" (nth 3 args) ")"))
546 (unless (null (nth 0 args))
547 (insert (nth 0 args)))))))
549 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
550 (put 'uref 'texinfo-format 'texinfo-format-uref)
551 (ptexinfmt-defun-if-broken texinfo-format-uref ()
552 "Format URL and optional URL-TITLE.
553 Insert ` ... ' around URL if no URL-TITLE argument;
554 otherwise, insert URL-TITLE followed by URL in parentheses."
555 (let ((args (texinfo-format-parse-args)))
556 (texinfo-discard-command)
559 (insert (nth 1 args) " (" (nth 0 args) ")")
560 (insert "`" (nth 0 args) "'"))))
563 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
564 (ptexinfmt-defun-if-void texinfo-format-inforef ()
565 (let ((args (texinfo-format-parse-args)))
566 (texinfo-discard-command)
568 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
569 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
574 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
575 ;; - Info-tagify suport @anthor-*-refill.
576 ;; - info.el support Ref in Tag table.
577 (unless (get 'anchor 'texinfo-format)
578 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
582 ;;; New command definition
583 ;; @alias NEW=EXISTING
584 (put 'alias 'texinfo-format 'texinfo-alias)
585 (ptexinfmt-defun-if-void texinfo-alias ()
586 (let ((start (1- (point)))
588 (skip-chars-forward " ")
589 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
590 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
591 (error "Invalid alias command")
592 (setq texinfo-alias-list
595 (buffer-substring (match-beginning 1) (match-end 1))
596 (buffer-substring (match-beginning 2) (match-end 2)))
598 (texinfo-discard-command))))
602 ;; @exampleindent INDENT (makeinfo 4.0 or later)
604 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
605 ;; INDENT: asis, 0, n
607 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
608 ;; WORD: none, insert
613 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
614 (put 'image 'texinfo-format 'texinfo-format-image)
615 (ptexinfmt-defun-if-void texinfo-format-image ()
616 ;; I don't know makeinfo parse FILENAME.
617 (let ((args (texinfo-format-parse-args))
619 (when (null (nth 0 args))
620 (error "Invalid image command"))
621 (texinfo-discard-command)
622 ;; makeinfo uses FILENAME.txt
623 (setq filename (format "%s.txt" (nth 0 args)))
624 (message "Reading included file: %s" filename)
625 ;; verbatim for Info output
626 (goto-char (+ (point) (cadr (insert-file-contents filename))))
627 (message "Reading included file: %s...done" filename)))
629 ;; @hyphenation command discards an argument within braces
630 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
631 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
632 "Discard both @-command and its argument in braces."
633 (goto-char texinfo-command-end)
635 (setq texinfo-command-end (point))
636 (delete-region texinfo-command-start texinfo-command-end))
639 ;;; @multitable ... @end multitable
640 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
641 "*Number of extra spaces between entries (columns) in @multitable.")
643 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
644 "*multitable-temporary-buffer*")
645 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
646 "texinfo-multitable-temp-")
648 ;; These commands are defined in texinfo.tex for printed output.
649 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
650 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
651 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
652 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
654 (put 'multitable 'texinfo-format 'texinfo-multitable)
656 (ptexinfmt-defun-if-void texinfo-multitable ()
657 "Produce multi-column tables."
659 ;; This function pushes information onto the `texinfo-stack'.
660 ;; A stack element consists of:
661 ;; - type-of-command, i.e., multitable
662 ;; - the information about column widths, and
663 ;; - the position of texinfo-command-start.
664 ;; e.g., ('multitable (1 2 3 4) 123)
665 ;; The command line is then deleted.
668 ;; push width information on stack
669 (texinfo-multitable-widths))
670 (texinfo-discard-line-with-args))
672 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
673 (ptexinfmt-defun-if-void texinfo-end-multitable ()
674 "Discard the @end multitable line and pop the stack of multitable."
675 (texinfo-discard-command)
676 (texinfo-pop-stack 'multitable))
678 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
679 "Return list of widths of each column in a multi-column table."
680 (let (texinfo-multitable-width-list)
682 ;; @multitable @columnfractions .25 .3 .45
685 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
686 ;; Place point before first argument
687 (skip-chars-forward " \t")
689 ;; Check for common misspelling
690 ((looking-at "@columnfraction ")
691 (error "In @multitable, @columnfractions misspelled"))
692 ;; Case 1: @columnfractions .25 .3 .45
693 ((looking-at "@columnfractions")
696 (setq texinfo-multitable-width-list
700 (* fill-column (read (get-buffer (current-buffer))))))
701 texinfo-multitable-width-list))))
703 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
705 (let ((start-of-templates (point)))
707 (skip-chars-forward " \t")
708 (let* ((start-of-template (1+ (point)))
710 ;; forward-sexp works with braces in Texinfo mode
711 (progn (forward-sexp 1) (1- (point)))))
712 (setq texinfo-multitable-width-list
714 (goto-char end-of-template)
717 (goto-char start-of-template)
719 texinfo-multitable-width-list))
720 ;; Remove carriage return from within a template, if any.
721 ;; This helps those those who want to use more than
722 ;; one line's worth of words in @multitable line.
723 (narrow-to-region start-of-template end-of-template)
724 (goto-char (point-min))
725 (while (search-forward "\n" nil t)
727 (goto-char (point-max))
734 You probably need to specify column widths for @multitable correctly")))
735 ;; Check whether columns fit on page.
736 (let ((desired-columns
738 ;; between column spaces
739 (length texinfo-multitable-width-list)
740 ;; additional between column spaces, if any
741 texinfo-extra-inter-column-width
742 ;; sum of spaces for each entry
743 (apply '+ texinfo-multitable-width-list))))
744 (if (> desired-columns fill-column)
746 Multi-column table width, %d chars, is greater than page width, %d chars."
747 desired-columns fill-column))))
748 texinfo-multitable-width-list))
750 ;; @item A1 @tab A2 @tab A3
751 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
752 "Return multitable row, as a string.
753 End of row is beginning of next @item or beginning of @end.
754 Cells within rows are separated by @tab."
755 (skip-chars-forward " \t")
756 (let* ((start (point))
758 (re-search-forward "@item\\|@end")
759 (match-beginning 0)))
760 (row (progn (goto-char end)
761 (skip-chars-backward " ")
762 ;; remove whitespace at end of argument
763 (delete-region (point) end)
764 (buffer-substring start (point)))))
765 (delete-region texinfo-command-start end)
768 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
769 (ptexinfmt-defun-if-void texinfo-multitable-item ()
770 "Format a row within a multicolumn table.
771 Cells in row are separated by @tab.
772 Widths of cells are specified by the arguments in the @multitable line.
773 All cells are made to be the same height.
774 This command is executed when texinfmt sees @item inside @multitable."
775 (let ((original-buffer (current-buffer))
776 (table-widths (reverse (car (cdr (car texinfo-stack)))))
777 (existing-fill-column fill-column)
781 (table-entry-height 0)
782 ;; unformatted row looks like: A1 @tab A2 @tab A3
783 ;; extract-row command deletes the source line in the table.
784 (unformated-row (texinfo-multitable-extract-row)))
785 ;; Use a temporary buffer
786 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
787 (delete-region (point-min) (point-max))
788 (insert unformated-row)
789 (goto-char (point-min))
790 ;; 1. Check for correct number of @tab in line.
791 (let ((tab-number 1)) ;; one @tab between two columns
792 (while (search-forward "@tab" nil t)
793 (setq tab-number (1+ tab-number)))
794 (if (/= tab-number (length table-widths))
795 (error "Wrong number of @tab's in a @multitable row")))
796 (goto-char (point-min))
797 ;; 2. Format each cell, and copy to a rectangle
798 ;; buffer looks like this: A1 @tab A2 @tab A3
799 ;; Cell #1: format up to @tab
800 ;; Cell #2: format up to @tab
801 ;; Cell #3: format up to eob
804 (setq end (save-excursion
805 (if (search-forward "@tab" nil 'move)
806 ;; Delete the @tab command, including the @-sign
809 (progn (forward-word -1) (1- (point)))))
811 ;; Set fill-column *wider* than needed to produce inter-column space
812 (setq fill-column (+ 1
813 texinfo-extra-inter-column-width
814 (nth table-column table-widths)))
815 (narrow-to-region start end)
816 ;; Remove whitespace before and after entry.
817 (skip-chars-forward " ")
818 (delete-region (point) (save-excursion (beginning-of-line) (point)))
819 (goto-char (point-max))
820 (skip-chars-backward " ")
821 (delete-region (point) (save-excursion (end-of-line) (point)))
822 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
823 ;; does not see an unterminated @multitable.
824 (let (texinfo-stack) ;; nil
825 (texinfo-format-scan))
826 (let (fill-prefix) ;; no fill prefix
827 (fill-region (point-min) (point-max)))
828 (setq table-entry-height
829 (max table-entry-height (count-lines (point-min) (point-max))))
830 ;; 3. Move point to end of bottom line, and pad that line to fill column.
831 (goto-char (point-min))
832 (forward-line (1- table-entry-height))
833 (let* ((beg (point)) ;; beginning of line
834 ;; add one more space for inter-column spacing
840 (current-column)))))) ;; end of existing line
842 (if (> needed-whitespace 0) needed-whitespace 1)
844 ;; now, put formatted cell into a rectangle
845 (set (intern (concat texinfo-multitable-rectangle-name
846 (int-to-string table-column)))
847 (extract-rectangle (point-min) (point)))
848 (delete-region (point-min) (point))
849 (goto-char (point-max))
850 (setq table-column (1+ table-column))
852 ;; 4. Add extra lines to rectangles so all are of same height
853 (let ((total-number-of-columns table-column)
856 (while (> table-column 0)
857 (let ((this-rectangle (int-to-string table-column)))
858 (while (< (length this-rectangle) table-entry-height)
859 (setq this-rectangle (append this-rectangle '("")))))
860 (setq table-column (1- table-column)))
861 ;; 5. Insert formatted rectangles in original buffer
862 (switch-to-buffer original-buffer)
863 (open-line table-entry-height)
864 (while (< column-number total-number-of-columns)
868 (concat texinfo-multitable-rectangle-name
869 (int-to-string column-number)))))
872 (setq column-number (1+ column-number))))
873 (kill-buffer texinfo-multitable-buffer-name)
874 (setq fill-column existing-fill-column)))
877 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
878 (let ((indexelts (symbol-value
879 (cdr (assoc (texinfo-parse-arg-discard)
880 texinfo-indexvar-alist))))
882 (insert "\n* Menu:\n\n")
883 (setq opoint (point))
884 (texinfo-print-index nil indexelts)
886 (if (memq system-type '(vax-vms windows-nt ms-dos))
887 (texinfo-sort-region opoint (point))
888 (shell-command-on-region opoint (point) "sort -fd" 1))))
892 ;;; ptexinfmt.el ends here