| 1 |
;;; ptexinfmt.el -- portable Texinfo formatter. |
| 2 |
|
| 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 <[email protected]> |
| 6 |
;; Copyright (C) 2000, 2001, 2002 TAKAHASHI Kaoru <[email protected]> |
| 7 |
|
| 8 |
;; Author: TAKAHASHI Kaoru <[email protected]> |
| 9 |
;; Yoshiki Hayashi <[email protected]> |
| 10 |
;; Katsumi Yamaoka <[email protected]> |
| 11 |
;; Maintainer: TAKAHASHI Kaoru <[email protected]> |
| 12 |
;; Created: 7 Jul 2000 |
| 13 |
;; Keywords: maint, tex, docs, emulation, compatibility |
| 14 |
|
| 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 3 of |
| 18 |
;; the License, or (at your option) any later version. |
| 19 |
|
| 20 |
;; This program is distributed in the hope that it will be |
| 21 |
;; useful, but WITHOUT ANY WARRANTY; without even the implied |
| 22 |
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 23 |
;; PURPOSE. See the GNU General Public License for more details. |
| 24 |
|
| 25 |
;; You should have received a copy of the GNU General Public License |
| 26 |
;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 |
|
| 28 |
;;; Commentary: |
| 29 |
|
| 30 |
;; Original code: Yoshiki Hayashi <[email protected]> |
| 31 |
;; makeinfo.el (gnujdoc project) |
| 32 |
|
| 33 |
;; Support texinfmt.el 2.32 or later. |
| 34 |
|
| 35 |
;; Modified by Yamaoka not to use APEL functions. |
| 36 |
|
| 37 |
;; Unimplemented command: |
| 38 |
;; @abbr |
| 39 |
;; @float, @caption, @shortcaption, @listoffloats |
| 40 |
;; @deftypecv[x] |
| 41 |
;; @headitem |
| 42 |
;; @comma{} |
| 43 |
;; @quotation (optional arguments) |
| 44 |
;; @acronym (optional argument) |
| 45 |
;; @dofirstparagraphindent |
| 46 |
;; @indent |
| 47 |
;; @verbatiminclude |
| 48 |
;; @\ |
| 49 |
;; @definfoenclose |
| 50 |
;; @deftypeivar |
| 51 |
;; @deftypeop |
| 52 |
;; @allowcodebreaks |
| 53 |
|
| 54 |
;;; Code: |
| 55 |
|
| 56 |
(require 'backquote) |
| 57 |
(require 'texinfmt) |
| 58 |
|
| 59 |
;;; Broken |
| 60 |
(defvar ptexinfmt-disable-broken-notice-flag t |
| 61 |
"If non-nil disable notice, when call `ptexinfmt-broken-facility'. |
| 62 |
This is last argument in `ptexinfmt-broken-facility'.") |
| 63 |
|
| 64 |
(put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun) |
| 65 |
(defmacro ptexinfmt-broken-facility (facility docstring assertion |
| 66 |
&optional dummy) |
| 67 |
"Declare a symbol FACILITY is broken if ASSERTION is nil. |
| 68 |
DOCSTRING will be printed if ASSERTION is nil and |
| 69 |
`ptexinfmt-disable-broken-notice-flag' is nil." |
| 70 |
`(let ((facility ',facility) |
| 71 |
(docstring ,docstring) |
| 72 |
(assertion (eval ',assertion))) |
| 73 |
(put facility 'broken (not assertion)) |
| 74 |
(if assertion |
| 75 |
nil |
| 76 |
(put facility 'broken-docstring docstring) |
| 77 |
(if ptexinfmt-disable-broken-notice-flag |
| 78 |
nil |
| 79 |
(message "BROKEN FACILITY DETECTED: %s" docstring))))) |
| 80 |
|
| 81 |
(put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun) |
| 82 |
(defmacro ptexinfmt-defun-if-broken (&rest args) |
| 83 |
"Redefine a function just like `defun' if it is considered broken." |
| 84 |
(let ((name (list 'quote (car args)))) |
| 85 |
(setq args (cdr args)) |
| 86 |
`(prog1 |
| 87 |
,name |
| 88 |
(if (get ,name 'broken) |
| 89 |
(defalias ,name |
| 90 |
(function (lambda ,@args))))))) |
| 91 |
|
| 92 |
(put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun) |
| 93 |
(defmacro ptexinfmt-defun-if-void (&rest args) |
| 94 |
"Define a function just like `defun' unless it is already defined." |
| 95 |
(let ((name (list 'quote (car args)))) |
| 96 |
(setq args (cdr args)) |
| 97 |
`(prog1 |
| 98 |
,name |
| 99 |
(if (fboundp ,name) |
| 100 |
nil |
| 101 |
(defalias ,name |
| 102 |
(function (lambda ,@args))))))) |
| 103 |
|
| 104 |
(put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun) |
| 105 |
(defmacro ptexinfmt-defvar-if-void (&rest args) |
| 106 |
"Define a variable just like `defvar' unless it is already defined." |
| 107 |
(let ((name (car args))) |
| 108 |
(setq args (cdr args)) |
| 109 |
`(prog1 |
| 110 |
(defvar ,name) |
| 111 |
(if (boundp ',name) |
| 112 |
nil |
| 113 |
(defvar ,name ,@args))))) |
| 114 |
|
| 115 |
;; sort -fd |
| 116 |
(ptexinfmt-broken-facility texinfo-format-printindex |
| 117 |
"Can't sort on Mule for Windows." |
| 118 |
(if (and (memq system-type '(windows-nt ms-dos)) |
| 119 |
;;; I don't know version threshold. |
| 120 |
;;; (string< texinfmt-version "2.37 of 24 May 1997") |
| 121 |
(boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows |
| 122 |
nil |
| 123 |
t)) |
| 124 |
|
| 125 |
;; @var |
| 126 |
(ptexinfmt-broken-facility texinfo-format-var |
| 127 |
"Don't perse @var argument." |
| 128 |
(condition-case nil |
| 129 |
(with-temp-buffer |
| 130 |
(let (texinfo-enclosure-list texinfo-alias-list) |
| 131 |
(texinfo-mode) |
| 132 |
(insert "@var{@asis{foo}}\n") |
| 133 |
(texinfo-format-expand-region (point-min) (point-max)) |
| 134 |
t)) |
| 135 |
(error nil))) |
| 136 |
|
| 137 |
;; @xref |
| 138 |
(ptexinfmt-broken-facility texinfo-format-xref |
| 139 |
"Can't format @xref, 1st argument is empty." |
| 140 |
(condition-case nil |
| 141 |
(with-temp-buffer |
| 142 |
(let (texinfo-enclosure-list texinfo-alias-list) |
| 143 |
(texinfo-mode) |
| 144 |
(insert "@xref{, xref, , file}\n") |
| 145 |
(texinfo-format-expand-region (point-min) (point-max)) |
| 146 |
t)) |
| 147 |
(error nil))) |
| 148 |
|
| 149 |
;; @uref |
| 150 |
(ptexinfmt-broken-facility texinfo-format-uref |
| 151 |
"Parse twice @uref argument." |
| 152 |
(condition-case nil |
| 153 |
(with-temp-buffer |
| 154 |
(let (texinfo-enclosure-list texinfo-alias-list) |
| 155 |
(texinfo-mode) |
| 156 |
(insert "@uref{mailto:foo@@noncommand.example.com}\n") |
| 157 |
(texinfo-format-expand-region (point-min) (point-max)) |
| 158 |
t)) |
| 159 |
(error nil))) |
| 160 |
|
| 161 |
;; @multitable |
| 162 |
(ptexinfmt-broken-facility texinfo-multitable-widths |
| 163 |
"`texinfo-multitable-widths' unsupport wide-char." |
| 164 |
(if (fboundp 'texinfo-multitable-widths) |
| 165 |
(with-temp-buffer |
| 166 |
(let ((str "幅広文字")) |
| 167 |
(texinfo-mode) |
| 168 |
(insert (format " {%s}\n" str)) |
| 169 |
(goto-char (point-min)) |
| 170 |
(if (= (car (texinfo-multitable-widths)) (length str)) |
| 171 |
t |
| 172 |
nil))) |
| 173 |
;; function definition is void |
| 174 |
nil)) |
| 175 |
|
| 176 |
(ptexinfmt-broken-facility texinfo-multitable-item |
| 177 |
"`texinfo-multitable-item' unsupport wide-char." |
| 178 |
(not (get 'texinfo-multitable-widths 'broken))) |
| 179 |
|
| 180 |
|
| 181 |
;;; Hardcopy and HTML (discard) |
| 182 |
;; html |
| 183 |
(put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args) |
| 184 |
(put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args) |
| 185 |
(put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args) |
| 186 |
|
| 187 |
;; size |
| 188 |
(put 'smallbook 'texinfo-format 'texinfo-discard-line) |
| 189 |
(put 'letterpaper 'texinfo-format 'texinfo-discard-line) |
| 190 |
(put 'afourpaper 'texinfo-format 'texinfo-discard-line) |
| 191 |
(put 'afourlatex 'texinfo-format 'texinfo-discard-line) |
| 192 |
(put 'afourwide 'texinfo-format 'texinfo-discard-line) |
| 193 |
(put 'afivepaper 'texinfo-format 'texinfo-discard-line) |
| 194 |
(put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args) |
| 195 |
|
| 196 |
;; style |
| 197 |
(put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args) |
| 198 |
(put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args) |
| 199 |
|
| 200 |
;; flags |
| 201 |
(put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line) |
| 202 |
(put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line) |
| 203 |
(put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args) |
| 204 |
(put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args) |
| 205 |
|
| 206 |
;; head & foot |
| 207 |
(put 'headings 'texinfo-format 'texinfo-discard-line-with-args) |
| 208 |
(put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args) |
| 209 |
(put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args) |
| 210 |
(put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args) |
| 211 |
(put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args) |
| 212 |
(put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args) |
| 213 |
(put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args) |
| 214 |
|
| 215 |
;; misc |
| 216 |
(put 'page 'texinfo-format 'texinfo-discard-line) |
| 217 |
(put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg) |
| 218 |
|
| 219 |
;; @slanted{} (makeinfo 4.8 or later) |
| 220 |
(put 'slanted 'texinfo-format 'texinfo-format-noop) |
| 221 |
|
| 222 |
;; @sansserif{} (makeinfo 4.8 or later) |
| 223 |
(put 'sansserif 'texinfo-format 'texinfo-format-noop) |
| 224 |
|
| 225 |
;; @tie{} (makeinfo 4.3 or later) |
| 226 |
(put 'tie 'texinfo-format 'texinfo-format-tie) |
| 227 |
(ptexinfmt-defun-if-void texinfo-format-tie () |
| 228 |
(texinfo-parse-arg-discard) |
| 229 |
(insert " ")) |
| 230 |
|
| 231 |
|
| 232 |
;;; Directory File |
| 233 |
;; @direcategory |
| 234 |
(put 'dircategory 'texinfo-format 'texinfo-format-dircategory) |
| 235 |
(ptexinfmt-defun-if-void texinfo-format-dircategory () |
| 236 |
(let ((str (texinfo-parse-arg-discard))) |
| 237 |
(delete-region (point) |
| 238 |
(progn |
| 239 |
(skip-chars-forward " ") |
| 240 |
(point))) |
| 241 |
(insert "INFO-DIR-SECTION " str "\n"))) |
| 242 |
|
| 243 |
;; @direntry |
| 244 |
(put 'direntry 'texinfo-format 'texinfo-format-direntry) |
| 245 |
(ptexinfmt-defun-if-void texinfo-format-direntry () |
| 246 |
(texinfo-push-stack 'direntry nil) |
| 247 |
(texinfo-discard-line) |
| 248 |
(insert "START-INFO-DIR-ENTRY\n")) |
| 249 |
|
| 250 |
(put 'direntry 'texinfo-end 'texinfo-end-direntry) |
| 251 |
(ptexinfmt-defun-if-void texinfo-end-direntry () |
| 252 |
(texinfo-discard-command) |
| 253 |
(insert "END-INFO-DIR-ENTRY\n\n") |
| 254 |
(texinfo-pop-stack 'direntry)) |
| 255 |
|
| 256 |
|
| 257 |
;;; Block Enclosing |
| 258 |
;; @detailmenu ... @end detailmenu |
| 259 |
(put 'detailmenu 'texinfo-format 'texinfo-discard-line) |
| 260 |
(put 'detailmenu 'texinfo-end 'texinfo-discard-command) |
| 261 |
|
| 262 |
;; @smalldisplay ... @end smalldisplay |
| 263 |
(put 'smalldisplay 'texinfo-format 'texinfo-format-example) |
| 264 |
(put 'smalldisplay 'texinfo-end 'texinfo-end-example) |
| 265 |
|
| 266 |
;; @smallformat ... @end smallformat |
| 267 |
(put 'smallformat 'texinfo-format 'texinfo-format-flushleft) |
| 268 |
(put 'smallformat 'texinfo-end 'texinfo-end-flushleft) |
| 269 |
|
| 270 |
;; @cartouche ... @end cartouche |
| 271 |
(put 'cartouche 'texinfo-format 'texinfo-discard-line) |
| 272 |
(put 'cartouche 'texinfo-end 'texinfo-discard-command) |
| 273 |
|
| 274 |
|
| 275 |
;;; Conditional |
| 276 |
;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later) |
| 277 |
(put 'ifnottex 'texinfo-format 'texinfo-discard-line) |
| 278 |
(put 'ifnottex 'texinfo-end 'texinfo-discard-command) |
| 279 |
|
| 280 |
;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later) |
| 281 |
(put 'ifnothtml 'texinfo-format 'texinfo-discard-line) |
| 282 |
(put 'ifnothtml 'texinfo-end 'texinfo-discard-command) |
| 283 |
|
| 284 |
;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later) |
| 285 |
(put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line) |
| 286 |
(put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command) |
| 287 |
|
| 288 |
;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later) |
| 289 |
(put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line) |
| 290 |
(put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command) |
| 291 |
|
| 292 |
;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later) |
| 293 |
(put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo) |
| 294 |
(ptexinfmt-defun-if-void texinfo-format-ifnotinfo () |
| 295 |
(delete-region texinfo-command-start |
| 296 |
(progn (re-search-forward "@end ifnotinfo[ \t]*\n") |
| 297 |
(point)))) |
| 298 |
|
| 299 |
;; @html ... @end html (makeinfo 3.11 or later) |
| 300 |
(put 'html 'texinfo-format 'texinfo-format-html) |
| 301 |
(ptexinfmt-defun-if-void texinfo-format-html () |
| 302 |
(delete-region texinfo-command-start |
| 303 |
(progn (re-search-forward "@end html[ \t]*\n") |
| 304 |
(point)))) |
| 305 |
|
| 306 |
;; @docbook ... @end docbook (makeinfo 4.7 or later) |
| 307 |
(put 'docbook 'texinfo-format 'texinfo-format-docbook) |
| 308 |
(ptexinfmt-defun-if-void texinfo-format-docbook () |
| 309 |
(delete-region texinfo-command-start |
| 310 |
(progn (re-search-forward "@end docbook[ \t]*\n") |
| 311 |
(point)))) |
| 312 |
|
| 313 |
;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later) |
| 314 |
(put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml) |
| 315 |
(defun texinfo-format-ifhtml () |
| 316 |
(delete-region texinfo-command-start |
| 317 |
(progn (re-search-forward "@end ifhtml[ \t]*\n") |
| 318 |
(point)))) |
| 319 |
|
| 320 |
;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later) |
| 321 |
(put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext) |
| 322 |
(ptexinfmt-defun-if-void texinfo-format-ifplaintext () |
| 323 |
(delete-region texinfo-command-start |
| 324 |
(progn (re-search-forward "@end ifplaintext[ \t]*\n") |
| 325 |
(point)))) |
| 326 |
|
| 327 |
;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later) |
| 328 |
(put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook) |
| 329 |
(ptexinfmt-defun-if-void texinfo-format-ifdocbook () |
| 330 |
(delete-region texinfo-command-start |
| 331 |
(progn (re-search-forward "@end ifdocbook[ \t]*\n") |
| 332 |
(point)))) |
| 333 |
|
| 334 |
|
| 335 |
;;; Marking |
| 336 |
;; @indicateurl, @url, @env, @command, |
| 337 |
(put 'env 'texinfo-format 'texinfo-format-code) |
| 338 |
(put 'command 'texinfo-format 'texinfo-format-code) |
| 339 |
|
| 340 |
(put 'indicateurl 'texinfo-format 'texinfo-format-code) |
| 341 |
(put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7 |
| 342 |
|
| 343 |
;; @acronym |
| 344 |
(put 'acronym 'texinfo-format 'texinfo-format-var) |
| 345 |
|
| 346 |
(ptexinfmt-defun-if-broken texinfo-format-var () |
| 347 |
(let ((arg (texinfo-parse-expanded-arg))) |
| 348 |
(texinfo-discard-command) |
| 349 |
(insert (upcase arg)))) |
| 350 |
|
| 351 |
;; @key |
| 352 |
(put 'key 'texinfo-format 'texinfo-format-key) |
| 353 |
(ptexinfmt-defun-if-void texinfo-format-key () |
| 354 |
(insert (texinfo-parse-arg-discard)) |
| 355 |
(goto-char texinfo-command-start)) |
| 356 |
|
| 357 |
;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]} |
| 358 |
(put 'email 'texinfo-format 'texinfo-format-email) |
| 359 |
(ptexinfmt-defun-if-void texinfo-format-email () |
| 360 |
"Format EMAIL-ADDRESS and optional DISPLAYED-TXT. |
| 361 |
Insert < ... > around EMAIL-ADDRESS." |
| 362 |
(let ((args (texinfo-format-parse-args))) |
| 363 |
(texinfo-discard-command) |
| 364 |
;; if displayed-text |
| 365 |
(if (nth 1 args) |
| 366 |
(insert (nth 1 args) " <" (nth 0 args) ">") |
| 367 |
(insert "<" (nth 0 args) ">")))) |
| 368 |
|
| 369 |
;; @option |
| 370 |
(put 'option 'texinfo-format 'texinfo-format-option) |
| 371 |
(ptexinfmt-defun-if-void texinfo-format-option () |
| 372 |
"Insert ` ... ' around arg unless inside a table; in that case, no quotes." |
| 373 |
;; `looking-at-backward' not available in v. 18.57, 20.2 |
| 374 |
;; searched-for character is a control-H |
| 375 |
(if (not (search-backward "\010" |
| 376 |
(save-excursion (beginning-of-line) (point)) |
| 377 |
t)) |
| 378 |
(insert "`" (texinfo-parse-arg-discard) "'") |
| 379 |
(insert (texinfo-parse-arg-discard))) |
| 380 |
(goto-char texinfo-command-start)) |
| 381 |
|
| 382 |
;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later) |
| 383 |
(put 'verb 'texinfo-format 'texinfo-format-verb) |
| 384 |
(ptexinfmt-defun-if-void texinfo-format-verb () |
| 385 |
"Format text between non-quoted unique delimiter characters verbatim. |
| 386 |
Enclose the verbatim text, including the delimiters, in braces. Print |
| 387 |
text exactly as written (but not the delimiters) in a fixed-width. |
| 388 |
|
| 389 |
For example, @verb\{|@|\} results in @ and |
| 390 |
@verb\{+@'e?`!`+} results in @'e?`!`." |
| 391 |
|
| 392 |
(let ((delimiter (buffer-substring-no-properties |
| 393 |
(1+ texinfo-command-end) (+ 2 texinfo-command-end)))) |
| 394 |
(unless (looking-at "{") |
| 395 |
(error "Not found: @verb start brace")) |
| 396 |
(delete-region texinfo-command-start (+ 2 texinfo-command-end)) |
| 397 |
(search-forward delimiter)) |
| 398 |
(delete-char -1) |
| 399 |
(unless (looking-at "}") |
| 400 |
(error "Not found: @verb end brace")) |
| 401 |
(delete-char 1)) |
| 402 |
|
| 403 |
|
| 404 |
;;; @LaTeX, @registeredsymbol{} |
| 405 |
(put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX) |
| 406 |
(ptexinfmt-defun-if-void texinfo-format-LaTeX () |
| 407 |
(texinfo-parse-arg-discard) |
| 408 |
(insert "LaTeX")) |
| 409 |
|
| 410 |
(put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol) |
| 411 |
(ptexinfmt-defun-if-void texinfo-format-registeredsymbol () |
| 412 |
(texinfo-parse-arg-discard) |
| 413 |
(insert "(R)")) |
| 414 |
|
| 415 |
;;; Accents and Special characters |
| 416 |
;; @euro{} ==> Euro |
| 417 |
(put 'euro 'texinfo-format 'texinfo-format-euro) |
| 418 |
(ptexinfmt-defun-if-void texinfo-format-euro () |
| 419 |
(texinfo-parse-arg-discard) |
| 420 |
(insert "Euro ")) |
| 421 |
|
| 422 |
;; @pounds{} ==> # Pounds Sterling |
| 423 |
(put 'pounds 'texinfo-format 'texinfo-format-pounds) |
| 424 |
(ptexinfmt-defun-if-void texinfo-format-pounds () |
| 425 |
(texinfo-parse-arg-discard) |
| 426 |
(insert "#")) |
| 427 |
|
| 428 |
;; @ordf{} ==> a Spanish feminine |
| 429 |
(put 'ordf 'texinfo-format 'texinfo-format-ordf) |
| 430 |
(ptexinfmt-defun-if-void texinfo-format-ordf () |
| 431 |
(texinfo-parse-arg-discard) |
| 432 |
(insert "a")) |
| 433 |
|
| 434 |
;; @ordm{} ==> o Spanish masculine |
| 435 |
(put 'ordm 'texinfo-format 'texinfo-format-ordm) |
| 436 |
(ptexinfmt-defun-if-void texinfo-format-ordm () |
| 437 |
(texinfo-parse-arg-discard) |
| 438 |
(insert "o")) |
| 439 |
|
| 440 |
;; @OE{} ==> OE French-OE-ligature |
| 441 |
(put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature) |
| 442 |
(ptexinfmt-defun-if-void texinfo-format-French-OE-ligature () |
| 443 |
(insert "OE" (texinfo-parse-arg-discard)) |
| 444 |
(goto-char texinfo-command-start)) |
| 445 |
|
| 446 |
;; @oe{} ==> oe |
| 447 |
(put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature) |
| 448 |
(ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case |
| 449 |
(insert "oe" (texinfo-parse-arg-discard)) |
| 450 |
(goto-char texinfo-command-start)) |
| 451 |
|
| 452 |
;; @AA{} ==> AA Scandinavian-A-with-circle |
| 453 |
(put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle) |
| 454 |
(ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle () |
| 455 |
(insert "AA" (texinfo-parse-arg-discard)) |
| 456 |
(goto-char texinfo-command-start)) |
| 457 |
|
| 458 |
;; @aa{} ==> aa |
| 459 |
(put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle) |
| 460 |
(ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case |
| 461 |
(insert "aa" (texinfo-parse-arg-discard)) |
| 462 |
(goto-char texinfo-command-start)) |
| 463 |
|
| 464 |
;; @AE{} ==> AE Latin-Scandinavian-AE |
| 465 |
(put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE) |
| 466 |
(ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE () |
| 467 |
(insert "AE" (texinfo-parse-arg-discard)) |
| 468 |
(goto-char texinfo-command-start)) |
| 469 |
|
| 470 |
;; @ae{} ==> ae |
| 471 |
(put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae) |
| 472 |
(ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case |
| 473 |
(insert "ae" (texinfo-parse-arg-discard)) |
| 474 |
(goto-char texinfo-command-start)) |
| 475 |
|
| 476 |
;; @ss{} ==> ss German-sharp-S |
| 477 |
(put 'ss 'texinfo-format 'texinfo-format-German-sharp-S) |
| 478 |
(ptexinfmt-defun-if-void texinfo-format-German-sharp-S () |
| 479 |
(insert "ss" (texinfo-parse-arg-discard)) |
| 480 |
(goto-char texinfo-command-start)) |
| 481 |
|
| 482 |
;; @questiondown{} ==> ? upside-down-question-mark |
| 483 |
(put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark) |
| 484 |
(ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark () |
| 485 |
(insert "?" (texinfo-parse-arg-discard)) |
| 486 |
(goto-char texinfo-command-start)) |
| 487 |
|
| 488 |
;; @exclamdown{} ==> ! upside-down-exclamation-mark |
| 489 |
(put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark) |
| 490 |
(ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark () |
| 491 |
(insert "!" (texinfo-parse-arg-discard)) |
| 492 |
(goto-char texinfo-command-start)) |
| 493 |
|
| 494 |
;; @L{} ==> L/ Polish suppressed-L (Lslash) |
| 495 |
(put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L) |
| 496 |
(ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L () |
| 497 |
(insert (texinfo-parse-arg-discard) "/L") |
| 498 |
(goto-char texinfo-command-start)) |
| 499 |
|
| 500 |
;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case) |
| 501 |
(put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case) |
| 502 |
(ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case () |
| 503 |
(insert (texinfo-parse-arg-discard) "/l") |
| 504 |
(goto-char texinfo-command-start)) |
| 505 |
|
| 506 |
;; @O{} ==> O/ Scandinavian O-with-slash |
| 507 |
(put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash) |
| 508 |
(ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash () |
| 509 |
(insert (texinfo-parse-arg-discard) "O/") |
| 510 |
(goto-char texinfo-command-start)) |
| 511 |
|
| 512 |
;; @o{} ==> o/ Scandinavian O-with-slash (lower case) |
| 513 |
(put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case) |
| 514 |
(ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case () |
| 515 |
(insert (texinfo-parse-arg-discard) "o/") |
| 516 |
(goto-char texinfo-command-start)) |
| 517 |
|
| 518 |
;; @,{c} ==> c, cedilla accent |
| 519 |
(put '\, 'texinfo-format 'texinfo-format-cedilla-accent) |
| 520 |
(ptexinfmt-defun-if-void texinfo-format-cedilla-accent () |
| 521 |
(insert (texinfo-parse-arg-discard) ",") |
| 522 |
(goto-char texinfo-command-start)) |
| 523 |
|
| 524 |
|
| 525 |
;; @dotaccent{o} ==> .o overdot-accent |
| 526 |
(put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent) |
| 527 |
(ptexinfmt-defun-if-void texinfo-format-overdot-accent () |
| 528 |
(insert "." (texinfo-parse-arg-discard)) |
| 529 |
(goto-char texinfo-command-start)) |
| 530 |
|
| 531 |
;; @ubaraccent{o} ==> _o underbar-accent |
| 532 |
(put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent) |
| 533 |
(ptexinfmt-defun-if-void texinfo-format-underbar-accent () |
| 534 |
(insert "_" (texinfo-parse-arg-discard)) |
| 535 |
(goto-char texinfo-command-start)) |
| 536 |
|
| 537 |
;; @udotaccent{o} ==> o-. underdot-accent |
| 538 |
(put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent) |
| 539 |
(ptexinfmt-defun-if-void texinfo-format-underdot-accent () |
| 540 |
(insert (texinfo-parse-arg-discard) "-.") |
| 541 |
(goto-char texinfo-command-start)) |
| 542 |
|
| 543 |
;; @H{o} ==> ""o long Hungarian umlaut |
| 544 |
(put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut) |
| 545 |
(ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut () |
| 546 |
(insert "\"\"" (texinfo-parse-arg-discard)) |
| 547 |
(goto-char texinfo-command-start)) |
| 548 |
|
| 549 |
;; @ringaccent{o} ==> *o ring accent |
| 550 |
(put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent) |
| 551 |
(ptexinfmt-defun-if-void texinfo-format-ring-accent () |
| 552 |
(insert "*" (texinfo-parse-arg-discard)) |
| 553 |
(goto-char texinfo-command-start)) |
| 554 |
|
| 555 |
;; @tieaccent{oo} ==> [oo tie after accent |
| 556 |
(put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent) |
| 557 |
(ptexinfmt-defun-if-void texinfo-format-tie-after-accent () |
| 558 |
(insert "[" (texinfo-parse-arg-discard)) |
| 559 |
(goto-char texinfo-command-start)) |
| 560 |
|
| 561 |
;; @u{o} ==> (o breve accent |
| 562 |
(put 'u 'texinfo-format 'texinfo-format-breve-accent) |
| 563 |
(ptexinfmt-defun-if-void texinfo-format-breve-accent () |
| 564 |
(insert "(" (texinfo-parse-arg-discard)) |
| 565 |
(goto-char texinfo-command-start)) |
| 566 |
|
| 567 |
;; @v{o} ==> <o hacek accent |
| 568 |
(put 'v 'texinfo-format 'texinfo-format-hacek-accent) |
| 569 |
(ptexinfmt-defun-if-void texinfo-format-hacek-accent () |
| 570 |
(insert "<" (texinfo-parse-arg-discard)) |
| 571 |
(goto-char texinfo-command-start)) |
| 572 |
|
| 573 |
;; @dotless{i} ==> i dotless i and dotless j |
| 574 |
(put 'dotless 'texinfo-format 'texinfo-format-dotless) |
| 575 |
(ptexinfmt-defun-if-void texinfo-format-dotless () |
| 576 |
(insert (texinfo-parse-arg-discard)) |
| 577 |
(goto-char texinfo-command-start)) |
| 578 |
|
| 579 |
;; @. |
| 580 |
(put '\. 'texinfo-format 'texinfo-format-\.) |
| 581 |
(ptexinfmt-defun-if-void texinfo-format-\. () |
| 582 |
(texinfo-discard-command) |
| 583 |
(insert ".")) |
| 584 |
|
| 585 |
;; @: |
| 586 |
(put '\: 'texinfo-format 'texinfo-format-\:) |
| 587 |
(ptexinfmt-defun-if-void texinfo-format-\: () |
| 588 |
(texinfo-discard-command)) |
| 589 |
|
| 590 |
;; @- |
| 591 |
(put '\- 'texinfo-format 'texinfo-format-soft-hyphen) |
| 592 |
(ptexinfmt-defun-if-void texinfo-format-soft-hyphen () |
| 593 |
(texinfo-discard-command)) |
| 594 |
|
| 595 |
;; @/ |
| 596 |
(put '\/ 'texinfo-format 'texinfo-format-\/) |
| 597 |
(ptexinfmt-defun-if-void texinfo-format-\/ () |
| 598 |
(texinfo-discard-command)) |
| 599 |
|
| 600 |
|
| 601 |
;;; Cross References |
| 602 |
;; @ref, @xref |
| 603 |
(put 'ref 'texinfo-format 'texinfo-format-xref) |
| 604 |
|
| 605 |
(ptexinfmt-defun-if-broken texinfo-format-xref () |
| 606 |
(let ((args (texinfo-format-parse-args))) |
| 607 |
(texinfo-discard-command) |
| 608 |
(insert "*Note ") |
| 609 |
(let ((fname (or (nth 1 args) (nth 2 args)))) |
| 610 |
(if (null (or fname (nth 3 args))) |
| 611 |
(insert (nth 0 args) "::") |
| 612 |
(insert (or fname (nth 0 args)) ": ") |
| 613 |
(if (nth 3 args) |
| 614 |
(insert "(" (nth 3 args) ")")) |
| 615 |
(unless (null (nth 0 args)) |
| 616 |
(insert (nth 0 args))))))) |
| 617 |
|
| 618 |
;; @uref{URL [,TEXT] [,REPLACEMENT]} |
| 619 |
(put 'uref 'texinfo-format 'texinfo-format-uref) |
| 620 |
(ptexinfmt-defun-if-broken texinfo-format-uref () |
| 621 |
"Format URL and optional URL-TITLE. |
| 622 |
Insert ` ... ' around URL if no URL-TITLE argument; |
| 623 |
otherwise, insert URL-TITLE followed by URL in parentheses." |
| 624 |
(let ((args (texinfo-format-parse-args))) |
| 625 |
(texinfo-discard-command) |
| 626 |
;; if url-title |
| 627 |
(if (nth 1 args) |
| 628 |
(insert (nth 1 args) " (" (nth 0 args) ")") |
| 629 |
(insert "`" (nth 0 args) "'")))) |
| 630 |
|
| 631 |
;; @inforef |
| 632 |
(put 'inforef 'texinfo-format 'texinfo-format-inforef) |
| 633 |
(ptexinfmt-defun-if-void texinfo-format-inforef () |
| 634 |
(let ((args (texinfo-format-parse-args))) |
| 635 |
(texinfo-discard-command) |
| 636 |
(if (nth 1 args) |
| 637 |
(insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args)) |
| 638 |
(insert "*Note " "(" (nth 2 args) ")" (car args) "::")))) |
| 639 |
|
| 640 |
|
| 641 |
;; @anchor |
| 642 |
;; don't emulation |
| 643 |
;; If support @anchor for Mule 2.3, We must fix informat.el and info.el: |
| 644 |
;; - Info-tagify suport @anthor-*-refill. |
| 645 |
;; - info.el support Ref in Tag table. |
| 646 |
(unless (get 'anchor 'texinfo-format) |
| 647 |
(put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg)) |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
;;; New command definition |
| 652 |
;; @alias NEW=EXISTING |
| 653 |
(put 'alias 'texinfo-format 'texinfo-alias) |
| 654 |
(ptexinfmt-defun-if-void texinfo-alias () |
| 655 |
(let ((start (1- (point))) |
| 656 |
args) |
| 657 |
(skip-chars-forward " ") |
| 658 |
(save-excursion (end-of-line) (setq texinfo-command-end (point))) |
| 659 |
(if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) |
| 660 |
(error "Invalid alias command") |
| 661 |
(setq texinfo-alias-list |
| 662 |
(cons |
| 663 |
(cons |
| 664 |
(buffer-substring (match-beginning 1) (match-end 1)) |
| 665 |
(buffer-substring (match-beginning 2) (match-end 2))) |
| 666 |
texinfo-alias-list)) |
| 667 |
(texinfo-discard-command)))) |
| 668 |
|
| 669 |
|
| 670 |
;;; Indent |
| 671 |
;; @exampleindent INDENT (makeinfo 4.0 or later) |
| 672 |
|
| 673 |
;; @paragraphindent INDENT (makeinfo 4.0 or later) |
| 674 |
;; INDENT: asis, 0, n |
| 675 |
|
| 676 |
;; @firstparagraphindent WORD (makeinfo 4.6 or later) |
| 677 |
;; WORD: none, insert |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
;;; Special |
| 682 |
;; @image{FILENAME [, WIDTH] [, HEIGHT]} |
| 683 |
(put 'image 'texinfo-format 'texinfo-format-image) |
| 684 |
(ptexinfmt-defun-if-void texinfo-format-image () |
| 685 |
;; I don't know makeinfo parse FILENAME. |
| 686 |
(let ((args (texinfo-format-parse-args)) |
| 687 |
filename) |
| 688 |
(when (null (nth 0 args)) |
| 689 |
(error "Invalid image command")) |
| 690 |
(texinfo-discard-command) |
| 691 |
;; makeinfo uses FILENAME.txt |
| 692 |
(setq filename (format "%s.txt" (nth 0 args))) |
| 693 |
(message "Reading included file: %s" filename) |
| 694 |
;; verbatim for Info output |
| 695 |
(goto-char (+ (point) (cadr (insert-file-contents filename)))) |
| 696 |
(message "Reading included file: %s...done" filename))) |
| 697 |
|
| 698 |
;; @hyphenation command discards an argument within braces |
| 699 |
(put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg) |
| 700 |
(ptexinfmt-defun-if-void texinfo-discard-command-and-arg () |
| 701 |
"Discard both @-command and its argument in braces." |
| 702 |
(goto-char texinfo-command-end) |
| 703 |
(forward-list 1) |
| 704 |
(setq texinfo-command-end (point)) |
| 705 |
(delete-region texinfo-command-start texinfo-command-end)) |
| 706 |
|
| 707 |
|
| 708 |
;;; @multitable ... @end multitable |
| 709 |
(ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0 |
| 710 |
"*Number of extra spaces between entries (columns) in @multitable.") |
| 711 |
|
| 712 |
(ptexinfmt-defvar-if-void texinfo-multitable-buffer-name |
| 713 |
"*multitable-temporary-buffer*") |
| 714 |
(ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name |
| 715 |
"texinfo-multitable-temp-") |
| 716 |
|
| 717 |
;; These commands are defined in texinfo.tex for printed output. |
| 718 |
(put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args) |
| 719 |
(put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args) |
| 720 |
(put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args) |
| 721 |
(put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args) |
| 722 |
|
| 723 |
(put 'multitable 'texinfo-format 'texinfo-multitable) |
| 724 |
|
| 725 |
(ptexinfmt-defun-if-void texinfo-multitable () |
| 726 |
"Produce multi-column tables." |
| 727 |
|
| 728 |
;; This function pushes information onto the `texinfo-stack'. |
| 729 |
;; A stack element consists of: |
| 730 |
;; - type-of-command, i.e., multitable |
| 731 |
;; - the information about column widths, and |
| 732 |
;; - the position of texinfo-command-start. |
| 733 |
;; e.g., ('multitable (1 2 3 4) 123) |
| 734 |
;; The command line is then deleted. |
| 735 |
(texinfo-push-stack |
| 736 |
'multitable |
| 737 |
;; push width information on stack |
| 738 |
(texinfo-multitable-widths)) |
| 739 |
(texinfo-discard-line-with-args)) |
| 740 |
|
| 741 |
(put 'multitable 'texinfo-end 'texinfo-end-multitable) |
| 742 |
(ptexinfmt-defun-if-void texinfo-end-multitable () |
| 743 |
"Discard the @end multitable line and pop the stack of multitable." |
| 744 |
(texinfo-discard-command) |
| 745 |
(texinfo-pop-stack 'multitable)) |
| 746 |
|
| 747 |
(ptexinfmt-defun-if-broken texinfo-multitable-widths () |
| 748 |
"Return list of widths of each column in a multi-column table." |
| 749 |
(let (texinfo-multitable-width-list) |
| 750 |
;; Fractions format: |
| 751 |
;; @multitable @columnfractions .25 .3 .45 |
| 752 |
;; |
| 753 |
;; Template format: |
| 754 |
;; @multitable {Column 1 template} {Column 2} {Column 3 example} |
| 755 |
;; Place point before first argument |
| 756 |
(skip-chars-forward " \t") |
| 757 |
(cond |
| 758 |
;; Check for common misspelling |
| 759 |
((looking-at "@columnfraction ") |
| 760 |
(error "In @multitable, @columnfractions misspelled")) |
| 761 |
;; Case 1: @columnfractions .25 .3 .45 |
| 762 |
((looking-at "@columnfractions") |
| 763 |
(forward-word 1) |
| 764 |
(while (not (eolp)) |
| 765 |
(setq texinfo-multitable-width-list |
| 766 |
(cons |
| 767 |
(truncate |
| 768 |
(1- |
| 769 |
(* fill-column (read (get-buffer (current-buffer)))))) |
| 770 |
texinfo-multitable-width-list)))) |
| 771 |
;; |
| 772 |
;; Case 2: {Column 1 template} {Column 2} {Column 3 example} |
| 773 |
((looking-at "{") |
| 774 |
(let ((start-of-templates (point))) |
| 775 |
(while (not (eolp)) |
| 776 |
(skip-chars-forward " \t") |
| 777 |
(let* ((start-of-template (1+ (point))) |
| 778 |
(end-of-template |
| 779 |
;; forward-sexp works with braces in Texinfo mode |
| 780 |
(progn (forward-sexp 1) (1- (point))))) |
| 781 |
(setq texinfo-multitable-width-list |
| 782 |
(cons (- (progn |
| 783 |
(goto-char end-of-template) |
| 784 |
(current-column)) |
| 785 |
(progn |
| 786 |
(goto-char start-of-template) |
| 787 |
(current-column))) |
| 788 |
texinfo-multitable-width-list)) |
| 789 |
;; Remove carriage return from within a template, if any. |
| 790 |
;; This helps those those who want to use more than |
| 791 |
;; one line's worth of words in @multitable line. |
| 792 |
(narrow-to-region start-of-template end-of-template) |
| 793 |
(goto-char (point-min)) |
| 794 |
(while (search-forward "\n" nil t) |
| 795 |
(delete-char -1)) |
| 796 |
(goto-char (point-max)) |
| 797 |
(widen) |
| 798 |
(forward-char 1))))) |
| 799 |
;; |
| 800 |
;; Case 3: Trouble |
| 801 |
(t |
| 802 |
(error "\ |
| 803 |
You probably need to specify column widths for @multitable correctly"))) |
| 804 |
;; Check whether columns fit on page. |
| 805 |
(let ((desired-columns |
| 806 |
(+ |
| 807 |
;; between column spaces |
| 808 |
(length texinfo-multitable-width-list) |
| 809 |
;; additional between column spaces, if any |
| 810 |
texinfo-extra-inter-column-width |
| 811 |
;; sum of spaces for each entry |
| 812 |
(apply '+ texinfo-multitable-width-list)))) |
| 813 |
(if (> desired-columns fill-column) |
| 814 |
(error (format "\ |
| 815 |
Multi-column table width, %d chars, is greater than page width, %d chars." |
| 816 |
desired-columns fill-column)))) |
| 817 |
texinfo-multitable-width-list)) |
| 818 |
|
| 819 |
;; @item A1 @tab A2 @tab A3 |
| 820 |
(ptexinfmt-defun-if-void texinfo-multitable-extract-row () |
| 821 |
"Return multitable row, as a string. |
| 822 |
End of row is beginning of next @item or beginning of @end. |
| 823 |
Cells within rows are separated by @tab." |
| 824 |
(skip-chars-forward " \t") |
| 825 |
(let* ((start (point)) |
| 826 |
(end (progn |
| 827 |
(re-search-forward "@item\\|@end") |
| 828 |
(match-beginning 0))) |
| 829 |
(row (progn (goto-char end) |
| 830 |
(skip-chars-backward " ") |
| 831 |
;; remove whitespace at end of argument |
| 832 |
(delete-region (point) end) |
| 833 |
(buffer-substring start (point))))) |
| 834 |
(delete-region texinfo-command-start end) |
| 835 |
row)) |
| 836 |
|
| 837 |
(put 'multitable 'texinfo-item 'texinfo-multitable-item) |
| 838 |
(ptexinfmt-defun-if-void texinfo-multitable-item () |
| 839 |
"Format a row within a multicolumn table. |
| 840 |
Cells in row are separated by @tab. |
| 841 |
Widths of cells are specified by the arguments in the @multitable line. |
| 842 |
All cells are made to be the same height. |
| 843 |
This command is executed when texinfmt sees @item inside @multitable." |
| 844 |
(let ((original-buffer (current-buffer)) |
| 845 |
(table-widths (reverse (car (cdr (car texinfo-stack))))) |
| 846 |
(existing-fill-column fill-column) |
| 847 |
start |
| 848 |
end |
| 849 |
(table-column 0) |
| 850 |
(table-entry-height 0) |
| 851 |
;; unformatted row looks like: A1 @tab A2 @tab A3 |
| 852 |
;; extract-row command deletes the source line in the table. |
| 853 |
(unformated-row (texinfo-multitable-extract-row))) |
| 854 |
;; Use a temporary buffer |
| 855 |
(set-buffer (get-buffer-create texinfo-multitable-buffer-name)) |
| 856 |
(delete-region (point-min) (point-max)) |
| 857 |
(insert unformated-row) |
| 858 |
(goto-char (point-min)) |
| 859 |
;; 1. Check for correct number of @tab in line. |
| 860 |
(let ((tab-number 1)) ;; one @tab between two columns |
| 861 |
(while (search-forward "@tab" nil t) |
| 862 |
(setq tab-number (1+ tab-number))) |
| 863 |
(if (/= tab-number (length table-widths)) |
| 864 |
(error "Wrong number of @tab's in a @multitable row"))) |
| 865 |
(goto-char (point-min)) |
| 866 |
;; 2. Format each cell, and copy to a rectangle |
| 867 |
;; buffer looks like this: A1 @tab A2 @tab A3 |
| 868 |
;; Cell #1: format up to @tab |
| 869 |
;; Cell #2: format up to @tab |
| 870 |
;; Cell #3: format up to eob |
| 871 |
(while (not (eobp)) |
| 872 |
(setq start (point)) |
| 873 |
(setq end (save-excursion |
| 874 |
(if (search-forward "@tab" nil 'move) |
| 875 |
;; Delete the @tab command, including the @-sign |
| 876 |
(delete-region |
| 877 |
(point) |
| 878 |
(progn (forward-word -1) (1- (point))))) |
| 879 |
(point))) |
| 880 |
;; Set fill-column *wider* than needed to produce inter-column space |
| 881 |
(setq fill-column (+ 1 |
| 882 |
texinfo-extra-inter-column-width |
| 883 |
(nth table-column table-widths))) |
| 884 |
(narrow-to-region start end) |
| 885 |
;; Remove whitespace before and after entry. |
| 886 |
(skip-chars-forward " ") |
| 887 |
(delete-region (point) (save-excursion (beginning-of-line) (point))) |
| 888 |
(goto-char (point-max)) |
| 889 |
(skip-chars-backward " ") |
| 890 |
(delete-region (point) (save-excursion (end-of-line) (point))) |
| 891 |
;; Temorarily set texinfo-stack to nil so texinfo-format-scan |
| 892 |
;; does not see an unterminated @multitable. |
| 893 |
(let (texinfo-stack) ;; nil |
| 894 |
(texinfo-format-scan)) |
| 895 |
(let (fill-prefix) ;; no fill prefix |
| 896 |
(fill-region (point-min) (point-max))) |
| 897 |
(setq table-entry-height |
| 898 |
(max table-entry-height (count-lines (point-min) (point-max)))) |
| 899 |
;; 3. Move point to end of bottom line, and pad that line to fill column. |
| 900 |
(goto-char (point-min)) |
| 901 |
(forward-line (1- table-entry-height)) |
| 902 |
(let* ((beg (point)) ;; beginning of line |
| 903 |
;; add one more space for inter-column spacing |
| 904 |
(needed-whitespace |
| 905 |
(1+ |
| 906 |
(- fill-column |
| 907 |
(progn |
| 908 |
(end-of-line) |
| 909 |
(current-column)))))) ;; end of existing line |
| 910 |
(insert (make-string |
| 911 |
(if (> needed-whitespace 0) needed-whitespace 1) |
| 912 |
? ))) |
| 913 |
;; now, put formatted cell into a rectangle |
| 914 |
(set (intern (concat texinfo-multitable-rectangle-name |
| 915 |
(int-to-string table-column))) |
| 916 |
(extract-rectangle (point-min) (point))) |
| 917 |
(delete-region (point-min) (point)) |
| 918 |
(goto-char (point-max)) |
| 919 |
(setq table-column (1+ table-column)) |
| 920 |
(widen)) |
| 921 |
;; 4. Add extra lines to rectangles so all are of same height |
| 922 |
(let ((total-number-of-columns table-column) |
| 923 |
(column-number 0) |
| 924 |
here) |
| 925 |
(while (> table-column 0) |
| 926 |
(let ((this-rectangle (int-to-string table-column))) |
| 927 |
(while (< (length this-rectangle) table-entry-height) |
| 928 |
(setq this-rectangle (append this-rectangle '(""))))) |
| 929 |
(setq table-column (1- table-column))) |
| 930 |
;; 5. Insert formatted rectangles in original buffer |
| 931 |
(switch-to-buffer original-buffer) |
| 932 |
(open-line table-entry-height) |
| 933 |
(while (< column-number total-number-of-columns) |
| 934 |
(setq here (point)) |
| 935 |
(insert-rectangle |
| 936 |
(eval (intern |
| 937 |
(concat texinfo-multitable-rectangle-name |
| 938 |
(int-to-string column-number))))) |
| 939 |
(goto-char here) |
| 940 |
(end-of-line) |
| 941 |
(setq column-number (1+ column-number)))) |
| 942 |
(kill-buffer texinfo-multitable-buffer-name) |
| 943 |
(setq fill-column existing-fill-column))) |
| 944 |
|
| 945 |
|
| 946 |
(ptexinfmt-defun-if-broken texinfo-format-printindex () |
| 947 |
(let ((indexelts (symbol-value |
| 948 |
(cdr (assoc (texinfo-parse-arg-discard) |
| 949 |
texinfo-indexvar-alist)))) |
| 950 |
opoint) |
| 951 |
(insert "\n* Menu:\n\n") |
| 952 |
(setq opoint (point)) |
| 953 |
(texinfo-print-index nil indexelts) |
| 954 |
|
| 955 |
(if (memq system-type '(vax-vms windows-nt ms-dos)) |
| 956 |
(texinfo-sort-region opoint (point)) |
| 957 |
(shell-command-on-region opoint (point) "sort -fd" 1)))) |
| 958 |
|
| 959 |
(ptexinfmt-broken-facility texinfo-format-end-node () |
| 960 |
(with-temp-buffer |
| 961 |
(insert (prin1-to-string (symbol-function 'texinfo-format-end-node))) |
| 962 |
(goto-char (point-min)) |
| 963 |
(not (search-forward "fill-paragraph" nil t nil)))) |
| 964 |
|
| 965 |
(ptexinfmt-defun-if-broken texinfo-format-end-node () |
| 966 |
(let (start |
| 967 |
(arg (texinfo-parse-line-arg))) |
| 968 |
(texinfo-discard-command) ; remove or insert whitespace, as needed |
| 969 |
(delete-region (save-excursion (skip-chars-backward " \t\n") (point)) |
| 970 |
(point)) |
| 971 |
(insert (format " (%d) " texinfo-footnote-number)) |
| 972 |
;;(fill-paragraph nil) |
| 973 |
(save-excursion |
| 974 |
(if (search-forward "\n--------- Footnotes ---------\n" nil t) |
| 975 |
(progn ; already have footnote, put new one before end of node |
| 976 |
(if (re-search-forward "^@node" nil 'move) |
| 977 |
(forward-line -1)) |
| 978 |
(setq start (point)) |
| 979 |
(insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) |
| 980 |
(fill-region start (point))) |
| 981 |
;; else no prior footnote |
| 982 |
(if (re-search-forward "^@node" nil 'move) |
| 983 |
(forward-line -1)) |
| 984 |
(insert "\n--------- Footnotes ---------\n") |
| 985 |
(setq start (point)) |
| 986 |
(insert (format "\n(%d) %s\n" texinfo-footnote-number arg)))))) |
| 987 |
|
| 988 |
(provide 'ptexinfmt) |
| 989 |
|
| 990 |
;; Local Variables: |
| 991 |
;; indent-tabs-mode: nil |
| 992 |
;; End: |
| 993 |
|
| 994 |
;;; ptexinfmt.el ends here |