1 ;;; ptexinfmt.el --- portable Texinfo formatter -*- lexical-binding: t -*-
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 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., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
39 ;; Unimplemented command:
40 ;; @abbr{ABBREVIATION}
41 ;; @float ... @end float, @caption{TEXT}, @shortcaption{TEXT}, @listoffloats
44 ;; @quotation (optional arguments)
45 ;; @acronym{ACRONYM[, MEANING]} (optional argument)
46 ;; @dofirstparagraphindent
48 ;; @verbatiminclude FILENAME
50 ;; @definfoenclose phoo,//,\\
51 ;; @deftypeivar CLASS DATA-TYPE VARIABLE-NAME
52 ;; @deftypeop CATEGORY CLASS DATA-TYPE NAME ARGUMENTS...
53 ;; @allowcodebreaks false
55 ;; @quotedblleft @quotedblright
56 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
57 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
58 ;; @clicksequence, @click, @clickstyle, @arrow
64 ;; Work around a problem that double-quotes at bol disappear:
65 ;; @dfn{FOO} => FOO", ``BAR'' => BAR", \BAZ/ => BAZ/
66 (modify-syntax-entry ?\" "w" texinfo-format-syntax-table)
67 (modify-syntax-entry ?\\ "w" texinfo-format-syntax-table)
70 (defvar ptexinfmt-disable-broken-notice-flag t
71 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
72 This is last argument in `ptexinfmt-broken-facility'.")
74 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
75 (defmacro ptexinfmt-broken-facility (facility docstring assertion
77 "Declare a symbol FACILITY is broken if ASSERTION is nil.
78 DOCSTRING will be printed if ASSERTION is nil and
79 `ptexinfmt-disable-broken-notice-flag' is nil."
80 `(let ((facility ',facility)
81 (docstring ,docstring)
82 (assertion (eval ',assertion)))
83 (put facility 'broken (not assertion))
86 (put facility 'broken-docstring docstring)
87 (if ptexinfmt-disable-broken-notice-flag
89 (message "BROKEN FACILITY DETECTED: %s" docstring)))))
91 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
92 (defmacro ptexinfmt-defun-if-broken (&rest args)
93 "Redefine a function just like `defun' if it is considered broken."
94 (let ((name (list 'quote (car args))))
95 (setq args (cdr args))
98 (if (get ,name 'broken)
100 (function (lambda ,@args)))))))
102 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
103 (defmacro ptexinfmt-defun-if-void (&rest args)
104 "Define a function just like `defun' unless it is already defined."
105 (let ((name (list 'quote (car args))))
106 (setq args (cdr args))
112 (function (lambda ,@args)))))))
114 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
115 (defmacro ptexinfmt-defvar-if-void (&rest args)
116 "Define a variable just like `defvar' unless it is already defined."
117 (let ((name (car args)))
118 (setq args (cdr args))
123 (defvar ,name ,@args)))))
126 (ptexinfmt-broken-facility texinfo-format-printindex
127 "Can't sort on Mule for Windows."
128 (if (and (memq system-type '(windows-nt ms-dos))
129 ;;; I don't know version threshold.
130 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
131 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
135 ;; @var{METASYNTACTIC-VARIABLE}
136 (defvar texinfo-enclosure-list)
137 (defvar texinfo-alias-list)
138 (ptexinfmt-broken-facility texinfo-format-var
139 "Don't perse @var argument."
142 (let (texinfo-enclosure-list texinfo-alias-list)
144 (insert "@var{@asis{foo}}\n")
145 (texinfo-format-expand-region (point-min) (point-max))
149 ;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
150 ;; INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
151 (ptexinfmt-broken-facility texinfo-format-xref
152 "Can't format @xref, 1st argument is empty."
155 (let (texinfo-enclosure-list texinfo-alias-list)
157 (insert "@xref{, xref, , file}\n")
158 (texinfo-format-expand-region (point-min) (point-max))
162 ;; @uref{URL[, TEXT][, REPLACEMENT]}
163 (ptexinfmt-broken-facility texinfo-format-uref
164 "Parse twice @uref argument."
167 (let (texinfo-enclosure-list texinfo-alias-list)
169 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
170 (texinfo-format-expand-region (point-min) (point-max))
175 (ptexinfmt-broken-facility texinfo-multitable-widths
176 "`texinfo-multitable-widths' unsupport wide-char."
177 (if (fboundp 'texinfo-multitable-widths)
179 (let ((str (string (make-char 'japanese-jisx0208 73 125)
180 (make-char 'japanese-jisx0208 57 45)
181 (make-char 'japanese-jisx0208 74 56)
182 (make-char 'japanese-jisx0208 59 122))))
184 (insert (format " {%s}\n" str))
185 (goto-char (point-min))
186 (if (= (car (texinfo-multitable-widths)) (length str))
189 ;; function definition is void
192 (ptexinfmt-broken-facility texinfo-multitable-item
193 "`texinfo-multitable-item' unsupport wide-char."
194 (not (get 'texinfo-multitable-widths 'broken)))
197 ;;; Hardcopy and HTML (discard)
199 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
205 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
206 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
207 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
208 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
209 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
210 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
218 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
219 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
220 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
221 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
224 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
225 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
226 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
227 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
228 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
229 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
230 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
233 (put 'page 'texinfo-format 'texinfo-discard-line)
234 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
236 ;; @slanted{TEXT} (makeinfo 4.8 or later)
237 (put 'slanted 'texinfo-format 'texinfo-format-noop)
239 ;; @sansserif{TEXT} (makeinfo 4.8 or later)
240 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
242 ;; @tie{} (makeinfo 4.3 or later)
243 (put 'tie 'texinfo-format 'texinfo-format-tie)
244 (ptexinfmt-defun-if-void texinfo-format-tie ()
245 (texinfo-parse-arg-discard)
250 ;; @direcategory DIRPART
251 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
252 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
253 (let ((str (texinfo-parse-arg-discard)))
254 (delete-region (point)
256 (skip-chars-forward " ")
258 (insert "INFO-DIR-SECTION " str "\n")))
260 ;; @direntry ... @end direntry
261 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
262 (ptexinfmt-defun-if-void texinfo-format-direntry ()
263 (texinfo-push-stack 'direntry nil)
264 (texinfo-discard-line)
265 (insert "START-INFO-DIR-ENTRY\n"))
267 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
268 (ptexinfmt-defun-if-void texinfo-end-direntry ()
269 (texinfo-discard-command)
270 (insert "END-INFO-DIR-ENTRY\n\n")
271 (texinfo-pop-stack 'direntry))
275 ;; @detailmenu ... @end detailmenu
276 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
277 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
279 ;; @smalldisplay ... @end smalldisplay
280 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
281 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
283 ;; @smallformat ... @end smallformat
284 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
285 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
287 ;; @cartouche ... @end cartouche
288 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
289 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
293 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
294 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
295 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
297 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
298 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
299 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
301 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
302 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
303 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
305 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
306 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
307 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
309 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
310 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
311 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
312 (delete-region texinfo-command-start
313 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
316 ;; @html ... @end html (makeinfo 3.11 or later)
317 (put 'html 'texinfo-format 'texinfo-format-html)
318 (ptexinfmt-defun-if-void texinfo-format-html ()
319 (delete-region texinfo-command-start
320 (progn (re-search-forward "@end html[ \t]*\n")
323 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
324 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
325 (ptexinfmt-defun-if-void texinfo-format-docbook ()
326 (delete-region texinfo-command-start
327 (progn (re-search-forward "@end docbook[ \t]*\n")
330 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
331 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
332 (defun texinfo-format-ifhtml ()
333 (delete-region texinfo-command-start
334 (progn (re-search-forward "@end ifhtml[ \t]*\n")
337 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
338 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
339 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
340 (delete-region texinfo-command-start
341 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
344 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
345 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
346 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
347 (delete-region texinfo-command-start
348 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
353 ;; @env{ENVIRONMENT-VARIABLE}
354 (put 'env 'texinfo-format 'texinfo-format-code)
356 ;; @command{COMMAND-NAME}
357 (put 'command 'texinfo-format 'texinfo-format-code)
359 ;; @indicateurl{INDICATEURL}
360 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
362 ;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
363 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
366 (put 'acronym 'texinfo-format 'texinfo-format-var)
368 ;; @var{METASYNTACTIC-VARIABLE}
369 (ptexinfmt-defun-if-broken texinfo-format-var ()
370 (let ((arg (texinfo-parse-expanded-arg)))
371 (texinfo-discard-command)
372 (insert (upcase arg))))
375 (put 'key 'texinfo-format 'texinfo-format-key)
376 (ptexinfmt-defun-if-void texinfo-format-key ()
377 (insert (texinfo-parse-arg-discard))
378 (goto-char texinfo-command-start))
380 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
381 (put 'email 'texinfo-format 'texinfo-format-email)
382 (ptexinfmt-defun-if-void texinfo-format-email ()
383 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
384 Insert < ... > around EMAIL-ADDRESS."
385 (let ((args (texinfo-format-parse-args)))
386 (texinfo-discard-command)
389 (insert (nth 1 args) " <" (nth 0 args) ">")
390 (insert "<" (nth 0 args) ">"))))
392 ;; @option{OPTION-NAME}
393 (put 'option 'texinfo-format 'texinfo-format-option)
394 (ptexinfmt-defun-if-void texinfo-format-option ()
395 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
396 ;; `looking-at-backward' not available in v. 18.57, 20.2
397 ;; searched-for character is a control-H
398 (if (not (search-backward "\010"
399 (save-excursion (beginning-of-line) (point))
401 (insert "`" (texinfo-parse-arg-discard) "'")
402 (insert (texinfo-parse-arg-discard)))
403 (goto-char texinfo-command-start))
405 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
406 (put 'verb 'texinfo-format 'texinfo-format-verb)
407 (ptexinfmt-defun-if-void texinfo-format-verb ()
408 "Format text between non-quoted unique delimiter characters verbatim.
409 Enclose the verbatim text, including the delimiters, in braces. Print
410 text exactly as written (but not the delimiters) in a fixed-width.
412 For example, @verb\{|@|\} results in @ and
413 @verb\{+@'e?`!`+} results in @'e?`!`."
415 (let ((delimiter (buffer-substring-no-properties
416 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
417 (unless (looking-at "{")
418 (error "Not found: @verb start brace"))
419 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
420 (search-forward delimiter))
422 (unless (looking-at "}")
423 (error "Not found: @verb end brace"))
428 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
429 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
430 (texinfo-parse-arg-discard)
433 ;; @registeredsymbol{}
434 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
435 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
436 (texinfo-parse-arg-discard)
439 ;;; Accents and Special characters
441 (put 'euro 'texinfo-format 'texinfo-format-euro)
442 (ptexinfmt-defun-if-void texinfo-format-euro ()
443 (texinfo-parse-arg-discard)
446 ;; @pounds{} ==> # Pounds Sterling
447 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
448 (ptexinfmt-defun-if-void texinfo-format-pounds ()
449 (texinfo-parse-arg-discard)
452 ;; @ordf{} ==> a Spanish feminine
453 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
454 (ptexinfmt-defun-if-void texinfo-format-ordf ()
455 (texinfo-parse-arg-discard)
458 ;; @ordm{} ==> o Spanish masculine
459 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
460 (ptexinfmt-defun-if-void texinfo-format-ordm ()
461 (texinfo-parse-arg-discard)
464 ;; @OE{} ==> OE French-OE-ligature
465 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
466 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
467 (insert "OE" (texinfo-parse-arg-discard))
468 (goto-char texinfo-command-start))
471 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
472 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
473 (insert "oe" (texinfo-parse-arg-discard))
474 (goto-char texinfo-command-start))
476 ;; @AA{} ==> AA Scandinavian-A-with-circle
477 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
478 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
479 (insert "AA" (texinfo-parse-arg-discard))
480 (goto-char texinfo-command-start))
483 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
484 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
485 (insert "aa" (texinfo-parse-arg-discard))
486 (goto-char texinfo-command-start))
488 ;; @AE{} ==> AE Latin-Scandinavian-AE
489 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
490 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
491 (insert "AE" (texinfo-parse-arg-discard))
492 (goto-char texinfo-command-start))
495 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
496 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
497 (insert "ae" (texinfo-parse-arg-discard))
498 (goto-char texinfo-command-start))
500 ;; @ss{} ==> ss German-sharp-S
501 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
502 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
503 (insert "ss" (texinfo-parse-arg-discard))
504 (goto-char texinfo-command-start))
506 ;; @questiondown{} ==> ? upside-down-question-mark
507 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
508 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
509 (insert "?" (texinfo-parse-arg-discard))
510 (goto-char texinfo-command-start))
512 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
513 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
514 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
515 (insert "!" (texinfo-parse-arg-discard))
516 (goto-char texinfo-command-start))
518 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
519 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
520 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
521 (insert (texinfo-parse-arg-discard) "/L")
522 (goto-char texinfo-command-start))
524 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
525 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
526 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
527 (insert (texinfo-parse-arg-discard) "/l")
528 (goto-char texinfo-command-start))
530 ;; @O{} ==> O/ Scandinavian O-with-slash
531 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
532 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
533 (insert (texinfo-parse-arg-discard) "O/")
534 (goto-char texinfo-command-start))
536 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
537 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
538 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
539 (insert (texinfo-parse-arg-discard) "o/")
540 (goto-char texinfo-command-start))
542 ;; @,{c} ==> c, cedilla accent
543 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
544 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
545 (insert (texinfo-parse-arg-discard) ",")
546 (goto-char texinfo-command-start))
549 ;; @dotaccent{o} ==> .o overdot-accent
550 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
551 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
552 (insert "." (texinfo-parse-arg-discard))
553 (goto-char texinfo-command-start))
555 ;; @ubaraccent{o} ==> _o underbar-accent
556 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
557 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
558 (insert "_" (texinfo-parse-arg-discard))
559 (goto-char texinfo-command-start))
561 ;; @udotaccent{o} ==> o-. underdot-accent
562 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
563 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
564 (insert (texinfo-parse-arg-discard) "-.")
565 (goto-char texinfo-command-start))
567 ;; @H{o} ==> ""o long Hungarian umlaut
568 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
569 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
570 (insert "\"\"" (texinfo-parse-arg-discard))
571 (goto-char texinfo-command-start))
573 ;; @ringaccent{o} ==> *o ring accent
574 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
575 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
576 (insert "*" (texinfo-parse-arg-discard))
577 (goto-char texinfo-command-start))
579 ;; @tieaccent{oo} ==> [oo tie after accent
580 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
581 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
582 (insert "[" (texinfo-parse-arg-discard))
583 (goto-char texinfo-command-start))
585 ;; @u{o} ==> (o breve accent
586 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
587 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
588 (insert "(" (texinfo-parse-arg-discard))
589 (goto-char texinfo-command-start))
591 ;; @v{o} ==> <o hacek accent
592 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
593 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
594 (insert "<" (texinfo-parse-arg-discard))
595 (goto-char texinfo-command-start))
597 ;; @dotless{i} ==> i dotless i and dotless j
598 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
599 (ptexinfmt-defun-if-void texinfo-format-dotless ()
600 (insert (texinfo-parse-arg-discard))
601 (goto-char texinfo-command-start))
604 (put '\. 'texinfo-format 'texinfo-format-\.)
605 (ptexinfmt-defun-if-void texinfo-format-\. ()
606 (texinfo-discard-command)
610 (put '\: 'texinfo-format 'texinfo-format-\:)
611 (ptexinfmt-defun-if-void texinfo-format-\: ()
612 (texinfo-discard-command))
615 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
616 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
617 (texinfo-discard-command))
620 (put '\/ 'texinfo-format 'texinfo-format-\/)
621 (ptexinfmt-defun-if-void texinfo-format-\/ ()
622 (texinfo-discard-command))
625 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
626 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
627 (insert "o" (texinfo-parse-arg-discard))
628 (goto-char texinfo-command-start))
631 (put 'geq 'texinfo-format 'texinfo-format-geq)
632 (ptexinfmt-defun-if-void texinfo-format-geq ()
633 (insert ">=" (texinfo-parse-arg-discard))
634 (goto-char texinfo-command-start))
637 (put 'leq 'texinfo-format 'texinfo-format-leq)
638 (ptexinfmt-defun-if-void texinfo-format-leq ()
639 (insert "<=" (texinfo-parse-arg-discard))
640 (goto-char texinfo-command-start))
644 ;; @ref{NODE-NAME, ...}
645 ;; @xref{NODE-NAME, ...}
646 (put 'ref 'texinfo-format 'texinfo-format-xref)
648 (ptexinfmt-defun-if-broken texinfo-format-xref ()
649 (let ((args (texinfo-format-parse-args)))
650 (texinfo-discard-command)
652 (let ((fname (or (nth 1 args) (nth 2 args))))
653 (if (null (or fname (nth 3 args)))
654 (insert (nth 0 args) "::")
655 (insert (or fname (nth 0 args)) ": ")
657 (insert "(" (nth 3 args) ")"))
658 (unless (null (nth 0 args))
659 (insert (nth 0 args)))))))
661 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
662 (put 'uref 'texinfo-format 'texinfo-format-uref)
663 (ptexinfmt-defun-if-broken texinfo-format-uref ()
664 "Format URL and optional URL-TITLE.
665 Insert ` ... ' around URL if no URL-TITLE argument;
666 otherwise, insert URL-TITLE followed by URL in parentheses."
667 (let ((args (texinfo-format-parse-args)))
668 (texinfo-discard-command)
671 (insert (nth 1 args) " (" (nth 0 args) ")")
672 (insert "`" (nth 0 args) "'"))))
674 ;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
675 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
676 (ptexinfmt-defun-if-void texinfo-format-inforef ()
677 (let ((args (texinfo-format-parse-args)))
678 (texinfo-discard-command)
680 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
681 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
686 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
687 ;; - Info-tagify suport @anthor-*-refill.
688 ;; - info.el support Ref in Tag table.
689 (unless (get 'anchor 'texinfo-format)
690 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
694 ;;; New command definition
695 ;; @alias NEW=EXISTING
696 (put 'alias 'texinfo-format 'texinfo-alias)
697 (ptexinfmt-defun-if-void texinfo-alias ()
698 (let ((start (1- (point)))
700 (skip-chars-forward " ")
701 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
702 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
703 (error "Invalid alias command")
704 (setq texinfo-alias-list
707 (buffer-substring (match-beginning 1) (match-end 1))
708 (buffer-substring (match-beginning 2) (match-end 2)))
710 (texinfo-discard-command))))
714 ;; @exampleindent INDENT (makeinfo 4.0 or later)
716 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
717 ;; INDENT: asis, 0, n
719 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
720 ;; WORD: none, insert
725 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
726 (put 'image 'texinfo-format 'texinfo-format-image)
727 (ptexinfmt-defun-if-void texinfo-format-image ()
728 ;; I don't know makeinfo parse FILENAME.
729 (let ((args (texinfo-format-parse-args))
731 (when (null (nth 0 args))
732 (error "Invalid image command"))
733 (texinfo-discard-command)
734 ;; makeinfo uses FILENAME.txt
735 (setq filename (format "%s.txt" (nth 0 args)))
736 (message "Reading included file: %s" filename)
737 ;; verbatim for Info output
738 (goto-char (+ (point) (cadr (insert-file-contents filename))))
739 (message "Reading included file: %s...done" filename)))
743 ;;; @multitable ... @end multitable
744 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
745 "*Number of extra spaces between entries (columns) in @multitable.")
747 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
748 "*multitable-temporary-buffer*")
749 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
750 "texinfo-multitable-temp-")
752 ;; These commands are defined in texinfo.tex for printed output.
753 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
754 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
755 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
756 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
758 (put 'multitable 'texinfo-format 'texinfo-multitable)
760 (ptexinfmt-defun-if-void texinfo-multitable ()
761 "Produce multi-column tables."
763 ;; This function pushes information onto the `texinfo-stack'.
764 ;; A stack element consists of:
765 ;; - type-of-command, i.e., multitable
766 ;; - the information about column widths, and
767 ;; - the position of texinfo-command-start.
768 ;; e.g., ('multitable (1 2 3 4) 123)
769 ;; The command line is then deleted.
772 ;; push width information on stack
773 (texinfo-multitable-widths))
774 (texinfo-discard-line-with-args))
776 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
777 (ptexinfmt-defun-if-void texinfo-end-multitable ()
778 "Discard the @end multitable line and pop the stack of multitable."
779 (texinfo-discard-command)
780 (texinfo-pop-stack 'multitable))
782 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
783 "Return list of widths of each column in a multi-column table."
784 (let (texinfo-multitable-width-list)
786 ;; @multitable @columnfractions .25 .3 .45
789 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
790 ;; Place point before first argument
791 (skip-chars-forward " \t")
793 ;; Check for common misspelling
794 ((looking-at "@columnfraction ")
795 (error "In @multitable, @columnfractions misspelled"))
796 ;; Case 1: @columnfractions .25 .3 .45
797 ((looking-at "@columnfractions")
800 (setq texinfo-multitable-width-list
804 (* fill-column (read (get-buffer (current-buffer))))))
805 texinfo-multitable-width-list))))
807 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
809 (let ((start-of-templates (point)))
811 (skip-chars-forward " \t")
812 (let* ((start-of-template (1+ (point)))
814 ;; forward-sexp works with braces in Texinfo mode
815 (progn (forward-sexp 1) (1- (point)))))
816 (setq texinfo-multitable-width-list
818 (goto-char end-of-template)
821 (goto-char start-of-template)
823 texinfo-multitable-width-list))
824 ;; Remove carriage return from within a template, if any.
825 ;; This helps those those who want to use more than
826 ;; one line's worth of words in @multitable line.
827 (narrow-to-region start-of-template end-of-template)
828 (goto-char (point-min))
829 (while (search-forward "\n" nil t)
831 (goto-char (point-max))
838 You probably need to specify column widths for @multitable correctly")))
839 ;; Check whether columns fit on page.
840 (let ((desired-columns
842 ;; between column spaces
843 (length texinfo-multitable-width-list)
844 ;; additional between column spaces, if any
845 texinfo-extra-inter-column-width
846 ;; sum of spaces for each entry
847 (apply '+ texinfo-multitable-width-list))))
848 (if (> desired-columns fill-column)
850 Multi-column table width, %d chars, is greater than page width, %d chars."
851 desired-columns fill-column))))
852 texinfo-multitable-width-list))
854 ;; @item A1 @tab A2 @tab A3
855 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
856 "Return multitable row, as a string.
857 End of row is beginning of next @item or beginning of @end.
858 Cells within rows are separated by @tab."
859 (skip-chars-forward " \t")
860 (let* ((start (point))
862 (re-search-forward "@item\\|@end")
863 (match-beginning 0)))
864 (row (progn (goto-char end)
865 (skip-chars-backward " ")
866 ;; remove whitespace at end of argument
867 (delete-region (point) end)
868 (buffer-substring start (point)))))
869 (delete-region texinfo-command-start end)
872 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
873 (ptexinfmt-defun-if-void texinfo-multitable-item ()
874 "Format a row within a multicolumn table.
875 Cells in row are separated by @tab.
876 Widths of cells are specified by the arguments in the @multitable line.
877 All cells are made to be the same height.
878 This command is executed when texinfmt sees @item inside @multitable."
879 (let ((original-buffer (current-buffer))
880 (table-widths (reverse (car (cdr (car texinfo-stack)))))
881 (existing-fill-column fill-column)
885 (table-entry-height 0)
886 ;; unformatted row looks like: A1 @tab A2 @tab A3
887 ;; extract-row command deletes the source line in the table.
888 (unformated-row (texinfo-multitable-extract-row)))
889 ;; Use a temporary buffer
890 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
891 (delete-region (point-min) (point-max))
892 (insert unformated-row)
893 (goto-char (point-min))
894 ;; 1. Check for correct number of @tab in line.
895 (let ((tab-number 1)) ;; one @tab between two columns
896 (while (search-forward "@tab" nil t)
897 (setq tab-number (1+ tab-number)))
898 (if (/= tab-number (length table-widths))
899 (error "Wrong number of @tab's in a @multitable row")))
900 (goto-char (point-min))
901 ;; 2. Format each cell, and copy to a rectangle
902 ;; buffer looks like this: A1 @tab A2 @tab A3
903 ;; Cell #1: format up to @tab
904 ;; Cell #2: format up to @tab
905 ;; Cell #3: format up to eob
908 (setq end (save-excursion
909 (if (search-forward "@tab" nil 'move)
910 ;; Delete the @tab command, including the @-sign
913 (progn (forward-word -1) (1- (point)))))
915 ;; Set fill-column *wider* than needed to produce inter-column space
916 (setq fill-column (+ 1
917 texinfo-extra-inter-column-width
918 (nth table-column table-widths)))
919 (narrow-to-region start end)
920 ;; Remove whitespace before and after entry.
921 (skip-chars-forward " ")
922 (delete-region (point) (save-excursion (beginning-of-line) (point)))
923 (goto-char (point-max))
924 (skip-chars-backward " ")
925 (delete-region (point) (save-excursion (end-of-line) (point)))
926 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
927 ;; does not see an unterminated @multitable.
928 (let (texinfo-stack) ;; nil
929 (texinfo-format-scan))
930 (let (fill-prefix) ;; no fill prefix
931 (fill-region (point-min) (point-max)))
932 (setq table-entry-height
933 (max table-entry-height (count-lines (point-min) (point-max))))
934 ;; 3. Move point to end of bottom line, and pad that line to fill column.
935 (goto-char (point-min))
936 (forward-line (1- table-entry-height))
937 (let* ((beg (point)) ;; beginning of line
938 ;; add one more space for inter-column spacing
944 (current-column)))))) ;; end of existing line
946 (if (> needed-whitespace 0) needed-whitespace 1)
948 ;; now, put formatted cell into a rectangle
949 (set (intern (concat texinfo-multitable-rectangle-name
950 (int-to-string table-column)))
951 (extract-rectangle (point-min) (point)))
952 (delete-region (point-min) (point))
953 (goto-char (point-max))
954 (setq table-column (1+ table-column))
956 ;; 4. Add extra lines to rectangles so all are of same height
957 (let ((total-number-of-columns table-column)
960 (while (> table-column 0)
961 (let ((this-rectangle (int-to-string table-column)))
962 (while (< (length this-rectangle) table-entry-height)
963 (setq this-rectangle (append this-rectangle '("")))))
964 (setq table-column (1- table-column)))
965 ;; 5. Insert formatted rectangles in original buffer
966 (switch-to-buffer original-buffer)
967 (open-line table-entry-height)
968 (while (< column-number total-number-of-columns)
972 (concat texinfo-multitable-rectangle-name
973 (int-to-string column-number)))))
976 (setq column-number (1+ column-number))))
977 (kill-buffer texinfo-multitable-buffer-name)
978 (setq fill-column existing-fill-column)))
981 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
982 (let ((indexelts (symbol-value
983 (cdr (assoc (texinfo-parse-arg-discard)
984 texinfo-indexvar-alist))))
986 (insert "\n* Menu:\n\n")
987 (setq opoint (point))
988 (texinfo-print-index nil indexelts)
990 (if (memq system-type '(vax-vms windows-nt ms-dos))
991 (texinfo-sort-region opoint (point))
992 (shell-command-on-region opoint (point) "sort -fd" 1))))
995 ;; @copying ... @end copying
996 ;; that Emacs 21.4 and lesser and XEmacs don't support.
997 (if (fboundp 'texinfo-copying)
999 (defvar texinfo-copying-text ""
1000 "Text of the copyright notice and copying permissions.")
1002 (defun texinfo-copying ()
1003 "Copy the copyright notice and copying permissions from the Texinfo file,
1004 as indicated by the @copying ... @end copying command;
1005 insert the text with the @insertcopying command."
1006 (let ((beg (progn (beginning-of-line) (point)))
1007 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
1008 (setq texinfo-copying-text
1009 (buffer-substring-no-properties
1010 (save-excursion (goto-char beg) (forward-line 1) (point))
1011 (save-excursion (goto-char end) (forward-line -1) (point))))
1012 (delete-region beg end)))
1014 (defun texinfo-insertcopying ()
1015 "Insert the copyright notice and copying permissions from the Texinfo file,
1016 which are indicated by the @copying ... @end copying command."
1017 (insert (concat "\n" texinfo-copying-text)))
1019 (defadvice texinfo-format-scan (before expand-@copying-section activate)
1020 "Extract @copying and replace @insertcopying with it."
1021 (goto-char (point-min))
1022 (when (search-forward "@copying" nil t)
1024 (while (search-forward "@insertcopying" nil t)
1025 (delete-region (match-beginning 0) (match-end 0))
1026 (texinfo-insertcopying))))
1030 (if (fboundp 'texinfo-format-comma)
1032 (put 'comma 'texinfo-format 'texinfo-format-comma)
1033 (defun texinfo-format-comma ()
1034 (texinfo-parse-arg-discard)
1036 (put-text-property (1- (point)) (point) 'ignore t))
1038 ;; Redefine this function so as to work for @comma
1039 (defun texinfo-format-parse-args ()
1040 (let ((start (1- (point)))
1043 (search-forward "{")
1045 (texinfo-format-expand-region
1047 (save-excursion (up-list 1) (1- (point)))))
1048 ;; The following does not handle cross references of the form:
1049 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1050 ;; re-search-forward finds the first right brace after the second
1052 (while (/= (preceding-char) ?\})
1053 (skip-chars-forward " \t\n")
1055 ;;; (re-search-forward "[},]")
1056 ;; Ignore commas that are derived from @comma{}.
1057 (while (and (re-search-forward "[},]" nil t)
1058 (get-text-property (match-beginning 0) 'ignore)))
1062 (skip-chars-backward " \t\n")
1066 (while (search-forward "\n" end t)
1067 (replace-match " "))))
1068 (push (if (> end beg) (buffer-substring-no-properties beg end))
1071 ;;(if (eolp) (forward-char 1))
1072 (setq texinfo-command-end (point))
1075 (provide 'ptexinfmt)
1077 ;;; ptexinfmt.el ends here