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
45 ;; @quotation (optional arguments)
46 ;; @acronym{ACRONYM[, MEANING]} (optional argument)
47 ;; @dofirstparagraphindent
49 ;; @verbatiminclude FILENAME
51 ;; @definfoenclose phoo,//,\\
52 ;; @deftypeivar CLASS DATA-TYPE VARIABLE-NAME
53 ;; @deftypeop CATEGORY CLASS DATA-TYPE NAME ARGUMENTS...
54 ;; @allowcodebreaks false
56 ;; @quotedblleft @quotedblright
57 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
58 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
59 ;; @clicksequence, @click, @clickstyle, @arrow
65 ;; Work around a problem that double-quotes at bol disappear:
66 ;; @dfn{FOO} => FOO", ``BAR'' => BAR", \BAZ/ => BAZ/
67 (modify-syntax-entry ?\" "w" texinfo-format-syntax-table)
68 (modify-syntax-entry ?\\ "w" texinfo-format-syntax-table)
71 (defvar ptexinfmt-disable-broken-notice-flag t
72 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
73 This is last argument in `ptexinfmt-broken-facility'.")
75 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
76 (defmacro ptexinfmt-broken-facility (facility docstring assertion
78 "Declare a symbol FACILITY is broken if ASSERTION is nil.
79 DOCSTRING will be printed if ASSERTION is nil and
80 `ptexinfmt-disable-broken-notice-flag' is nil."
81 `(let ((facility ',facility)
82 (docstring ,docstring)
83 (assertion (eval ',assertion)))
84 (put facility 'broken (not assertion))
87 (put facility 'broken-docstring docstring)
88 (if ptexinfmt-disable-broken-notice-flag
90 (message "BROKEN FACILITY DETECTED: %s" docstring)))))
92 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
93 (defmacro ptexinfmt-defun-if-broken (&rest args)
94 "Redefine a function just like `defun' if it is considered broken."
95 (let ((name (list 'quote (car args))))
96 (setq args (cdr args))
99 (if (get ,name 'broken)
101 (function (lambda ,@args)))))))
103 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
104 (defmacro ptexinfmt-defun-if-void (&rest args)
105 "Define a function just like `defun' unless it is already defined."
106 (let ((name (list 'quote (car args))))
107 (setq args (cdr args))
113 (function (lambda ,@args)))))))
115 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
116 (defmacro ptexinfmt-defvar-if-void (&rest args)
117 "Define a variable just like `defvar' unless it is already defined."
118 (let ((name (car args)))
119 (setq args (cdr args))
124 (defvar ,name ,@args)))))
127 (ptexinfmt-broken-facility texinfo-format-printindex
128 "Can't sort on Mule for Windows."
129 (if (and (memq system-type '(windows-nt ms-dos))
130 ;;; I don't know version threshold.
131 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
132 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
136 ;; @var{METASYNTACTIC-VARIABLE}
137 (defvar texinfo-enclosure-list)
138 (defvar texinfo-alias-list)
139 (ptexinfmt-broken-facility texinfo-format-var
140 "Don't perse @var argument."
143 (let (texinfo-enclosure-list texinfo-alias-list)
145 (insert "@var{@asis{foo}}\n")
146 (texinfo-format-expand-region (point-min) (point-max))
150 ;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
151 ;; INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
152 (ptexinfmt-broken-facility texinfo-format-xref
153 "Can't format @xref, 1st argument is empty."
156 (let (texinfo-enclosure-list texinfo-alias-list)
158 (insert "@xref{, xref, , file}\n")
159 (texinfo-format-expand-region (point-min) (point-max))
163 ;; @uref{URL[, TEXT][, REPLACEMENT]}
164 (ptexinfmt-broken-facility texinfo-format-uref
165 "Parse twice @uref argument."
168 (let (texinfo-enclosure-list texinfo-alias-list)
170 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
171 (texinfo-format-expand-region (point-min) (point-max))
176 (ptexinfmt-broken-facility texinfo-multitable-widths
177 "`texinfo-multitable-widths' unsupport wide-char."
178 (if (fboundp 'texinfo-multitable-widths)
180 (let ((str (string (make-char 'japanese-jisx0208 73 125)
181 (make-char 'japanese-jisx0208 57 45)
182 (make-char 'japanese-jisx0208 74 56)
183 (make-char 'japanese-jisx0208 59 122))))
185 (insert (format " {%s}\n" str))
186 (goto-char (point-min))
187 (if (= (car (texinfo-multitable-widths)) (length str))
190 ;; function definition is void
193 (ptexinfmt-broken-facility texinfo-multitable-item
194 "`texinfo-multitable-item' unsupport wide-char."
195 (not (get 'texinfo-multitable-widths 'broken)))
198 ;;; Hardcopy and HTML (discard)
200 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
202 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
206 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
207 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
208 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
209 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
210 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
211 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
212 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
216 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
219 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
220 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
221 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
222 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
225 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
226 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
227 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
228 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
229 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
230 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
231 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
234 (put 'page 'texinfo-format 'texinfo-discard-line)
235 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
237 ;; @slanted{TEXT} (makeinfo 4.8 or later)
238 (put 'slanted 'texinfo-format 'texinfo-format-noop)
240 ;; @sansserif{TEXT} (makeinfo 4.8 or later)
241 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
243 ;; @tie{} (makeinfo 4.3 or later)
244 (put 'tie 'texinfo-format 'texinfo-format-tie)
245 (ptexinfmt-defun-if-void texinfo-format-tie ()
246 (texinfo-parse-arg-discard)
251 ;; @direcategory DIRPART
252 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
253 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
254 (let ((str (texinfo-parse-arg-discard)))
255 (delete-region (point)
257 (skip-chars-forward " ")
259 (insert "INFO-DIR-SECTION " str "\n")))
261 ;; @direntry ... @end direntry
262 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
263 (ptexinfmt-defun-if-void texinfo-format-direntry ()
264 (texinfo-push-stack 'direntry nil)
265 (texinfo-discard-line)
266 (insert "START-INFO-DIR-ENTRY\n"))
268 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
269 (ptexinfmt-defun-if-void texinfo-end-direntry ()
270 (texinfo-discard-command)
271 (insert "END-INFO-DIR-ENTRY\n\n")
272 (texinfo-pop-stack 'direntry))
276 ;; @detailmenu ... @end detailmenu
277 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
278 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
280 ;; @smalldisplay ... @end smalldisplay
281 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
282 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
284 ;; @smallformat ... @end smallformat
285 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
286 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
288 ;; @cartouche ... @end cartouche
289 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
290 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
294 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
295 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
296 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
298 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
299 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
300 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
302 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
303 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
304 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
306 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
307 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
308 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
310 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
311 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
312 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
313 (delete-region texinfo-command-start
314 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
317 ;; @html ... @end html (makeinfo 3.11 or later)
318 (put 'html 'texinfo-format 'texinfo-format-html)
319 (ptexinfmt-defun-if-void texinfo-format-html ()
320 (delete-region texinfo-command-start
321 (progn (re-search-forward "@end html[ \t]*\n")
324 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
325 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
326 (ptexinfmt-defun-if-void texinfo-format-docbook ()
327 (delete-region texinfo-command-start
328 (progn (re-search-forward "@end docbook[ \t]*\n")
331 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
332 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
333 (defun texinfo-format-ifhtml ()
334 (delete-region texinfo-command-start
335 (progn (re-search-forward "@end ifhtml[ \t]*\n")
338 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
339 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
340 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
341 (delete-region texinfo-command-start
342 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
345 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
346 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
347 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
348 (delete-region texinfo-command-start
349 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
354 ;; @env{ENVIRONMENT-VARIABLE}
355 (put 'env 'texinfo-format 'texinfo-format-code)
357 ;; @command{COMMAND-NAME}
358 (put 'command 'texinfo-format 'texinfo-format-code)
360 ;; @indicateurl{INDICATEURL}
361 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
363 ;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
364 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
367 (put 'acronym 'texinfo-format 'texinfo-format-var)
369 ;; @var{METASYNTACTIC-VARIABLE}
370 (ptexinfmt-defun-if-broken texinfo-format-var ()
371 (let ((arg (texinfo-parse-expanded-arg)))
372 (texinfo-discard-command)
373 (insert (upcase arg))))
376 (put 'key 'texinfo-format 'texinfo-format-key)
377 (ptexinfmt-defun-if-void texinfo-format-key ()
378 (insert (texinfo-parse-arg-discard))
379 (goto-char texinfo-command-start))
381 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
382 (put 'email 'texinfo-format 'texinfo-format-email)
383 (ptexinfmt-defun-if-void texinfo-format-email ()
384 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
385 Insert < ... > around EMAIL-ADDRESS."
386 (let ((args (texinfo-format-parse-args)))
387 (texinfo-discard-command)
390 (insert (nth 1 args) " <" (nth 0 args) ">")
391 (insert "<" (nth 0 args) ">"))))
393 ;; @option{OPTION-NAME}
394 (put 'option 'texinfo-format 'texinfo-format-option)
395 (ptexinfmt-defun-if-void texinfo-format-option ()
396 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
397 ;; `looking-at-backward' not available in v. 18.57, 20.2
398 ;; searched-for character is a control-H
399 (if (not (search-backward "\010"
400 (save-excursion (beginning-of-line) (point))
402 (insert "`" (texinfo-parse-arg-discard) "'")
403 (insert (texinfo-parse-arg-discard)))
404 (goto-char texinfo-command-start))
406 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
407 (put 'verb 'texinfo-format 'texinfo-format-verb)
408 (ptexinfmt-defun-if-void texinfo-format-verb ()
409 "Format text between non-quoted unique delimiter characters verbatim.
410 Enclose the verbatim text, including the delimiters, in braces. Print
411 text exactly as written (but not the delimiters) in a fixed-width.
413 For example, @verb\{|@|\} results in @ and
414 @verb\{+@'e?`!`+} results in @'e?`!`."
416 (let ((delimiter (buffer-substring-no-properties
417 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
418 (unless (looking-at "{")
419 (error "Not found: @verb start brace"))
420 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
421 (search-forward delimiter))
423 (unless (looking-at "}")
424 (error "Not found: @verb end brace"))
429 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
430 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
431 (texinfo-parse-arg-discard)
434 ;; @registeredsymbol{}
435 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
436 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
437 (texinfo-parse-arg-discard)
440 ;;; Accents and Special characters
442 (put 'euro 'texinfo-format 'texinfo-format-euro)
443 (ptexinfmt-defun-if-void texinfo-format-euro ()
444 (texinfo-parse-arg-discard)
447 ;; @pounds{} ==> # Pounds Sterling
448 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
449 (ptexinfmt-defun-if-void texinfo-format-pounds ()
450 (texinfo-parse-arg-discard)
453 ;; @ordf{} ==> a Spanish feminine
454 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
455 (ptexinfmt-defun-if-void texinfo-format-ordf ()
456 (texinfo-parse-arg-discard)
459 ;; @ordm{} ==> o Spanish masculine
460 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
461 (ptexinfmt-defun-if-void texinfo-format-ordm ()
462 (texinfo-parse-arg-discard)
465 ;; @OE{} ==> OE French-OE-ligature
466 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
467 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
468 (insert "OE" (texinfo-parse-arg-discard))
469 (goto-char texinfo-command-start))
472 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
473 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
474 (insert "oe" (texinfo-parse-arg-discard))
475 (goto-char texinfo-command-start))
477 ;; @AA{} ==> AA Scandinavian-A-with-circle
478 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
479 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
480 (insert "AA" (texinfo-parse-arg-discard))
481 (goto-char texinfo-command-start))
484 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
485 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
486 (insert "aa" (texinfo-parse-arg-discard))
487 (goto-char texinfo-command-start))
489 ;; @AE{} ==> AE Latin-Scandinavian-AE
490 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
491 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
492 (insert "AE" (texinfo-parse-arg-discard))
493 (goto-char texinfo-command-start))
496 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
497 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
498 (insert "ae" (texinfo-parse-arg-discard))
499 (goto-char texinfo-command-start))
501 ;; @ss{} ==> ss German-sharp-S
502 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
503 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
504 (insert "ss" (texinfo-parse-arg-discard))
505 (goto-char texinfo-command-start))
507 ;; @questiondown{} ==> ? upside-down-question-mark
508 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
509 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
510 (insert "?" (texinfo-parse-arg-discard))
511 (goto-char texinfo-command-start))
513 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
514 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
515 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
516 (insert "!" (texinfo-parse-arg-discard))
517 (goto-char texinfo-command-start))
519 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
520 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
521 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
522 (insert (texinfo-parse-arg-discard) "/L")
523 (goto-char texinfo-command-start))
525 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
526 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
527 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
528 (insert (texinfo-parse-arg-discard) "/l")
529 (goto-char texinfo-command-start))
531 ;; @O{} ==> O/ Scandinavian O-with-slash
532 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
533 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
534 (insert (texinfo-parse-arg-discard) "O/")
535 (goto-char texinfo-command-start))
537 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
538 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
539 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
540 (insert (texinfo-parse-arg-discard) "o/")
541 (goto-char texinfo-command-start))
543 ;; @,{c} ==> c, cedilla accent
544 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
545 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
546 (insert (texinfo-parse-arg-discard) ",")
547 (goto-char texinfo-command-start))
550 ;; @dotaccent{o} ==> .o overdot-accent
551 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
552 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
553 (insert "." (texinfo-parse-arg-discard))
554 (goto-char texinfo-command-start))
556 ;; @ubaraccent{o} ==> _o underbar-accent
557 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
558 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
559 (insert "_" (texinfo-parse-arg-discard))
560 (goto-char texinfo-command-start))
562 ;; @udotaccent{o} ==> o-. underdot-accent
563 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
564 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
565 (insert (texinfo-parse-arg-discard) "-.")
566 (goto-char texinfo-command-start))
568 ;; @H{o} ==> ""o long Hungarian umlaut
569 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
570 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
571 (insert "\"\"" (texinfo-parse-arg-discard))
572 (goto-char texinfo-command-start))
574 ;; @ringaccent{o} ==> *o ring accent
575 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
576 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
577 (insert "*" (texinfo-parse-arg-discard))
578 (goto-char texinfo-command-start))
580 ;; @tieaccent{oo} ==> [oo tie after accent
581 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
582 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
583 (insert "[" (texinfo-parse-arg-discard))
584 (goto-char texinfo-command-start))
586 ;; @u{o} ==> (o breve accent
587 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
588 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
589 (insert "(" (texinfo-parse-arg-discard))
590 (goto-char texinfo-command-start))
592 ;; @v{o} ==> <o hacek accent
593 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
594 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
595 (insert "<" (texinfo-parse-arg-discard))
596 (goto-char texinfo-command-start))
598 ;; @dotless{i} ==> i dotless i and dotless j
599 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
600 (ptexinfmt-defun-if-void texinfo-format-dotless ()
601 (insert (texinfo-parse-arg-discard))
602 (goto-char texinfo-command-start))
605 (put '\. 'texinfo-format 'texinfo-format-\.)
606 (ptexinfmt-defun-if-void texinfo-format-\. ()
607 (texinfo-discard-command)
611 (put '\: 'texinfo-format 'texinfo-format-\:)
612 (ptexinfmt-defun-if-void texinfo-format-\: ()
613 (texinfo-discard-command))
616 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
617 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
618 (texinfo-discard-command))
621 (put '\/ 'texinfo-format 'texinfo-format-\/)
622 (ptexinfmt-defun-if-void texinfo-format-\/ ()
623 (texinfo-discard-command))
626 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
627 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
628 (insert "o" (texinfo-parse-arg-discard))
629 (goto-char texinfo-command-start))
632 (put 'geq 'texinfo-format 'texinfo-format-geq)
633 (ptexinfmt-defun-if-void texinfo-format-geq ()
634 (insert ">=" (texinfo-parse-arg-discard))
635 (goto-char texinfo-command-start))
638 (put 'leq 'texinfo-format 'texinfo-format-leq)
639 (ptexinfmt-defun-if-void texinfo-format-leq ()
640 (insert "<=" (texinfo-parse-arg-discard))
641 (goto-char texinfo-command-start))
645 ;; @ref{NODE-NAME, ...}
646 ;; @xref{NODE-NAME, ...}
647 (put 'ref 'texinfo-format 'texinfo-format-xref)
649 (ptexinfmt-defun-if-broken texinfo-format-xref ()
650 (let ((args (texinfo-format-parse-args)))
651 (texinfo-discard-command)
653 (let ((fname (or (nth 1 args) (nth 2 args))))
654 (if (null (or fname (nth 3 args)))
655 (insert (nth 0 args) "::")
656 (insert (or fname (nth 0 args)) ": ")
658 (insert "(" (nth 3 args) ")"))
659 (unless (null (nth 0 args))
660 (insert (nth 0 args)))))))
662 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
663 (put 'uref 'texinfo-format 'texinfo-format-uref)
664 (ptexinfmt-defun-if-broken texinfo-format-uref ()
665 "Format URL and optional URL-TITLE.
666 Insert ` ... ' around URL if no URL-TITLE argument;
667 otherwise, insert URL-TITLE followed by URL in parentheses."
668 (let ((args (texinfo-format-parse-args)))
669 (texinfo-discard-command)
672 (insert (nth 1 args) " (" (nth 0 args) ")")
673 (insert "`" (nth 0 args) "'"))))
675 ;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
676 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
677 (ptexinfmt-defun-if-void texinfo-format-inforef ()
678 (let ((args (texinfo-format-parse-args)))
679 (texinfo-discard-command)
681 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
682 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
687 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
688 ;; - Info-tagify suport @anthor-*-refill.
689 ;; - info.el support Ref in Tag table.
690 (unless (get 'anchor 'texinfo-format)
691 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
695 ;;; New command definition
696 ;; @alias NEW=EXISTING
697 (put 'alias 'texinfo-format 'texinfo-alias)
698 (ptexinfmt-defun-if-void texinfo-alias ()
699 (let ((start (1- (point)))
701 (skip-chars-forward " ")
702 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
703 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
704 (error "Invalid alias command")
705 (setq texinfo-alias-list
708 (buffer-substring (match-beginning 1) (match-end 1))
709 (buffer-substring (match-beginning 2) (match-end 2)))
711 (texinfo-discard-command))))
715 ;; @exampleindent INDENT (makeinfo 4.0 or later)
717 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
718 ;; INDENT: asis, 0, n
720 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
721 ;; WORD: none, insert
726 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
727 (put 'image 'texinfo-format 'texinfo-format-image)
728 (ptexinfmt-defun-if-void texinfo-format-image ()
729 ;; I don't know makeinfo parse FILENAME.
730 (let ((args (texinfo-format-parse-args))
732 (when (null (nth 0 args))
733 (error "Invalid image command"))
734 (texinfo-discard-command)
735 ;; makeinfo uses FILENAME.txt
736 (setq filename (format "%s.txt" (nth 0 args)))
737 (message "Reading included file: %s" filename)
738 ;; verbatim for Info output
739 (goto-char (+ (point) (cadr (insert-file-contents filename))))
740 (message "Reading included file: %s...done" filename)))
744 ;;; @multitable ... @end multitable
745 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
746 "*Number of extra spaces between entries (columns) in @multitable.")
748 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
749 "*multitable-temporary-buffer*")
750 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
751 "texinfo-multitable-temp-")
753 ;; These commands are defined in texinfo.tex for printed output.
754 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
755 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
756 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
757 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
759 (put 'multitable 'texinfo-format 'texinfo-multitable)
761 (ptexinfmt-defun-if-void texinfo-multitable ()
762 "Produce multi-column tables."
764 ;; This function pushes information onto the `texinfo-stack'.
765 ;; A stack element consists of:
766 ;; - type-of-command, i.e., multitable
767 ;; - the information about column widths, and
768 ;; - the position of texinfo-command-start.
769 ;; e.g., ('multitable (1 2 3 4) 123)
770 ;; The command line is then deleted.
773 ;; push width information on stack
774 (texinfo-multitable-widths))
775 (texinfo-discard-line-with-args))
777 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
778 (ptexinfmt-defun-if-void texinfo-end-multitable ()
779 "Discard the @end multitable line and pop the stack of multitable."
780 (texinfo-discard-command)
781 (texinfo-pop-stack 'multitable))
783 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
784 "Return list of widths of each column in a multi-column table."
785 (let (texinfo-multitable-width-list)
787 ;; @multitable @columnfractions .25 .3 .45
790 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
791 ;; Place point before first argument
792 (skip-chars-forward " \t")
794 ;; Check for common misspelling
795 ((looking-at "@columnfraction ")
796 (error "In @multitable, @columnfractions misspelled"))
797 ;; Case 1: @columnfractions .25 .3 .45
798 ((looking-at "@columnfractions")
801 (setq texinfo-multitable-width-list
805 (* fill-column (read (get-buffer (current-buffer))))))
806 texinfo-multitable-width-list))))
808 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
810 (let ((start-of-templates (point)))
812 (skip-chars-forward " \t")
813 (let* ((start-of-template (1+ (point)))
815 ;; forward-sexp works with braces in Texinfo mode
816 (progn (forward-sexp 1) (1- (point)))))
817 (setq texinfo-multitable-width-list
819 (goto-char end-of-template)
822 (goto-char start-of-template)
824 texinfo-multitable-width-list))
825 ;; Remove carriage return from within a template, if any.
826 ;; This helps those those who want to use more than
827 ;; one line's worth of words in @multitable line.
828 (narrow-to-region start-of-template end-of-template)
829 (goto-char (point-min))
830 (while (search-forward "\n" nil t)
832 (goto-char (point-max))
839 You probably need to specify column widths for @multitable correctly")))
840 ;; Check whether columns fit on page.
841 (let ((desired-columns
843 ;; between column spaces
844 (length texinfo-multitable-width-list)
845 ;; additional between column spaces, if any
846 texinfo-extra-inter-column-width
847 ;; sum of spaces for each entry
848 (apply '+ texinfo-multitable-width-list))))
849 (if (> desired-columns fill-column)
851 Multi-column table width, %d chars, is greater than page width, %d chars."
852 desired-columns fill-column))))
853 texinfo-multitable-width-list))
855 ;; @item A1 @tab A2 @tab A3
856 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
857 "Return multitable row, as a string.
858 End of row is beginning of next @item or beginning of @end.
859 Cells within rows are separated by @tab."
860 (skip-chars-forward " \t")
861 (let* ((start (point))
863 (re-search-forward "@item\\|@end")
864 (match-beginning 0)))
865 (row (progn (goto-char end)
866 (skip-chars-backward " ")
867 ;; remove whitespace at end of argument
868 (delete-region (point) end)
869 (buffer-substring start (point)))))
870 (delete-region texinfo-command-start end)
873 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
874 (ptexinfmt-defun-if-void texinfo-multitable-item ()
875 "Format a row within a multicolumn table.
876 Cells in row are separated by @tab.
877 Widths of cells are specified by the arguments in the @multitable line.
878 All cells are made to be the same height.
879 This command is executed when texinfmt sees @item inside @multitable."
880 (let ((original-buffer (current-buffer))
881 (table-widths (reverse (car (cdr (car texinfo-stack)))))
882 (existing-fill-column fill-column)
886 (table-entry-height 0)
887 ;; unformatted row looks like: A1 @tab A2 @tab A3
888 ;; extract-row command deletes the source line in the table.
889 (unformated-row (texinfo-multitable-extract-row)))
890 ;; Use a temporary buffer
891 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
892 (delete-region (point-min) (point-max))
893 (insert unformated-row)
894 (goto-char (point-min))
895 ;; 1. Check for correct number of @tab in line.
896 (let ((tab-number 1)) ;; one @tab between two columns
897 (while (search-forward "@tab" nil t)
898 (setq tab-number (1+ tab-number)))
899 (if (/= tab-number (length table-widths))
900 (error "Wrong number of @tab's in a @multitable row")))
901 (goto-char (point-min))
902 ;; 2. Format each cell, and copy to a rectangle
903 ;; buffer looks like this: A1 @tab A2 @tab A3
904 ;; Cell #1: format up to @tab
905 ;; Cell #2: format up to @tab
906 ;; Cell #3: format up to eob
909 (setq end (save-excursion
910 (if (search-forward "@tab" nil 'move)
911 ;; Delete the @tab command, including the @-sign
914 (progn (forward-word -1) (1- (point)))))
916 ;; Set fill-column *wider* than needed to produce inter-column space
917 (setq fill-column (+ 1
918 texinfo-extra-inter-column-width
919 (nth table-column table-widths)))
920 (narrow-to-region start end)
921 ;; Remove whitespace before and after entry.
922 (skip-chars-forward " ")
923 (delete-region (point) (save-excursion (beginning-of-line) (point)))
924 (goto-char (point-max))
925 (skip-chars-backward " ")
926 (delete-region (point) (save-excursion (end-of-line) (point)))
927 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
928 ;; does not see an unterminated @multitable.
929 (let (texinfo-stack) ;; nil
930 (texinfo-format-scan))
931 (let (fill-prefix) ;; no fill prefix
932 (fill-region (point-min) (point-max)))
933 (setq table-entry-height
934 (max table-entry-height (count-lines (point-min) (point-max))))
935 ;; 3. Move point to end of bottom line, and pad that line to fill column.
936 (goto-char (point-min))
937 (forward-line (1- table-entry-height))
938 (let* ((beg (point)) ;; beginning of line
939 ;; add one more space for inter-column spacing
945 (current-column)))))) ;; end of existing line
947 (if (> needed-whitespace 0) needed-whitespace 1)
949 ;; now, put formatted cell into a rectangle
950 (set (intern (concat texinfo-multitable-rectangle-name
951 (int-to-string table-column)))
952 (extract-rectangle (point-min) (point)))
953 (delete-region (point-min) (point))
954 (goto-char (point-max))
955 (setq table-column (1+ table-column))
957 ;; 4. Add extra lines to rectangles so all are of same height
958 (let ((total-number-of-columns table-column)
961 (while (> table-column 0)
962 (let ((this-rectangle (int-to-string table-column)))
963 (while (< (length this-rectangle) table-entry-height)
964 (setq this-rectangle (append this-rectangle '("")))))
965 (setq table-column (1- table-column)))
966 ;; 5. Insert formatted rectangles in original buffer
967 (switch-to-buffer original-buffer)
968 (open-line table-entry-height)
969 (while (< column-number total-number-of-columns)
973 (concat texinfo-multitable-rectangle-name
974 (int-to-string column-number)))))
977 (setq column-number (1+ column-number))))
978 (kill-buffer texinfo-multitable-buffer-name)
979 (setq fill-column existing-fill-column)))
982 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
983 (let ((indexelts (symbol-value
984 (cdr (assoc (texinfo-parse-arg-discard)
985 texinfo-indexvar-alist))))
987 (insert "\n* Menu:\n\n")
988 (setq opoint (point))
989 (texinfo-print-index nil indexelts)
991 (if (memq system-type '(vax-vms windows-nt ms-dos))
992 (texinfo-sort-region opoint (point))
993 (shell-command-on-region opoint (point) "sort -fd" 1))))
996 ;; @copying ... @end copying
997 ;; that Emacs 21.4 and lesser and XEmacs don't support.
998 (if (fboundp 'texinfo-copying)
1000 (defvar texinfo-copying-text ""
1001 "Text of the copyright notice and copying permissions.")
1003 (defun texinfo-copying ()
1004 "Copy the copyright notice and copying permissions from the Texinfo file,
1005 as indicated by the @copying ... @end copying command;
1006 insert the text with the @insertcopying command."
1007 (let ((beg (progn (beginning-of-line) (point)))
1008 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
1009 (setq texinfo-copying-text
1010 (buffer-substring-no-properties
1011 (save-excursion (goto-char beg) (forward-line 1) (point))
1012 (save-excursion (goto-char end) (forward-line -1) (point))))
1013 (delete-region beg end)))
1015 (defun texinfo-insertcopying ()
1016 "Insert the copyright notice and copying permissions from the Texinfo file,
1017 which are indicated by the @copying ... @end copying command."
1018 (insert (concat "\n" texinfo-copying-text)))
1020 (defadvice texinfo-format-scan (before expand-@copying-section activate)
1021 "Extract @copying and replace @insertcopying with it."
1022 (goto-char (point-min))
1023 (when (search-forward "@copying" nil t)
1025 (while (search-forward "@insertcopying" nil t)
1026 (delete-region (match-beginning 0) (match-end 0))
1027 (texinfo-insertcopying))))
1031 (if (fboundp 'texinfo-format-comma)
1033 (put 'comma 'texinfo-format 'texinfo-format-comma)
1034 (defun texinfo-format-comma ()
1035 (texinfo-parse-arg-discard)
1037 (put-text-property (1- (point)) (point) 'ignore t))
1039 ;; Redefine this function so as to work for @comma
1040 (defun texinfo-format-parse-args ()
1041 (let ((start (1- (point)))
1044 (search-forward "{")
1046 (texinfo-format-expand-region
1048 (save-excursion (up-list 1) (1- (point)))))
1049 ;; The following does not handle cross references of the form:
1050 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1051 ;; re-search-forward finds the first right brace after the second
1053 (while (/= (preceding-char) ?\})
1054 (skip-chars-forward " \t\n")
1056 ;;; (re-search-forward "[},]")
1057 ;; Ignore commas that are derived from @comma{}.
1058 (while (and (re-search-forward "[},]" nil t)
1059 (get-text-property (match-beginning 0) 'ignore)))
1063 (skip-chars-backward " \t\n")
1067 (while (search-forward "\n" end t)
1068 (replace-match " "))))
1069 (push (if (> end beg) (buffer-substring-no-properties beg end))
1072 ;;(if (eolp) (forward-char 1))
1073 (setq texinfo-command-end (point))
1076 (provide 'ptexinfmt)
1078 ;;; ptexinfmt.el ends here