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 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
66 (defvar ptexinfmt-disable-broken-notice-flag t
67 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
68 This is last argument in `ptexinfmt-broken-facility'.")
70 (put 'ptexinfmt-broken-facility
'lisp-indent-function
'defun
)
71 (defmacro ptexinfmt-broken-facility
(facility docstring assertion
73 "Declare a symbol FACILITY is broken if ASSERTION is nil.
74 DOCSTRING will be printed if ASSERTION is nil and
75 `ptexinfmt-disable-broken-notice-flag' is nil."
76 `(let ((facility ',facility
)
77 (docstring ,docstring
)
78 (assertion (eval ',assertion
)))
79 (put facility
'broken
(not assertion
))
82 (put facility
'broken-docstring docstring
)
83 (if ptexinfmt-disable-broken-notice-flag
85 (message "BROKEN FACILITY DETECTED: %s" docstring
)))))
87 (put 'ptexinfmt-defun-if-broken
'lisp-indent-function
'defun
)
88 (defmacro ptexinfmt-defun-if-broken
(&rest args
)
89 "Redefine a function just like `defun' if it is considered broken."
90 (let ((name (list 'quote
(car args
))))
91 (setq args
(cdr args
))
94 (if (get ,name
'broken
)
96 (function (lambda ,@args
)))))))
98 (put 'ptexinfmt-defun-if-void
'lisp-indent-function
'defun
)
99 (defmacro ptexinfmt-defun-if-void
(&rest args
)
100 "Define a function just like `defun' unless it is already defined."
101 (let ((name (list 'quote
(car args
))))
102 (setq args
(cdr args
))
108 (function (lambda ,@args
)))))))
110 (put 'ptexinfmt-defvar-if-void
'lisp-indent-function
'defun
)
111 (defmacro ptexinfmt-defvar-if-void
(&rest args
)
112 "Define a variable just like `defvar' unless it is already defined."
113 (let ((name (car args
)))
114 (setq args
(cdr args
))
119 (defvar ,name
,@args
)))))
122 (ptexinfmt-broken-facility texinfo-format-printindex
123 "Can't sort on Mule for Windows."
124 (if (and (memq system-type
'(windows-nt ms-dos
))
125 ;;; I don't know version threshold.
126 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
127 (boundp 'MULE
) (not (featurep 'meadow
))) ; Mule for Windows
131 ;; @var{METASYNTACTIC-VARIABLE}
132 (ptexinfmt-broken-facility texinfo-format-var
133 "Don't perse @var argument."
136 (let (texinfo-enclosure-list texinfo-alias-list
)
138 (insert "@var{@asis{foo}}\n")
139 (texinfo-format-expand-region (point-min) (point-max))
143 ;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
144 ;; INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
145 (ptexinfmt-broken-facility texinfo-format-xref
146 "Can't format @xref, 1st argument is empty."
149 (let (texinfo-enclosure-list texinfo-alias-list
)
151 (insert "@xref{, xref, , file}\n")
152 (texinfo-format-expand-region (point-min) (point-max))
156 ;; @uref{URL[, TEXT][, REPLACEMENT]}
157 (ptexinfmt-broken-facility texinfo-format-uref
158 "Parse twice @uref argument."
161 (let (texinfo-enclosure-list texinfo-alias-list
)
163 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
164 (texinfo-format-expand-region (point-min) (point-max))
169 (ptexinfmt-broken-facility texinfo-multitable-widths
170 "`texinfo-multitable-widths' unsupport wide-char."
171 (if (fboundp 'texinfo-multitable-widths
)
173 (let ((str "\e$BI}9-J8;z\e(B"))
175 (insert (format " {%s}\n" str
))
176 (goto-char (point-min))
177 (if (= (car (texinfo-multitable-widths)) (length str
))
180 ;; function definition is void
183 (ptexinfmt-broken-facility texinfo-multitable-item
184 "`texinfo-multitable-item' unsupport wide-char."
185 (not (get 'texinfo-multitable-widths
'broken
)))
188 ;;; Hardcopy and HTML (discard)
190 (put 'documentlanguage
'texinfo-format
'texinfo-discard-line-with-args
)
191 (put 'documentencoding
'texinfo-format
'texinfo-discard-line-with-args
)
192 (put 'documentdescription
'texinfo-format
'texinfo-discard-line-with-args
)
195 (put 'smallbook
'texinfo-format
'texinfo-discard-line
)
196 (put 'letterpaper
'texinfo-format
'texinfo-discard-line
)
197 (put 'afourpaper
'texinfo-format
'texinfo-discard-line
)
198 (put 'afourlatex
'texinfo-format
'texinfo-discard-line
)
199 (put 'afourwide
'texinfo-format
'texinfo-discard-line
)
200 (put 'afivepaper
'texinfo-format
'texinfo-discard-line
)
201 (put 'pagesizes
'texinfo-format
'texinfo-discard-line-with-args
)
202 (put 'fonttextsize
'texinfo-format
'texinfo-discard-line-with-args
)
205 (put 'setchapternewpage
'texinfo-format
'texinfo-discard-line-with-args
)
206 (put 'kbdinputstyle
'texinfo-format
'texinfo-discard-line-with-args
)
209 (put 'setcontentsaftertitlepage
'texinfo-format
'texinfo-discard-line
)
210 (put 'setshortcontentsaftertitlepage
'texinfo-format
'texinfo-discard-line
)
211 (put 'novalidate
'texinfo-format
'texinfo-discard-line-with-args
)
212 (put 'frenchspacing
'texinfo-format
'texinfo-discard-line-with-args
)
215 (put 'headings
'texinfo-format
'texinfo-discard-line-with-args
)
216 (put 'evenfooting
'texinfo-format
'texinfo-discard-line-with-args
)
217 (put 'evenheading
'texinfo-format
'texinfo-discard-line-with-args
)
218 (put 'oddfooting
'texinfo-format
'texinfo-discard-line-with-args
)
219 (put 'oddheading
'texinfo-format
'texinfo-discard-line-with-args
)
220 (put 'everyfooting
'texinfo-format
'texinfo-discard-line-with-args
)
221 (put 'everyheading
'texinfo-format
'texinfo-discard-line-with-args
)
224 (put 'page
'texinfo-format
'texinfo-discard-line
)
225 (put 'hyphenation
'texinfo-format
'texinfo-discard-command-and-arg
)
227 ;; @slanted{TEXT} (makeinfo 4.8 or later)
228 (put 'slanted
'texinfo-format
'texinfo-format-noop
)
230 ;; @sansserif{TEXT} (makeinfo 4.8 or later)
231 (put 'sansserif
'texinfo-format
'texinfo-format-noop
)
233 ;; @tie{} (makeinfo 4.3 or later)
234 (put 'tie
'texinfo-format
'texinfo-format-tie
)
235 (ptexinfmt-defun-if-void texinfo-format-tie
()
236 (texinfo-parse-arg-discard)
241 ;; @direcategory DIRPART
242 (put 'dircategory
'texinfo-format
'texinfo-format-dircategory
)
243 (ptexinfmt-defun-if-void texinfo-format-dircategory
()
244 (let ((str (texinfo-parse-arg-discard)))
245 (delete-region (point)
247 (skip-chars-forward " ")
249 (insert "INFO-DIR-SECTION " str
"\n")))
251 ;; @direntry ... @end direntry
252 (put 'direntry
'texinfo-format
'texinfo-format-direntry
)
253 (ptexinfmt-defun-if-void texinfo-format-direntry
()
254 (texinfo-push-stack 'direntry nil
)
255 (texinfo-discard-line)
256 (insert "START-INFO-DIR-ENTRY\n"))
258 (put 'direntry
'texinfo-end
'texinfo-end-direntry
)
259 (ptexinfmt-defun-if-void texinfo-end-direntry
()
260 (texinfo-discard-command)
261 (insert "END-INFO-DIR-ENTRY\n\n")
262 (texinfo-pop-stack 'direntry
))
266 ;; @detailmenu ... @end detailmenu
267 (put 'detailmenu
'texinfo-format
'texinfo-discard-line
)
268 (put 'detailmenu
'texinfo-end
'texinfo-discard-command
)
270 ;; @smalldisplay ... @end smalldisplay
271 (put 'smalldisplay
'texinfo-format
'texinfo-format-example
)
272 (put 'smalldisplay
'texinfo-end
'texinfo-end-example
)
274 ;; @smallformat ... @end smallformat
275 (put 'smallformat
'texinfo-format
'texinfo-format-flushleft
)
276 (put 'smallformat
'texinfo-end
'texinfo-end-flushleft
)
278 ;; @cartouche ... @end cartouche
279 (put 'cartouche
'texinfo-format
'texinfo-discard-line
)
280 (put 'cartouche
'texinfo-end
'texinfo-discard-command
)
284 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
285 (put 'ifnottex
'texinfo-format
'texinfo-discard-line
)
286 (put 'ifnottex
'texinfo-end
'texinfo-discard-command
)
288 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
289 (put 'ifnothtml
'texinfo-format
'texinfo-discard-line
)
290 (put 'ifnothtml
'texinfo-end
'texinfo-discard-command
)
292 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
293 (put 'ifnotplaintext
'texinfo-format
'texinfo-discard-line
)
294 (put 'ifnotplaintext
'texinfo-end
'texinfo-discard-command
)
296 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
297 (put 'ifnotdocbook
'texinfo-format
'texinfo-discard-line
)
298 (put 'ifnotdocbook
'texinfo-end
'texinfo-discard-command
)
300 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
301 (put 'ifnotinfo
'texinfo-format
'texinfo-format-ifnotinfo
)
302 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo
()
303 (delete-region texinfo-command-start
304 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
307 ;; @html ... @end html (makeinfo 3.11 or later)
308 (put 'html
'texinfo-format
'texinfo-format-html
)
309 (ptexinfmt-defun-if-void texinfo-format-html
()
310 (delete-region texinfo-command-start
311 (progn (re-search-forward "@end html[ \t]*\n")
314 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
315 (put 'docbook
'texinfo-format
'texinfo-format-docbook
)
316 (ptexinfmt-defun-if-void texinfo-format-docbook
()
317 (delete-region texinfo-command-start
318 (progn (re-search-forward "@end docbook[ \t]*\n")
321 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
322 (put 'ifhtml
'texinfo-format
'texinfo-format-ifhtml
)
323 (defun texinfo-format-ifhtml ()
324 (delete-region texinfo-command-start
325 (progn (re-search-forward "@end ifhtml[ \t]*\n")
328 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
329 (put 'ifplaintext
'texinfo-format
'texinfo-format-ifplaintext
)
330 (ptexinfmt-defun-if-void texinfo-format-ifplaintext
()
331 (delete-region texinfo-command-start
332 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
335 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
336 (put 'ifdocbook
'texinfo-format
'texinfo-format-ifdocbook
)
337 (ptexinfmt-defun-if-void texinfo-format-ifdocbook
()
338 (delete-region texinfo-command-start
339 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
344 ;; @env{ENVIRONMENT-VARIABLE}
345 (put 'env
'texinfo-format
'texinfo-format-code
)
347 ;; @command{COMMAND-NAME}
348 (put 'command
'texinfo-format
'texinfo-format-code
)
350 ;; @indicateurl{INDICATEURL}
351 (put 'indicateurl
'texinfo-format
'texinfo-format-code
)
353 ;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
354 (put 'url
'texinfo-format
'texinfo-format-uref
) ; Texinfo 4.7
357 (put 'acronym
'texinfo-format
'texinfo-format-var
)
359 ;; @var{METASYNTACTIC-VARIABLE}
360 (ptexinfmt-defun-if-broken texinfo-format-var
()
361 (let ((arg (texinfo-parse-expanded-arg)))
362 (texinfo-discard-command)
363 (insert (upcase arg
))))
366 (put 'key
'texinfo-format
'texinfo-format-key
)
367 (ptexinfmt-defun-if-void texinfo-format-key
()
368 (insert (texinfo-parse-arg-discard))
369 (goto-char texinfo-command-start
))
371 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
372 (put 'email
'texinfo-format
'texinfo-format-email
)
373 (ptexinfmt-defun-if-void texinfo-format-email
()
374 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
375 Insert < ... > around EMAIL-ADDRESS."
376 (let ((args (texinfo-format-parse-args)))
377 (texinfo-discard-command)
380 (insert (nth 1 args
) " <" (nth 0 args
) ">")
381 (insert "<" (nth 0 args
) ">"))))
383 ;; @option{OPTION-NAME}
384 (put 'option
'texinfo-format
'texinfo-format-option
)
385 (ptexinfmt-defun-if-void texinfo-format-option
()
386 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
387 ;; `looking-at-backward' not available in v. 18.57, 20.2
388 ;; searched-for character is a control-H
389 (if (not (search-backward "\010"
390 (save-excursion (beginning-of-line) (point))
392 (insert "`" (texinfo-parse-arg-discard) "'")
393 (insert (texinfo-parse-arg-discard)))
394 (goto-char texinfo-command-start
))
396 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
397 (put 'verb
'texinfo-format
'texinfo-format-verb
)
398 (ptexinfmt-defun-if-void texinfo-format-verb
()
399 "Format text between non-quoted unique delimiter characters verbatim.
400 Enclose the verbatim text, including the delimiters, in braces. Print
401 text exactly as written (but not the delimiters) in a fixed-width.
403 For example, @verb\{|@|\} results in @ and
404 @verb\{+@'e?`!`+} results in @'e?`!`."
406 (let ((delimiter (buffer-substring-no-properties
407 (1+ texinfo-command-end
) (+ 2 texinfo-command-end
))))
408 (unless (looking-at "{")
409 (error "Not found: @verb start brace"))
410 (delete-region texinfo-command-start
(+ 2 texinfo-command-end
))
411 (search-forward delimiter
))
412 (delete-backward-char 1)
413 (unless (looking-at "}")
414 (error "Not found: @verb end brace"))
419 (put 'LaTeX
'texinfo-format
'texinfo-format-LaTeX
)
420 (ptexinfmt-defun-if-void texinfo-format-LaTeX
()
421 (texinfo-parse-arg-discard)
424 ;; @registeredsymbol{}
425 (put 'registeredsymbol
'texinfo-format
'texinfo-format-registeredsymbol
)
426 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol
()
427 (texinfo-parse-arg-discard)
430 ;;; Accents and Special characters
432 (put 'euro
'texinfo-format
'texinfo-format-euro
)
433 (ptexinfmt-defun-if-void texinfo-format-euro
()
434 (texinfo-parse-arg-discard)
437 ;; @pounds{} ==> # Pounds Sterling
438 (put 'pounds
'texinfo-format
'texinfo-format-pounds
)
439 (ptexinfmt-defun-if-void texinfo-format-pounds
()
440 (texinfo-parse-arg-discard)
443 ;; @ordf{} ==> a Spanish feminine
444 (put 'ordf
'texinfo-format
'texinfo-format-ordf
)
445 (ptexinfmt-defun-if-void texinfo-format-ordf
()
446 (texinfo-parse-arg-discard)
449 ;; @ordm{} ==> o Spanish masculine
450 (put 'ordm
'texinfo-format
'texinfo-format-ordm
)
451 (ptexinfmt-defun-if-void texinfo-format-ordm
()
452 (texinfo-parse-arg-discard)
455 ;; @OE{} ==> OE French-OE-ligature
456 (put 'OE
'texinfo-format
'texinfo-format-French-OE-ligature
)
457 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature
()
458 (insert "OE" (texinfo-parse-arg-discard))
459 (goto-char texinfo-command-start
))
462 (put 'oe
'texinfo-format
'texinfo-format-French-oe-ligature
)
463 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature
() ; lower case
464 (insert "oe" (texinfo-parse-arg-discard))
465 (goto-char texinfo-command-start
))
467 ;; @AA{} ==> AA Scandinavian-A-with-circle
468 (put 'AA
'texinfo-format
'texinfo-format-Scandinavian-A-with-circle
)
469 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle
()
470 (insert "AA" (texinfo-parse-arg-discard))
471 (goto-char texinfo-command-start
))
474 (put 'aa
'texinfo-format
'texinfo-format-Scandinavian-a-with-circle
)
475 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle
() ; lower case
476 (insert "aa" (texinfo-parse-arg-discard))
477 (goto-char texinfo-command-start
))
479 ;; @AE{} ==> AE Latin-Scandinavian-AE
480 (put 'AE
'texinfo-format
'texinfo-format-Latin-Scandinavian-AE
)
481 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE
()
482 (insert "AE" (texinfo-parse-arg-discard))
483 (goto-char texinfo-command-start
))
486 (put 'ae
'texinfo-format
'texinfo-format-Latin-Scandinavian-ae
)
487 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae
() ; lower case
488 (insert "ae" (texinfo-parse-arg-discard))
489 (goto-char texinfo-command-start
))
491 ;; @ss{} ==> ss German-sharp-S
492 (put 'ss
'texinfo-format
'texinfo-format-German-sharp-S
)
493 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S
()
494 (insert "ss" (texinfo-parse-arg-discard))
495 (goto-char texinfo-command-start
))
497 ;; @questiondown{} ==> ? upside-down-question-mark
498 (put 'questiondown
'texinfo-format
'texinfo-format-upside-down-question-mark
)
499 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark
()
500 (insert "?" (texinfo-parse-arg-discard))
501 (goto-char texinfo-command-start
))
503 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
504 (put 'exclamdown
'texinfo-format
'texinfo-format-upside-down-exclamation-mark
)
505 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark
()
506 (insert "!" (texinfo-parse-arg-discard))
507 (goto-char texinfo-command-start
))
509 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
510 (put 'L
'texinfo-format
'texinfo-format-Polish-suppressed-L
)
511 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L
()
512 (insert (texinfo-parse-arg-discard) "/L")
513 (goto-char texinfo-command-start
))
515 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
516 (put 'l
'texinfo-format
'texinfo-format-Polish-suppressed-l-lower-case
)
517 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case
()
518 (insert (texinfo-parse-arg-discard) "/l")
519 (goto-char texinfo-command-start
))
521 ;; @O{} ==> O/ Scandinavian O-with-slash
522 (put 'O
'texinfo-format
'texinfo-format-Scandinavian-O-with-slash
)
523 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash
()
524 (insert (texinfo-parse-arg-discard) "O/")
525 (goto-char texinfo-command-start
))
527 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
528 (put 'o
'texinfo-format
'texinfo-format-Scandinavian-o-with-slash-lower-case
)
529 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case
()
530 (insert (texinfo-parse-arg-discard) "o/")
531 (goto-char texinfo-command-start
))
533 ;; @,{c} ==> c, cedilla accent
534 (put '\
, 'texinfo-format
'texinfo-format-cedilla-accent
)
535 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent
()
536 (insert (texinfo-parse-arg-discard) ",")
537 (goto-char texinfo-command-start
))
540 ;; @dotaccent{o} ==> .o overdot-accent
541 (put 'dotaccent
'texinfo-format
'texinfo-format-overdot-accent
)
542 (ptexinfmt-defun-if-void texinfo-format-overdot-accent
()
543 (insert "." (texinfo-parse-arg-discard))
544 (goto-char texinfo-command-start
))
546 ;; @ubaraccent{o} ==> _o underbar-accent
547 (put 'ubaraccent
'texinfo-format
'texinfo-format-underbar-accent
)
548 (ptexinfmt-defun-if-void texinfo-format-underbar-accent
()
549 (insert "_" (texinfo-parse-arg-discard))
550 (goto-char texinfo-command-start
))
552 ;; @udotaccent{o} ==> o-. underdot-accent
553 (put 'udotaccent
'texinfo-format
'texinfo-format-underdot-accent
)
554 (ptexinfmt-defun-if-void texinfo-format-underdot-accent
()
555 (insert (texinfo-parse-arg-discard) "-.")
556 (goto-char texinfo-command-start
))
558 ;; @H{o} ==> ""o long Hungarian umlaut
559 (put 'H
'texinfo-format
'texinfo-format-long-Hungarian-umlaut
)
560 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut
()
561 (insert "\"\"" (texinfo-parse-arg-discard))
562 (goto-char texinfo-command-start
))
564 ;; @ringaccent{o} ==> *o ring accent
565 (put 'ringaccent
'texinfo-format
'texinfo-format-ring-accent
)
566 (ptexinfmt-defun-if-void texinfo-format-ring-accent
()
567 (insert "*" (texinfo-parse-arg-discard))
568 (goto-char texinfo-command-start
))
570 ;; @tieaccent{oo} ==> [oo tie after accent
571 (put 'tieaccent
'texinfo-format
'texinfo-format-tie-after-accent
)
572 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent
()
573 (insert "[" (texinfo-parse-arg-discard))
574 (goto-char texinfo-command-start
))
576 ;; @u{o} ==> (o breve accent
577 (put 'u
'texinfo-format
'texinfo-format-breve-accent
)
578 (ptexinfmt-defun-if-void texinfo-format-breve-accent
()
579 (insert "(" (texinfo-parse-arg-discard))
580 (goto-char texinfo-command-start
))
582 ;; @v{o} ==> <o hacek accent
583 (put 'v
'texinfo-format
'texinfo-format-hacek-accent
)
584 (ptexinfmt-defun-if-void texinfo-format-hacek-accent
()
585 (insert "<" (texinfo-parse-arg-discard))
586 (goto-char texinfo-command-start
))
588 ;; @dotless{i} ==> i dotless i and dotless j
589 (put 'dotless
'texinfo-format
'texinfo-format-dotless
)
590 (ptexinfmt-defun-if-void texinfo-format-dotless
()
591 (insert (texinfo-parse-arg-discard))
592 (goto-char texinfo-command-start
))
595 (put '\.
'texinfo-format
'texinfo-format-\.
)
596 (ptexinfmt-defun-if-void texinfo-format-\.
()
597 (texinfo-discard-command)
601 (put '\
: 'texinfo-format
'texinfo-format-\
:)
602 (ptexinfmt-defun-if-void texinfo-format-\
: ()
603 (texinfo-discard-command))
606 (put '\-
'texinfo-format
'texinfo-format-soft-hyphen
)
607 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen
()
608 (texinfo-discard-command))
611 (put '\
/ 'texinfo-format
'texinfo-format-\
/)
612 (ptexinfmt-defun-if-void texinfo-format-\
/ ()
613 (texinfo-discard-command))
616 (put 'textdegree
'texinfo-format
'texinfo-format-textdegree
)
617 (ptexinfmt-defun-if-void texinfo-format-textdegree
()
618 (insert "o" (texinfo-parse-arg-discard))
619 (goto-char texinfo-command-start
))
622 (put 'geq
'texinfo-format
'texinfo-format-geq
)
623 (ptexinfmt-defun-if-void texinfo-format-geq
()
624 (insert ">=" (texinfo-parse-arg-discard))
625 (goto-char texinfo-command-start
))
628 (put 'leq
'texinfo-format
'texinfo-format-leq
)
629 (ptexinfmt-defun-if-void texinfo-format-leq
()
630 (insert "<=" (texinfo-parse-arg-discard))
631 (goto-char texinfo-command-start
))
635 ;; @ref{NODE-NAME, ...}
636 ;; @xref{NODE-NAME, ...}
637 (put 'ref
'texinfo-format
'texinfo-format-xref
)
639 (ptexinfmt-defun-if-broken texinfo-format-xref
()
640 (let ((args (texinfo-format-parse-args)))
641 (texinfo-discard-command)
643 (let ((fname (or (nth 1 args
) (nth 2 args
))))
644 (if (null (or fname
(nth 3 args
)))
645 (insert (nth 0 args
) "::")
646 (insert (or fname
(nth 0 args
)) ": ")
648 (insert "(" (nth 3 args
) ")"))
649 (unless (null (nth 0 args
))
650 (insert (nth 0 args
)))))))
652 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
653 (put 'uref
'texinfo-format
'texinfo-format-uref
)
654 (ptexinfmt-defun-if-broken texinfo-format-uref
()
655 "Format URL and optional URL-TITLE.
656 Insert ` ... ' around URL if no URL-TITLE argument;
657 otherwise, insert URL-TITLE followed by URL in parentheses."
658 (let ((args (texinfo-format-parse-args)))
659 (texinfo-discard-command)
662 (insert (nth 1 args
) " (" (nth 0 args
) ")")
663 (insert "`" (nth 0 args
) "'"))))
665 ;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
666 (put 'inforef
'texinfo-format
'texinfo-format-inforef
)
667 (ptexinfmt-defun-if-void texinfo-format-inforef
()
668 (let ((args (texinfo-format-parse-args)))
669 (texinfo-discard-command)
671 (insert "*Note " (nth 1 args
) ": (" (nth 2 args
) ")" (car args
))
672 (insert "*Note " "(" (nth 2 args
) ")" (car args
) "::"))))
677 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
678 ;; - Info-tagify suport @anthor-*-refill.
679 ;; - info.el support Ref in Tag table.
680 (unless (get 'anchor
'texinfo-format
)
681 (put 'anchor
'texinfo-format
'texinfo-discard-command-and-arg
))
685 ;;; New command definition
686 ;; @alias NEW=EXISTING
687 (put 'alias
'texinfo-format
'texinfo-alias
)
688 (ptexinfmt-defun-if-void texinfo-alias
()
689 (let ((start (1- (point)))
691 (skip-chars-forward " ")
692 (save-excursion (end-of-line) (setq texinfo-command-end
(point)))
693 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
694 (error "Invalid alias command")
695 (setq texinfo-alias-list
698 (buffer-substring (match-beginning 1) (match-end 1))
699 (buffer-substring (match-beginning 2) (match-end 2)))
701 (texinfo-discard-command))))
705 ;; @exampleindent INDENT (makeinfo 4.0 or later)
707 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
708 ;; INDENT: asis, 0, n
710 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
711 ;; WORD: none, insert
716 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
717 (put 'image
'texinfo-format
'texinfo-format-image
)
718 (ptexinfmt-defun-if-void texinfo-format-image
()
719 ;; I don't know makeinfo parse FILENAME.
720 (let ((args (texinfo-format-parse-args))
722 (when (null (nth 0 args
))
723 (error "Invalid image command"))
724 (texinfo-discard-command)
725 ;; makeinfo uses FILENAME.txt
726 (setq filename
(format "%s.txt" (nth 0 args
)))
727 (message "Reading included file: %s" filename
)
728 ;; verbatim for Info output
729 (goto-char (+ (point) (cadr (insert-file-contents filename
))))
730 (message "Reading included file: %s...done" filename
)))
734 ;;; @multitable ... @end multitable
735 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width
0
736 "*Number of extra spaces between entries (columns) in @multitable.")
738 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
739 "*multitable-temporary-buffer*")
740 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
741 "texinfo-multitable-temp-")
743 ;; These commands are defined in texinfo.tex for printed output.
744 (put 'multitableparskip
'texinfo-format
'texinfo-discard-line-with-args
)
745 (put 'multitableparindent
'texinfo-format
'texinfo-discard-line-with-args
)
746 (put 'multitablecolmargin
'texinfo-format
'texinfo-discard-line-with-args
)
747 (put 'multitablelinespace
'texinfo-format
'texinfo-discard-line-with-args
)
749 (put 'multitable
'texinfo-format
'texinfo-multitable
)
751 (ptexinfmt-defun-if-void texinfo-multitable
()
752 "Produce multi-column tables."
754 ;; This function pushes information onto the `texinfo-stack'.
755 ;; A stack element consists of:
756 ;; - type-of-command, i.e., multitable
757 ;; - the information about column widths, and
758 ;; - the position of texinfo-command-start.
759 ;; e.g., ('multitable (1 2 3 4) 123)
760 ;; The command line is then deleted.
763 ;; push width information on stack
764 (texinfo-multitable-widths))
765 (texinfo-discard-line-with-args))
767 (put 'multitable
'texinfo-end
'texinfo-end-multitable
)
768 (ptexinfmt-defun-if-void texinfo-end-multitable
()
769 "Discard the @end multitable line and pop the stack of multitable."
770 (texinfo-discard-command)
771 (texinfo-pop-stack 'multitable
))
773 (ptexinfmt-defun-if-broken texinfo-multitable-widths
()
774 "Return list of widths of each column in a multi-column table."
775 (let (texinfo-multitable-width-list)
777 ;; @multitable @columnfractions .25 .3 .45
780 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
781 ;; Place point before first argument
782 (skip-chars-forward " \t")
784 ;; Check for common misspelling
785 ((looking-at "@columnfraction ")
786 (error "In @multitable, @columnfractions misspelled"))
787 ;; Case 1: @columnfractions .25 .3 .45
788 ((looking-at "@columnfractions")
791 (setq texinfo-multitable-width-list
795 (* fill-column
(read (get-buffer (current-buffer))))))
796 texinfo-multitable-width-list
))))
798 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
800 (let ((start-of-templates (point)))
802 (skip-chars-forward " \t")
803 (let* ((start-of-template (1+ (point)))
805 ;; forward-sexp works with braces in Texinfo mode
806 (progn (forward-sexp 1) (1- (point)))))
807 (setq texinfo-multitable-width-list
809 (goto-char end-of-template
)
812 (goto-char start-of-template
)
814 texinfo-multitable-width-list
))
815 ;; Remove carriage return from within a template, if any.
816 ;; This helps those those who want to use more than
817 ;; one line's worth of words in @multitable line.
818 (narrow-to-region start-of-template end-of-template
)
819 (goto-char (point-min))
820 (while (search-forward "\n" nil t
)
822 (goto-char (point-max))
829 You probably need to specify column widths for @multitable correctly")))
830 ;; Check whether columns fit on page.
831 (let ((desired-columns
833 ;; between column spaces
834 (length texinfo-multitable-width-list
)
835 ;; additional between column spaces, if any
836 texinfo-extra-inter-column-width
837 ;; sum of spaces for each entry
838 (apply '+ texinfo-multitable-width-list
))))
839 (if (> desired-columns fill-column
)
841 Multi-column table width, %d chars, is greater than page width, %d chars."
842 desired-columns fill-column
))))
843 texinfo-multitable-width-list
))
845 ;; @item A1 @tab A2 @tab A3
846 (ptexinfmt-defun-if-void texinfo-multitable-extract-row
()
847 "Return multitable row, as a string.
848 End of row is beginning of next @item or beginning of @end.
849 Cells within rows are separated by @tab."
850 (skip-chars-forward " \t")
851 (let* ((start (point))
853 (re-search-forward "@item\\|@end")
854 (match-beginning 0)))
855 (row (progn (goto-char end
)
856 (skip-chars-backward " ")
857 ;; remove whitespace at end of argument
858 (delete-region (point) end
)
859 (buffer-substring start
(point)))))
860 (delete-region texinfo-command-start end
)
863 (put 'multitable
'texinfo-item
'texinfo-multitable-item
)
864 (ptexinfmt-defun-if-void texinfo-multitable-item
()
865 "Format a row within a multicolumn table.
866 Cells in row are separated by @tab.
867 Widths of cells are specified by the arguments in the @multitable line.
868 All cells are made to be the same height.
869 This command is executed when texinfmt sees @item inside @multitable."
870 (let ((original-buffer (current-buffer))
871 (table-widths (reverse (car (cdr (car texinfo-stack
)))))
872 (existing-fill-column fill-column
)
876 (table-entry-height 0)
877 ;; unformatted row looks like: A1 @tab A2 @tab A3
878 ;; extract-row command deletes the source line in the table.
879 (unformated-row (texinfo-multitable-extract-row)))
880 ;; Use a temporary buffer
881 (set-buffer (get-buffer-create texinfo-multitable-buffer-name
))
882 (delete-region (point-min) (point-max))
883 (insert unformated-row
)
884 (goto-char (point-min))
885 ;; 1. Check for correct number of @tab in line.
886 (let ((tab-number 1)) ;; one @tab between two columns
887 (while (search-forward "@tab" nil t
)
888 (setq tab-number
(1+ tab-number
)))
889 (if (/= tab-number
(length table-widths
))
890 (error "Wrong number of @tab's in a @multitable row")))
891 (goto-char (point-min))
892 ;; 2. Format each cell, and copy to a rectangle
893 ;; buffer looks like this: A1 @tab A2 @tab A3
894 ;; Cell #1: format up to @tab
895 ;; Cell #2: format up to @tab
896 ;; Cell #3: format up to eob
899 (setq end
(save-excursion
900 (if (search-forward "@tab" nil
'move
)
901 ;; Delete the @tab command, including the @-sign
904 (progn (forward-word -
1) (1- (point)))))
906 ;; Set fill-column *wider* than needed to produce inter-column space
907 (setq fill-column
(+ 1
908 texinfo-extra-inter-column-width
909 (nth table-column table-widths
)))
910 (narrow-to-region start end
)
911 ;; Remove whitespace before and after entry.
912 (skip-chars-forward " ")
913 (delete-region (point) (save-excursion (beginning-of-line) (point)))
914 (goto-char (point-max))
915 (skip-chars-backward " ")
916 (delete-region (point) (save-excursion (end-of-line) (point)))
917 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
918 ;; does not see an unterminated @multitable.
919 (let (texinfo-stack) ;; nil
920 (texinfo-format-scan))
921 (let (fill-prefix) ;; no fill prefix
922 (fill-region (point-min) (point-max)))
923 (setq table-entry-height
924 (max table-entry-height
(count-lines (point-min) (point-max))))
925 ;; 3. Move point to end of bottom line, and pad that line to fill column.
926 (goto-char (point-min))
927 (forward-line (1- table-entry-height
))
928 (let* ((beg (point)) ;; beginning of line
929 ;; add one more space for inter-column spacing
935 (current-column)))))) ;; end of existing line
937 (if (> needed-whitespace
0) needed-whitespace
1)
939 ;; now, put formatted cell into a rectangle
940 (set (intern (concat texinfo-multitable-rectangle-name
941 (int-to-string table-column
)))
942 (extract-rectangle (point-min) (point)))
943 (delete-region (point-min) (point))
944 (goto-char (point-max))
945 (setq table-column
(1+ table-column
))
947 ;; 4. Add extra lines to rectangles so all are of same height
948 (let ((total-number-of-columns table-column
)
951 (while (> table-column
0)
952 (let ((this-rectangle (int-to-string table-column
)))
953 (while (< (length this-rectangle
) table-entry-height
)
954 (setq this-rectangle
(append this-rectangle
'("")))))
955 (setq table-column
(1- table-column
)))
956 ;; 5. Insert formatted rectangles in original buffer
957 (switch-to-buffer original-buffer
)
958 (open-line table-entry-height
)
959 (while (< column-number total-number-of-columns
)
963 (concat texinfo-multitable-rectangle-name
964 (int-to-string column-number
)))))
967 (setq column-number
(1+ column-number
))))
968 (kill-buffer texinfo-multitable-buffer-name
)
969 (setq fill-column existing-fill-column
)))
972 (ptexinfmt-defun-if-broken texinfo-format-printindex
()
973 (let ((indexelts (symbol-value
974 (cdr (assoc (texinfo-parse-arg-discard)
975 texinfo-indexvar-alist
))))
977 (insert "\n* Menu:\n\n")
978 (setq opoint
(point))
979 (texinfo-print-index nil indexelts
)
981 (if (memq system-type
'(vax-vms windows-nt ms-dos
))
982 (texinfo-sort-region opoint
(point))
983 (shell-command-on-region opoint
(point) "sort -fd" 1))))
986 ;; @copying ... @end copying
987 ;; that Emacs 21.4 and lesser and XEmacs don't support.
988 (if (fboundp 'texinfo-copying
)
990 (defvar texinfo-copying-text
""
991 "Text of the copyright notice and copying permissions.")
993 (defun texinfo-copying ()
994 "Copy the copyright notice and copying permissions from the Texinfo file,
995 as indicated by the @copying ... @end copying command;
996 insert the text with the @insertcopying command."
997 (let ((beg (progn (beginning-of-line) (point)))
998 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
999 (setq texinfo-copying-text
1000 (buffer-substring-no-properties
1001 (save-excursion (goto-char beg
) (forward-line 1) (point))
1002 (save-excursion (goto-char end
) (forward-line -
1) (point))))
1003 (delete-region beg end
)))
1005 (defun texinfo-insertcopying ()
1006 "Insert the copyright notice and copying permissions from the Texinfo file,
1007 which are indicated by the @copying ... @end copying command."
1008 (insert (concat "\n" texinfo-copying-text
)))
1010 (defadvice texinfo-format-scan
(before expand-
@copying-section activate
)
1011 "Extract @copying and replace @insertcopying with it."
1012 (goto-char (point-min))
1013 (when (search-forward "@copying" nil t
)
1015 (while (search-forward "@insertcopying" nil t
)
1016 (delete-region (match-beginning 0) (match-end 0))
1017 (texinfo-insertcopying))))
1019 (provide 'ptexinfmt
)
1021 ;;; ptexinfmt.el ends here