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 ;; @indicateurl, @url, @env, @command,
317 (put 'env 'texinfo-format 'texinfo-format-code)
318 (put 'command 'texinfo-format 'texinfo-format-code)
320 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
321 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
324 (put 'acronym 'texinfo-format 'texinfo-format-var)
326 (ptexinfmt-defun-if-broken texinfo-format-var ()
327 (let ((arg (texinfo-parse-expanded-arg)))
328 (texinfo-discard-command)
329 (insert (upcase arg))))
332 (put 'key 'texinfo-format 'texinfo-format-key)
333 (ptexinfmt-defun-if-void texinfo-format-key ()
334 (insert (texinfo-parse-arg-discard))
335 (goto-char texinfo-command-start))
337 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
338 (put 'email 'texinfo-format 'texinfo-format-email)
339 (ptexinfmt-defun-if-void texinfo-format-email ()
340 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
341 Insert < ... > around EMAIL-ADDRESS."
342 (let ((args (texinfo-format-parse-args)))
343 (texinfo-discard-command)
346 (insert (nth 1 args) " <" (nth 0 args) ">")
347 (insert "<" (nth 0 args) ">"))))
350 (put 'option 'texinfo-format 'texinfo-format-option)
351 (ptexinfmt-defun-if-void texinfo-format-option ()
352 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
353 ;; `looking-at-backward' not available in v. 18.57, 20.2
354 ;; searched-for character is a control-H
355 (if (not (search-backward "\010"
356 (save-excursion (beginning-of-line) (point))
358 (insert "`" (texinfo-parse-arg-discard) "'")
359 (insert (texinfo-parse-arg-discard)))
360 (goto-char texinfo-command-start))
362 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
363 (put 'verb 'texinfo-format 'texinfo-format-verb)
364 (ptexinfmt-defun-if-void texinfo-format-verb ()
365 "Format text between non-quoted unique delimiter characters verbatim.
366 Enclose the verbatim text, including the delimiters, in braces. Print
367 text exactly as written (but not the delimiters) in a fixed-width.
369 For example, @verb\{|@|\} results in @ and
370 @verb\{+@'e?`!`+} results in @'e?`!`."
372 (let ((delimiter (buffer-substring-no-properties
373 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
374 (unless (looking-at "{")
375 (error "Not found: @verb start brace"))
376 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
377 (search-forward delimiter))
378 (delete-backward-char 1)
379 (unless (looking-at "}")
380 (error "Not found: @verb end brace"))
384 ;;; @LaTeX, @registeredsymbol{}
385 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
386 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
387 (texinfo-parse-arg-discard)
390 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
391 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
392 (texinfo-parse-arg-discard)
395 ;;; Accents and Special characters
396 ;; @pounds{} ==> # Pounds Sterling
397 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
398 (ptexinfmt-defun-if-void texinfo-format-pounds ()
399 (texinfo-parse-arg-discard)
402 ;; @OE{} ==> OE French-OE-ligature
403 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
404 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
405 (insert "OE" (texinfo-parse-arg-discard))
406 (goto-char texinfo-command-start))
409 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
410 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
411 (insert "oe" (texinfo-parse-arg-discard))
412 (goto-char texinfo-command-start))
414 ;; @AA{} ==> AA Scandinavian-A-with-circle
415 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
416 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
417 (insert "AA" (texinfo-parse-arg-discard))
418 (goto-char texinfo-command-start))
421 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
422 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
423 (insert "aa" (texinfo-parse-arg-discard))
424 (goto-char texinfo-command-start))
426 ;; @AE{} ==> AE Latin-Scandinavian-AE
427 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
428 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
429 (insert "AE" (texinfo-parse-arg-discard))
430 (goto-char texinfo-command-start))
433 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
434 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
435 (insert "ae" (texinfo-parse-arg-discard))
436 (goto-char texinfo-command-start))
438 ;; @ss{} ==> ss German-sharp-S
439 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
440 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
441 (insert "ss" (texinfo-parse-arg-discard))
442 (goto-char texinfo-command-start))
444 ;; @questiondown{} ==> ? upside-down-question-mark
445 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
446 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
447 (insert "?" (texinfo-parse-arg-discard))
448 (goto-char texinfo-command-start))
450 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
451 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
452 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
453 (insert "!" (texinfo-parse-arg-discard))
454 (goto-char texinfo-command-start))
456 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
457 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
458 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
459 (insert (texinfo-parse-arg-discard) "/L")
460 (goto-char texinfo-command-start))
462 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
463 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
464 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
465 (insert (texinfo-parse-arg-discard) "/l")
466 (goto-char texinfo-command-start))
468 ;; @O{} ==> O/ Scandinavian O-with-slash
469 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
470 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
471 (insert (texinfo-parse-arg-discard) "O/")
472 (goto-char texinfo-command-start))
474 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
475 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
476 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
477 (insert (texinfo-parse-arg-discard) "o/")
478 (goto-char texinfo-command-start))
480 ;; @,{c} ==> c, cedilla accent
481 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
482 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
483 (insert (texinfo-parse-arg-discard) ",")
484 (goto-char texinfo-command-start))
487 ;; @dotaccent{o} ==> .o overdot-accent
488 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
489 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
490 (insert "." (texinfo-parse-arg-discard))
491 (goto-char texinfo-command-start))
493 ;; @ubaraccent{o} ==> _o underbar-accent
494 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
495 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
496 (insert "_" (texinfo-parse-arg-discard))
497 (goto-char texinfo-command-start))
499 ;; @udotaccent{o} ==> o-. underdot-accent
500 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
501 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
502 (insert (texinfo-parse-arg-discard) "-.")
503 (goto-char texinfo-command-start))
505 ;; @H{o} ==> ""o long Hungarian umlaut
506 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
507 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
508 (insert "\"\"" (texinfo-parse-arg-discard))
509 (goto-char texinfo-command-start))
511 ;; @ringaccent{o} ==> *o ring accent
512 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
513 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
514 (insert "*" (texinfo-parse-arg-discard))
515 (goto-char texinfo-command-start))
517 ;; @tieaccent{oo} ==> [oo tie after accent
518 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
519 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
520 (insert "[" (texinfo-parse-arg-discard))
521 (goto-char texinfo-command-start))
523 ;; @u{o} ==> (o breve accent
524 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
525 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
526 (insert "(" (texinfo-parse-arg-discard))
527 (goto-char texinfo-command-start))
529 ;; @v{o} ==> <o hacek accent
530 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
531 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
532 (insert "<" (texinfo-parse-arg-discard))
533 (goto-char texinfo-command-start))
535 ;; @dotless{i} ==> i dotless i and dotless j
536 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
537 (ptexinfmt-defun-if-void texinfo-format-dotless ()
538 (insert (texinfo-parse-arg-discard))
539 (goto-char texinfo-command-start))
542 (put '\. 'texinfo-format 'texinfo-format-\.)
543 (ptexinfmt-defun-if-void texinfo-format-\. ()
544 (texinfo-discard-command)
548 (put '\: 'texinfo-format 'texinfo-format-\:)
549 (ptexinfmt-defun-if-void texinfo-format-\: ()
550 (texinfo-discard-command))
553 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
554 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
555 (texinfo-discard-command))
558 (put '\/ 'texinfo-format 'texinfo-format-\/)
559 (ptexinfmt-defun-if-void texinfo-format-\/ ()
560 (texinfo-discard-command))
565 (put 'ref 'texinfo-format 'texinfo-format-xref)
567 (ptexinfmt-defun-if-broken texinfo-format-xref ()
568 (let ((args (texinfo-format-parse-args)))
569 (texinfo-discard-command)
571 (let ((fname (or (nth 1 args) (nth 2 args))))
572 (if (null (or fname (nth 3 args)))
573 (insert (nth 0 args) "::")
574 (insert (or fname (nth 0 args)) ": ")
576 (insert "(" (nth 3 args) ")"))
577 (unless (null (nth 0 args))
578 (insert (nth 0 args)))))))
580 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
581 (put 'uref 'texinfo-format 'texinfo-format-uref)
582 (ptexinfmt-defun-if-broken texinfo-format-uref ()
583 "Format URL and optional URL-TITLE.
584 Insert ` ... ' around URL if no URL-TITLE argument;
585 otherwise, insert URL-TITLE followed by URL in parentheses."
586 (let ((args (texinfo-format-parse-args)))
587 (texinfo-discard-command)
590 (insert (nth 1 args) " (" (nth 0 args) ")")
591 (insert "`" (nth 0 args) "'"))))
594 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
595 (ptexinfmt-defun-if-void texinfo-format-inforef ()
596 (let ((args (texinfo-format-parse-args)))
597 (texinfo-discard-command)
599 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
600 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
605 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
606 ;; - Info-tagify suport @anthor-*-refill.
607 ;; - info.el support Ref in Tag table.
608 (unless (get 'anchor 'texinfo-format)
609 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
613 ;;; New command definition
614 ;; @alias NEW=EXISTING
615 (put 'alias 'texinfo-format 'texinfo-alias)
616 (ptexinfmt-defun-if-void texinfo-alias ()
617 (let ((start (1- (point)))
619 (skip-chars-forward " ")
620 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
621 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
622 (error "Invalid alias command")
623 (setq texinfo-alias-list
626 (buffer-substring (match-beginning 1) (match-end 1))
627 (buffer-substring (match-beginning 2) (match-end 2)))
629 (texinfo-discard-command))))
633 ;; @exampleindent INDENT (makeinfo 4.0 or later)
635 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
636 ;; INDENT: asis, 0, n
638 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
639 ;; WORD: none, insert
644 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
645 (put 'image 'texinfo-format 'texinfo-format-image)
646 (ptexinfmt-defun-if-void texinfo-format-image ()
647 ;; I don't know makeinfo parse FILENAME.
648 (let ((args (texinfo-format-parse-args))
650 (when (null (nth 0 args))
651 (error "Invalid image command"))
652 (texinfo-discard-command)
653 ;; makeinfo uses FILENAME.txt
654 (setq filename (format "%s.txt" (nth 0 args)))
655 (message "Reading included file: %s" filename)
656 ;; verbatim for Info output
657 (goto-char (+ (point) (cadr (insert-file-contents filename))))
658 (message "Reading included file: %s...done" filename)))
662 ;;; @multitable ... @end multitable
663 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
664 "*Number of extra spaces between entries (columns) in @multitable.")
666 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
667 "*multitable-temporary-buffer*")
668 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
669 "texinfo-multitable-temp-")
671 ;; These commands are defined in texinfo.tex for printed output.
672 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
673 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
674 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
675 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
677 (put 'multitable 'texinfo-format 'texinfo-multitable)
679 (ptexinfmt-defun-if-void texinfo-multitable ()
680 "Produce multi-column tables."
682 ;; This function pushes information onto the `texinfo-stack'.
683 ;; A stack element consists of:
684 ;; - type-of-command, i.e., multitable
685 ;; - the information about column widths, and
686 ;; - the position of texinfo-command-start.
687 ;; e.g., ('multitable (1 2 3 4) 123)
688 ;; The command line is then deleted.
691 ;; push width information on stack
692 (texinfo-multitable-widths))
693 (texinfo-discard-line-with-args))
695 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
696 (ptexinfmt-defun-if-void texinfo-end-multitable ()
697 "Discard the @end multitable line and pop the stack of multitable."
698 (texinfo-discard-command)
699 (texinfo-pop-stack 'multitable))
701 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
702 "Return list of widths of each column in a multi-column table."
703 (let (texinfo-multitable-width-list)
705 ;; @multitable @columnfractions .25 .3 .45
708 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
709 ;; Place point before first argument
710 (skip-chars-forward " \t")
712 ;; Check for common misspelling
713 ((looking-at "@columnfraction ")
714 (error "In @multitable, @columnfractions misspelled"))
715 ;; Case 1: @columnfractions .25 .3 .45
716 ((looking-at "@columnfractions")
719 (setq texinfo-multitable-width-list
723 (* fill-column (read (get-buffer (current-buffer))))))
724 texinfo-multitable-width-list))))
726 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
728 (let ((start-of-templates (point)))
730 (skip-chars-forward " \t")
731 (let* ((start-of-template (1+ (point)))
733 ;; forward-sexp works with braces in Texinfo mode
734 (progn (forward-sexp 1) (1- (point)))))
735 (setq texinfo-multitable-width-list
737 (goto-char end-of-template)
740 (goto-char start-of-template)
742 texinfo-multitable-width-list))
743 ;; Remove carriage return from within a template, if any.
744 ;; This helps those those who want to use more than
745 ;; one line's worth of words in @multitable line.
746 (narrow-to-region start-of-template end-of-template)
747 (goto-char (point-min))
748 (while (search-forward "\n" nil t)
750 (goto-char (point-max))
757 You probably need to specify column widths for @multitable correctly")))
758 ;; Check whether columns fit on page.
759 (let ((desired-columns
761 ;; between column spaces
762 (length texinfo-multitable-width-list)
763 ;; additional between column spaces, if any
764 texinfo-extra-inter-column-width
765 ;; sum of spaces for each entry
766 (apply '+ texinfo-multitable-width-list))))
767 (if (> desired-columns fill-column)
769 Multi-column table width, %d chars, is greater than page width, %d chars."
770 desired-columns fill-column))))
771 texinfo-multitable-width-list))
773 ;; @item A1 @tab A2 @tab A3
774 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
775 "Return multitable row, as a string.
776 End of row is beginning of next @item or beginning of @end.
777 Cells within rows are separated by @tab."
778 (skip-chars-forward " \t")
779 (let* ((start (point))
781 (re-search-forward "@item\\|@end")
782 (match-beginning 0)))
783 (row (progn (goto-char end)
784 (skip-chars-backward " ")
785 ;; remove whitespace at end of argument
786 (delete-region (point) end)
787 (buffer-substring start (point)))))
788 (delete-region texinfo-command-start end)
791 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
792 (ptexinfmt-defun-if-void texinfo-multitable-item ()
793 "Format a row within a multicolumn table.
794 Cells in row are separated by @tab.
795 Widths of cells are specified by the arguments in the @multitable line.
796 All cells are made to be the same height.
797 This command is executed when texinfmt sees @item inside @multitable."
798 (let ((original-buffer (current-buffer))
799 (table-widths (reverse (car (cdr (car texinfo-stack)))))
800 (existing-fill-column fill-column)
804 (table-entry-height 0)
805 ;; unformatted row looks like: A1 @tab A2 @tab A3
806 ;; extract-row command deletes the source line in the table.
807 (unformated-row (texinfo-multitable-extract-row)))
808 ;; Use a temporary buffer
809 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
810 (delete-region (point-min) (point-max))
811 (insert unformated-row)
812 (goto-char (point-min))
813 ;; 1. Check for correct number of @tab in line.
814 (let ((tab-number 1)) ;; one @tab between two columns
815 (while (search-forward "@tab" nil t)
816 (setq tab-number (1+ tab-number)))
817 (if (/= tab-number (length table-widths))
818 (error "Wrong number of @tab's in a @multitable row")))
819 (goto-char (point-min))
820 ;; 2. Format each cell, and copy to a rectangle
821 ;; buffer looks like this: A1 @tab A2 @tab A3
822 ;; Cell #1: format up to @tab
823 ;; Cell #2: format up to @tab
824 ;; Cell #3: format up to eob
827 (setq end (save-excursion
828 (if (search-forward "@tab" nil 'move)
829 ;; Delete the @tab command, including the @-sign
832 (progn (forward-word -1) (1- (point)))))
834 ;; Set fill-column *wider* than needed to produce inter-column space
835 (setq fill-column (+ 1
836 texinfo-extra-inter-column-width
837 (nth table-column table-widths)))
838 (narrow-to-region start end)
839 ;; Remove whitespace before and after entry.
840 (skip-chars-forward " ")
841 (delete-region (point) (save-excursion (beginning-of-line) (point)))
842 (goto-char (point-max))
843 (skip-chars-backward " ")
844 (delete-region (point) (save-excursion (end-of-line) (point)))
845 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
846 ;; does not see an unterminated @multitable.
847 (let (texinfo-stack) ;; nil
848 (texinfo-format-scan))
849 (let (fill-prefix) ;; no fill prefix
850 (fill-region (point-min) (point-max)))
851 (setq table-entry-height
852 (max table-entry-height (count-lines (point-min) (point-max))))
853 ;; 3. Move point to end of bottom line, and pad that line to fill column.
854 (goto-char (point-min))
855 (forward-line (1- table-entry-height))
856 (let* ((beg (point)) ;; beginning of line
857 ;; add one more space for inter-column spacing
863 (current-column)))))) ;; end of existing line
865 (if (> needed-whitespace 0) needed-whitespace 1)
867 ;; now, put formatted cell into a rectangle
868 (set (intern (concat texinfo-multitable-rectangle-name
869 (int-to-string table-column)))
870 (extract-rectangle (point-min) (point)))
871 (delete-region (point-min) (point))
872 (goto-char (point-max))
873 (setq table-column (1+ table-column))
875 ;; 4. Add extra lines to rectangles so all are of same height
876 (let ((total-number-of-columns table-column)
879 (while (> table-column 0)
880 (let ((this-rectangle (int-to-string table-column)))
881 (while (< (length this-rectangle) table-entry-height)
882 (setq this-rectangle (append this-rectangle '("")))))
883 (setq table-column (1- table-column)))
884 ;; 5. Insert formatted rectangles in original buffer
885 (switch-to-buffer original-buffer)
886 (open-line table-entry-height)
887 (while (< column-number total-number-of-columns)
891 (concat texinfo-multitable-rectangle-name
892 (int-to-string column-number)))))
895 (setq column-number (1+ column-number))))
896 (kill-buffer texinfo-multitable-buffer-name)
897 (setq fill-column existing-fill-column)))
900 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
901 (let ((indexelts (symbol-value
902 (cdr (assoc (texinfo-parse-arg-discard)
903 texinfo-indexvar-alist))))
905 (insert "\n* Menu:\n\n")
906 (setq opoint (point))
907 (texinfo-print-index nil indexelts)
909 (if (memq system-type '(vax-vms windows-nt ms-dos))
910 (texinfo-sort-region opoint (point))
911 (shell-command-on-region opoint (point) "sort -fd" 1))))
915 ;;; ptexinfmt.el ends here