1;;; texinfmt.el --- format Texinfo files into Info files 2 3;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 4;; 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 5;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 6 7;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org> 8;; Keywords: maint, tex, docs 9 10;; This file is part of GNU Emacs. 11 12;; GNU Emacs is free software; you can redistribute it and/or modify 13;; it under the terms of the GNU General Public License as published by 14;; the Free Software Foundation; either version 2, or (at your option) 15;; any later version. 16 17;; GNU Emacs is distributed in the hope that it will be useful, 18;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20;; GNU General Public License for more details. 21 22;; You should have received a copy of the GNU General Public License 23;; along with GNU Emacs; see the file COPYING. If not, write to the 24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 25;; Boston, MA 02110-1301, USA. 26 27;;; Commentary: 28 29;;; Code: 30 31;;; Emacs lisp functions to convert Texinfo files to Info files. 32 33(or (fboundp 'defgroup) 34 (defmacro defgroup (&rest ignore) nil)) 35 36(or (fboundp 'defcustom) 37 (defmacro defcustom (var value doc &rest ignore) 38 `(defvar ,var ,value ,doc))) 39 40(defvar texinfmt-version "2.42 of 7 Jul 2006") 41 42(defun texinfmt-version (&optional here) 43 "Show the version of texinfmt.el in the minibuffer. 44If optional argument HERE is non-nil, insert info at point." 45 (interactive "P") 46 (let ((version-string 47 (format "Version of \`texinfmt.el\': %s" texinfmt-version))) 48 (if here 49 (insert version-string) 50 (if (interactive-p) 51 (message "%s" version-string) 52 version-string)))) 53 54 55;;; Variable definitions 56 57(require 'texinfo) ; So `texinfo-footnote-style' is defined. 58(require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined. 59 60(defvar texinfo-format-syntax-table nil) 61 62(defvar texinfo-vindex) 63(defvar texinfo-findex) 64(defvar texinfo-cindex) 65(defvar texinfo-pindex) 66(defvar texinfo-tindex) 67(defvar texinfo-kindex) 68(defvar texinfo-last-node) 69(defvar texinfo-node-names) 70(defvar texinfo-enclosure-list) 71(defvar texinfo-alias-list) 72(defvar texinfo-fold-nodename-case nil) 73 74(defvar texinfo-command-start) 75(defvar texinfo-command-end) 76(defvar texinfo-command-name) 77(defvar texinfo-defun-type) 78(defvar texinfo-last-node-pos) 79(defvar texinfo-stack) 80(defvar texinfo-short-index-cmds-alist) 81(defvar texinfo-short-index-format-cmds-alist) 82(defvar texinfo-format-filename) 83(defvar texinfo-footnote-number) 84(defvar texinfo-start-of-header) 85(defvar texinfo-end-of-header) 86(defvar texinfo-raisesections-alist) 87(defvar texinfo-lowersections-alist) 88 89;;; Syntax table 90 91(if texinfo-format-syntax-table 92 nil 93 (setq texinfo-format-syntax-table (make-syntax-table)) 94 (modify-syntax-entry ?\" " " texinfo-format-syntax-table) 95 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table) 96 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table) 97 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table) 98 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table) 99 (modify-syntax-entry ?\] "." texinfo-format-syntax-table) 100 (modify-syntax-entry ?\( "." texinfo-format-syntax-table) 101 (modify-syntax-entry ?\) "." texinfo-format-syntax-table) 102 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table) 103 (modify-syntax-entry ?} "){" texinfo-format-syntax-table) 104 (modify-syntax-entry ?\' "." texinfo-format-syntax-table)) 105 106 107;;; Top level buffer and region formatting functions 108 109;;;###autoload 110(defun texinfo-format-buffer (&optional nosplit) 111 "Process the current buffer as texinfo code, into an Info file. 112The Info file output is generated in a buffer visiting the Info file 113name specified in the @setfilename command. 114 115Non-nil argument (prefix, if interactive) means don't make tag table 116and don't split the file if large. You can use Info-tagify and 117Info-split to do these manually." 118 (interactive "P") 119 (let ((lastmessage "Formatting Info file...") 120 (coding-system-for-write buffer-file-coding-system)) 121 (message lastmessage) 122 (widen) 123 (texinfo-format-buffer-1) 124 (Info-tagify) 125 (if nosplit 126 nil 127 (if (> (buffer-size) 100000) 128 (progn 129 (message (setq lastmessage "Splitting Info file...")) 130 (Info-split)))) 131 (message (concat lastmessage 132 (if (interactive-p) "done. Now save it." "done."))))) 133 134(defvar texinfo-region-buffer-name "*Info Region*" 135 "*Name of the temporary buffer used by \\[texinfo-format-region].") 136 137(defvar texinfo-pre-format-hook nil 138 "Hook called before the conversion of the Texinfo file to Info format. 139The functions on this hook are called with argument BUFFER, the buffer 140containing the Texinfo file.") 141 142;; These come from tex-mode.el. 143(defvar tex-start-of-header) 144(defvar tex-end-of-header) 145 146;;;###autoload 147(defun texinfo-format-region (region-beginning region-end) 148 "Convert the current region of the Texinfo file to Info format. 149This lets you see what that part of the file will look like in Info. 150The command is bound to \\[texinfo-format-region]. The text that is 151converted to Info is stored in a temporary buffer." 152 (interactive "r") 153 (message "Converting region to Info format...") 154 (let (texinfo-command-start 155 texinfo-command-end 156 texinfo-command-name 157 texinfo-vindex 158 texinfo-findex 159 texinfo-cindex 160 texinfo-pindex 161 texinfo-tindex 162 texinfo-kindex 163 texinfo-stack 164 (texinfo-format-filename "") 165 texinfo-example-start 166 texinfo-last-node-pos 167 texinfo-last-node 168 texinfo-node-names 169 (texinfo-footnote-number 0) 170 last-input-buffer 171 (fill-column-for-info fill-column) 172 (input-buffer (current-buffer)) 173 (input-directory default-directory) 174 (header-text "") 175 (header-beginning 1) 176 (header-end 1)) 177 178;;; Copy lines between beginning and end of header lines, 179;;; if any, or else copy the `@setfilename' line, if any. 180 (save-excursion 181 (save-restriction 182 (widen) 183 (goto-char (point-min)) 184 (let ((search-end (save-excursion (forward-line 100) (point)))) 185 (if (or 186 ;; Either copy header text. 187 (and 188 (prog1 189 (search-forward tex-start-of-header search-end t) 190 (forward-line 1) 191 ;; Mark beginning of header. 192 (setq header-beginning (point))) 193 (prog1 194 (search-forward tex-end-of-header nil t) 195 (beginning-of-line) 196 ;; Mark end of header 197 (setq header-end (point)))) 198 ;; Or copy @filename line. 199 (prog2 200 (goto-char (point-min)) 201 (search-forward "@setfilename" search-end t) 202 (beginning-of-line) 203 (setq header-beginning (point)) 204 (forward-line 1) 205 (setq header-end (point)))) 206 207 ;; Copy header 208 (setq header-text 209 (buffer-substring-no-properties 210 (min header-beginning region-beginning) 211 header-end)))))) 212 213;;; Find a buffer to use. 214 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) 215 (setq buffer-read-only t) 216 (let ((inhibit-read-only t)) 217 (erase-buffer) 218 ;; Insert the header into the buffer. 219 (insert header-text) 220 ;; Insert the region into the buffer. 221 (insert-buffer-substring 222 input-buffer 223 (max region-beginning header-end) 224 region-end) 225 (run-hook-with-args 'texinfo-pre-format-hook input-buffer) 226 ;; Make sure region ends in a newline. 227 (or (= (preceding-char) ?\n) 228 (insert "\n")) 229 230 (goto-char (point-min)) 231 (texinfo-mode) 232 (message "Converting region to Info format...") 233 (setq fill-column fill-column-for-info) 234 ;; Install a syntax table useful for scanning command operands. 235 (set-syntax-table texinfo-format-syntax-table) 236 237 ;; Insert @include files so `texinfo-raise-lower-sections' can 238 ;; work on them without losing track of multiple 239 ;; @raise/@lowersections commands. 240 (while (re-search-forward "^@include" nil t) 241 (setq texinfo-command-end (point)) 242 (let ((filename (concat input-directory 243 (texinfo-parse-line-arg)))) 244 (re-search-backward "^@include") 245 (delete-region (point) (save-excursion (forward-line 1) (point))) 246 (message "Reading included file: %s" filename) 247 (save-excursion 248 (save-restriction 249 (narrow-to-region 250 (point) 251 (+ (point) (car (cdr (insert-file-contents filename))))) 252 (goto-char (point-min)) 253 ;; Remove `@setfilename' line from included file, if any, 254 ;; so @setfilename command not duplicated. 255 (if (re-search-forward "^@setfilename" (line-end-position 100) t) 256 (delete-region (line-beginning-position 1) 257 (line-beginning-position 2))))))) 258 259 ;; Raise or lower level of each section, if necessary. 260 (goto-char (point-min)) 261 (texinfo-raise-lower-sections) 262 ;; Append @refill to appropriate paragraphs for filling. 263 (goto-char (point-min)) 264 (texinfo-append-refill) 265 ;; If the region includes the effective end of the data, 266 ;; discard everything after that. 267 (goto-char (point-max)) 268 (if (re-search-backward "^@bye" nil t) 269 (delete-region (point) (point-max))) 270 ;; Make sure buffer ends in a newline. 271 (or (= (preceding-char) ?\n) 272 (insert "\n")) 273 ;; Don't use a previous value of texinfo-enclosure-list. 274 (setq texinfo-enclosure-list nil) 275 (setq texinfo-alias-list nil) 276 277 (goto-char (point-min)) 278 (if (looking-at "\\\\input[ \t]+texinfo") 279 (delete-region (point) (line-beginning-position 2))) 280 281 ;; Insert Info region title text. 282 (goto-char (point-min)) 283 (if (search-forward 284 "@setfilename" (save-excursion (forward-line 100) (point)) t) 285 (progn 286 (setq texinfo-command-end (point)) 287 (beginning-of-line) 288 (setq texinfo-command-start (point)) 289 (let ((arg (texinfo-parse-arg-discard))) 290 (insert " " 291 texinfo-region-buffer-name 292 " buffer for: `") 293 (insert (file-name-nondirectory (expand-file-name arg))) 294 (insert "', -*-Text-*-\n"))) 295 ;; Else no `@setfilename' line 296 (insert " " 297 texinfo-region-buffer-name 298 " buffer -*-Text-*-\n")) 299 (insert "produced by `texinfo-format-region'\n" 300 "from a region in: " 301 (if (buffer-file-name input-buffer) 302 (concat "`" 303 (file-name-sans-versions 304 (file-name-nondirectory 305 (buffer-file-name input-buffer))) 306 "'") 307 (concat "buffer `" (buffer-name input-buffer) "'")) 308 "\nusing `texinfmt.el' version " 309 texinfmt-version 310 ".\n\n") 311 312 ;; Now convert for real. 313 (goto-char (point-min)) 314 (texinfo-format-scan) 315 (goto-char (point-min)) 316 (Info-tagify input-buffer) 317 (goto-char (point-min)) 318 (message "Done.")))) 319 320;;;###autoload 321(defun texi2info (&optional nosplit) 322 "Convert the current buffer (written in Texinfo code) into an Info file. 323The Info file output is generated in a buffer visiting the Info file 324names specified in the @setfilename command. 325 326This function automatically updates all node pointers and menus, and 327creates a master menu. This work is done on a temporary buffer that 328is automatically removed when the Info file is created. The original 329Texinfo source buffer is not changed. 330 331Non-nil argument (prefix, if interactive) means don't split the file 332if large. You can use Info-split to do this manually." 333 (interactive "P") 334 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" ))) 335 (message "First updating nodes and menus, then creating Info file.") 336 ;; (sit-for 2) 337 (copy-to-buffer temp-buffer (point-min) (point-max)) 338 (switch-to-buffer temp-buffer) 339 (texinfo-master-menu t) 340 (message "Now creating Info file.") 341 (sit-for 2) 342 (texinfo-format-buffer nosplit) 343 (save-buffer) 344 (kill-buffer temp-buffer))) 345 346 347;;; Primary internal formatting function for the whole buffer. 348 349(defun texinfo-format-buffer-1 () 350 (let (texinfo-format-filename 351 texinfo-example-start 352 texinfo-command-start 353 texinfo-command-end 354 texinfo-command-name 355 texinfo-last-node 356 texinfo-last-node-pos 357 texinfo-vindex 358 texinfo-findex 359 texinfo-cindex 360 texinfo-pindex 361 texinfo-tindex 362 texinfo-kindex 363 texinfo-stack 364 texinfo-node-names 365 (texinfo-footnote-number 0) 366 last-input-buffer 367 outfile 368 (fill-column-for-info fill-column) 369 (input-buffer (current-buffer)) 370 (input-directory default-directory)) 371 (setq texinfo-enclosure-list nil) 372 (setq texinfo-alias-list nil) 373 (save-excursion 374 (goto-char (point-min)) 375 (or (search-forward "@setfilename" nil t) 376 (error "Texinfo file needs an `@setfilename FILENAME' line")) 377 (setq texinfo-command-end (point)) 378 (setq outfile (texinfo-parse-line-arg))) 379 380 (find-file outfile) 381 (texinfo-mode) 382 (erase-buffer) 383 (buffer-disable-undo) 384 385 (message "Formatting Info file: %s" outfile) 386 (setq texinfo-format-filename 387 (file-name-nondirectory (expand-file-name outfile))) 388 389 (setq fill-column fill-column-for-info) 390 (set-syntax-table texinfo-format-syntax-table) 391 392 (insert-buffer-substring input-buffer) 393 (run-hook-with-args 'texinfo-pre-format-hook input-buffer) 394 (message "Converting %s to Info format..." (buffer-name input-buffer)) 395 396 ;; Insert @include files so `texinfo-raise-lower-sections' can 397 ;; work on them without losing track of multiple 398 ;; @raise/@lowersections commands. 399 (goto-char (point-min)) 400 (while (re-search-forward "^@include" nil t) 401 (setq texinfo-command-end (point)) 402 (let ((filename (concat input-directory 403 (texinfo-parse-line-arg)))) 404 (re-search-backward "^@include") 405 (delete-region (point) (line-beginning-position 2)) 406 (message "Reading included file: %s" filename) 407 (save-excursion 408 (save-restriction 409 (narrow-to-region 410 (point) 411 (+ (point) (car (cdr (insert-file-contents filename))))) 412 (goto-char (point-min)) 413 ;; Remove `@setfilename' line from included file, if any, 414 ;; so @setfilename command not duplicated. 415 (if (re-search-forward "^@setfilename" (line-end-position 100) t) 416 (delete-region (line-beginning-position 1) 417 (line-beginning-position 2))))))) 418 ;; Raise or lower level of each section, if necessary. 419 (goto-char (point-min)) 420 (texinfo-raise-lower-sections) 421 ;; Append @refill to appropriate paragraphs 422 (goto-char (point-min)) 423 (texinfo-append-refill) 424 (goto-char (point-min)) 425 (search-forward "@setfilename") 426 (beginning-of-line) 427 (delete-region (point-min) (point)) 428 ;; Remove @bye at end of file, if it is there. 429 (goto-char (point-max)) 430 (if (search-backward "@bye" nil t) 431 (delete-region (point) (point-max))) 432 ;; Make sure buffer ends in a newline. 433 (or (= (preceding-char) ?\n) 434 (insert "\n")) 435 ;; Scan the whole buffer, converting to Info format. 436 (texinfo-format-scan) 437 (goto-char (point-min)) 438 ;; Insert info about how this file was made. 439 (insert "Info file: " 440 texinfo-format-filename ", -*-Text-*-\n" 441 "produced by `texinfo-format-buffer'\n" 442 ;; Date string removed so that regression testing is easier. 443 ;; "on " 444 ;; (insert (format-time-string "%e %b %Y")) " " 445 "from file" 446 (if (buffer-file-name input-buffer) 447 (concat " `" 448 (file-name-sans-versions 449 (file-name-nondirectory 450 (buffer-file-name input-buffer))) 451 "'") 452 (concat "buffer `" (buffer-name input-buffer) "'")) 453 "\nusing `texinfmt.el' version " 454 texinfmt-version 455 ".\n\n") 456 ;; Return data for indices. 457 (list outfile 458 texinfo-vindex texinfo-findex texinfo-cindex 459 texinfo-pindex texinfo-tindex texinfo-kindex))) 460 461 462;;; Perform non-@-command file conversions: quotes and hyphens 463 464(defun texinfo-format-convert (min max) 465 ;; Convert left and right quotes to typewriter font quotes. 466 (goto-char min) 467 (while (search-forward "``" max t) 468 (replace-match "\"")) 469 (goto-char min) 470 (while (search-forward "''" max t) 471 (replace-match "\"")) 472 ;; Convert three hyphens in a row to two. 473 (goto-char min) 474 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t) 475 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning 2))))) 476 477 478;;; Handle paragraph filling 479 480;; Keep as concatinated lists for ease of maintenance 481 482(defvar texinfo-no-refill-regexp 483 (concat 484 "^@" 485 "\\(" 486 ;; add "itemize\\|" (from experiment of 2001 Nov 28) 487 ;; because of a problem with @end itemize@refill 488 ;; I don't know if this causes other problems. 489 ;; I suspect itemized lists don't get filled properly and a 490 ;; more precise fix is required. Bob 491 ;; commented out on 2005 Feb 28 by Bob 492 ;; "itemize\\|" 493 "direntry\\|" 494 "lisp\\|" 495 "smalllisp\\|" 496 "example\\|" 497 "smallexample\\|" 498 "display\\|" 499 "smalldisplay\\|" 500 "format\\|" 501 "smallformat\\|" 502 "flushleft\\|" 503 "flushright\\|" 504 "menu\\|" 505 "multitable\\|" 506 "titlepage\\|" 507 "iftex\\|" 508 "ifhtml\\|" 509 "tex\\|" 510 "html" 511 "\\)") 512 "Regexp specifying environments in which paragraphs are not filled.") 513 514(defvar texinfo-accent-commands 515 (concat 516 "@^\\|" 517 "@`\\|" 518 "@'\\|" 519 "@\"\\|" 520 "@,\\|" 521 "@=\\|" 522 "@~\\|" 523 "@OE{\\|" 524 "@oe{\\|" 525 "@AA{\\|" 526 "@aa{\\|" 527 "@AE{\\|" 528 "@ae{\\|" 529 "@ss{\\|" 530 "@questiondown{\\|" 531 "@exclamdown{\\|" 532 "@L{\\|" 533 "@l{\\|" 534 "@O{\\|" 535 "@o{\\|" 536 "@dotaccent{\\|" 537 "@ubaraccent{\\|" 538 "@d{\\|" 539 "@H{\\|" 540 "@ringaccent{\\|" 541 "@tieaccent{\\|" 542 "@u{\\|" 543 "@v{\\|" 544 "@dotless{" 545 )) 546 547(defvar texinfo-part-of-para-regexp 548 (concat 549 "^@" 550 "\\(" 551 "b{\\|" 552 "bullet{\\|" 553 "cite{\\|" 554 "code{\\|" 555 "email{\\|" 556 "emph{\\|" 557 "equiv{\\|" 558 "error{\\|" 559 "expansion{\\|" 560 "file{\\|" 561 "i{\\|" 562 "inforef{\\|" 563 "kbd{\\|" 564 "key{\\|" 565 "lisp{\\|" 566 "minus{\\|" 567 "point{\\|" 568 "print{\\|" 569 "pxref{\\|" 570 "r{\\|" 571 "ref{\\|" 572 "result{\\|" 573 "samp{\\|" 574 "sc{\\|" 575 "t{\\|" 576 "TeX{\\|" 577 "today{\\|" 578 "url{\\|" 579 "var{\\|" 580 "w{\\|" 581 "xref{\\|" 582 "@-\\|" ; @- is a descretionary hyphen (not an accent) (a noop). 583 texinfo-accent-commands 584 "\\)" 585 ) 586 "Regexp specifying @-commands found within paragraphs.") 587 588(defun texinfo-append-refill () 589 "Append @refill at end of each paragraph that should be filled. 590Do not append @refill to paragraphs within @example and similar environments. 591Do not append @refill to paragraphs containing @w{TEXT} or @*." 592 593 ;; It is necessary to append @refill before other processing because 594 ;; the other processing removes information that tells Texinfo 595 ;; whether the text should or should not be filled. 596 597 (while (< (point) (point-max)) 598 (let ((refill-blank-lines "^[ \t\n]*$") 599 (case-fold-search nil)) ; Don't confuse @TeX and @tex.... 600 (beginning-of-line) 601 ;; 1. Skip over blank lines; 602 ;; skip over lines beginning with @-commands, 603 ;; but do not skip over lines 604 ;; that are no-refill environments such as @example or 605 ;; that begin with within-paragraph @-commands such as @code. 606 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines)) 607 (not (looking-at 608 (concat 609 "\\(" 610 texinfo-no-refill-regexp 611 "\\|" 612 texinfo-part-of-para-regexp 613 "\\)"))) 614 (< (point) (point-max))) 615 (forward-line 1)) 616 ;; 2. Skip over @example and similar no-refill environments. 617 (if (looking-at texinfo-no-refill-regexp) 618 (let ((environment (match-string-no-properties 1))) 619 (progn (re-search-forward (concat "^@end " environment) nil t) 620 (forward-line 1))) 621 ;; Else 622 ;; 3. Do not refill a paragraph containing @w or @*, or ending 623 ;; with @<newline> followed by a newline. 624 (if (or (>= (point) (point-max)) 625 (re-search-forward 626 "@w{\\|@\\*\\|@\n\n" 627 (save-excursion (forward-paragraph) (forward-line 1) (point)) 628 t)) 629 ;; Go to end of paragraph and do nothing. 630 (forward-paragraph) 631 ;; 4. Else go to end of paragraph and insert @refill 632 (forward-paragraph) 633 (forward-line -1) 634 (let ((line-beg (point))) 635 (end-of-line) 636 (delete-region 637 (point) 638 (save-excursion (skip-chars-backward " \t") (point))) 639 (forward-char 1) 640 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t) 641 (forward-char -1)) 642 (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t) 643 (insert "@refill"))) 644 (forward-line 1)))))) 645 646 647;;; Handle `@raisesections' and `@lowersections' commands 648 649;; These commands change the hierarchical level of chapter structuring 650;; commands. 651;; 652;; @raisesections changes @subsection to @section, 653;; @section to @chapter, 654;; etc. 655;; 656;; @lowersections changes @chapter to @section 657;; @subsection to @subsubsection, 658;; etc. 659;; 660;; An @raisesections/@lowersections command changes only those 661;; structuring commands that follow the @raisesections/@lowersections 662;; command. 663;; 664;; Repeated @raisesections/@lowersections continue to raise or lower 665;; the heading level. 666;; 667;; An @lowersections command cancels an @raisesections command, and 668;; vice versa. 669;; 670;; You cannot raise or lower "beyond" chapters or subsubsections, but 671;; trying to do so does not elicit an error---you just get more 672;; headings that mean the same thing as you keep raising or lowering 673;; (for example, after a single @raisesections, both @chapter and 674;; @section produce chapter headings). 675 676(defun texinfo-raise-lower-sections () 677 "Raise or lower the hierarchical level of chapters, sections, etc. 678 679This function acts according to `@raisesections' and `@lowersections' 680commands in the Texinfo file. 681 682For example, an `@lowersections' command is useful if you wish to 683include what is written as an outer or standalone Texinfo file in 684another Texinfo file as an inner, included file. The `@lowersections' 685command changes chapters to sections, sections to subsections and so 686on. 687 688@raisesections changes @subsection to @section, 689 @section to @chapter, 690 @heading to @chapheading, 691 etc. 692 693@lowersections changes @chapter to @section, 694 @subsection to @subsubsection, 695 @heading to @subheading, 696 etc. 697 698An `@raisesections' or `@lowersections' command changes only those 699structuring commands that follow the `@raisesections' or 700`@lowersections' command. 701 702An `@lowersections' command cancels an `@raisesections' command, and 703vice versa. 704 705Repeated use of the commands continue to raise or lower the hierarchical 706level a step at a time. 707 708An attempt to raise above `chapters' reproduces chapter commands; an 709attempt to lower below subsubsections reproduces subsubsection 710commands." 711 712 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el'; 713 ;; it is a regexp matching chapter, section, other headings 714 ;; (but not the top node). 715 716 (let (type (level 0)) 717 (while 718 (re-search-forward 719 (concat 720 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\(" 721 texinfo-section-types-regexp 722 "\\)\\)") 723 nil t) 724 (beginning-of-line) 725 (save-excursion (setq type (read (current-buffer)))) 726 (cond 727 728 ;; 1. Increment level 729 ((eq type '@raisesections) 730 (setq level (1+ level)) 731 (delete-region 732 (point) (save-excursion (forward-line 1) (point)))) 733 734 ;; 2. Decrement level 735 ((eq type '@lowersections) 736 (setq level (1- level)) 737 (delete-region 738 (point) (save-excursion (forward-line 1) (point)))) 739 740 ;; Now handle structuring commands 741 ((cond 742 743 ;; 3. Raise level when positive 744 ((> level 0) 745 (let ((count level) 746 (new-level type)) 747 (while (> count 0) 748 (setq new-level 749 (cdr (assq new-level texinfo-raisesections-alist))) 750 (setq count (1- count))) 751 (kill-word 1) 752 (insert (symbol-name new-level)))) 753 754 ;; 4. Do nothing except move point when level is zero 755 ((= level 0) (forward-line 1)) 756 757 ;; 5. Lower level when positive 758 ((< level 0) 759 (let ((count level) 760 (new-level type)) 761 (while (< count 0) 762 (setq new-level 763 (cdr (assq new-level texinfo-lowersections-alist))) 764 (setq count (1+ count))) 765 (kill-word 1) 766 (insert (symbol-name new-level)))))))))) 767 768(defvar texinfo-raisesections-alist 769 '((@chapter . @chapter) ; Cannot go higher 770 (@unnumbered . @unnumbered) 771 (@centerchap . @unnumbered) 772 773 (@majorheading . @majorheading) 774 (@chapheading . @chapheading) 775 (@appendix . @appendix) 776 777 (@section . @chapter) 778 (@unnumberedsec . @unnumbered) 779 (@heading . @chapheading) 780 (@appendixsec . @appendix) 781 782 (@subsection . @section) 783 (@unnumberedsubsec . @unnumberedsec) 784 (@subheading . @heading) 785 (@appendixsubsec . @appendixsec) 786 787 (@subsubsection . @subsection) 788 (@unnumberedsubsubsec . @unnumberedsubsec) 789 (@subsubheading . @subheading) 790 (@appendixsubsubsec . @appendixsubsec)) 791 "*An alist of next higher levels for chapters, sections. etc. 792For example, section to chapter, subsection to section. 793Used by `texinfo-raise-lower-sections'. 794The keys specify types of section; the values correspond to the next 795higher types.") 796 797(defvar texinfo-lowersections-alist 798 '((@chapter . @section) 799 (@unnumbered . @unnumberedsec) 800 (@centerchap . @unnumberedsec) 801 (@majorheading . @heading) 802 (@chapheading . @heading) 803 (@appendix . @appendixsec) 804 805 (@section . @subsection) 806 (@unnumberedsec . @unnumberedsubsec) 807 (@heading . @subheading) 808 (@appendixsec . @appendixsubsec) 809 810 (@subsection . @subsubsection) 811 (@unnumberedsubsec . @unnumberedsubsubsec) 812 (@subheading . @subsubheading) 813 (@appendixsubsec . @appendixsubsubsec) 814 815 (@subsubsection . @subsubsection) ; Cannot go lower. 816 (@unnumberedsubsubsec . @unnumberedsubsubsec) 817 (@subsubheading . @subsubheading) 818 (@appendixsubsubsec . @appendixsubsubsec)) 819 "*An alist of next lower levels for chapters, sections. etc. 820For example, chapter to section, section to subsection. 821Used by `texinfo-raise-lower-sections'. 822The keys specify types of section; the values correspond to the next 823lower types.") 824 825 826;;; Perform those texinfo-to-info conversions that apply to the whole input 827;;; uniformly. 828 829(defun texinfo-format-scan () 830 (texinfo-format-convert (point-min) (point-max)) 831 ;; Search for @copying, which has to be first since the 832 ;; @insertcopying command then inserts the text elsewhere. 833 (goto-char (point-min)) 834 (when (search-forward "@copying" nil t) 835 (texinfo-copying)) 836 (while (search-forward "@insertcopying" nil t) 837 (delete-region (match-beginning 0) (match-end 0)) 838 839 (texinfo-insertcopying)) 840 ;; Scan for other @-commands. 841 (goto-char (point-min)) 842 (while (search-forward "@" nil t) 843 ;; 844 ;; These are the single-character accent commands: @^ @` @' @" @= @~ 845 ;; In Info, they are simply quoted and the @ deleted. 846 ;; Other single-character commands: 847 ;; @* forces a line break, 848 ;; @- is a discretionary hyphenation point; does nothing in Info. 849 ;; @<space>, @<tab>, @<newline> each produce a single space, 850 ;; unless followed by a newline. 851 ;; 852 ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]") 853 (if (looking-at "[@{}^'`\"=~ \t\n*?!-]") 854 ;; @*, causes a line break. 855 (cond 856 ;; @*, a line break 857 ((= (following-char) ?*) 858 ;; remove command 859 (delete-region (1- (point)) (1+ (point))) 860 ;; insert return if not at end of line; 861 ;; else line is already broken. 862 (if (not (= (following-char) ?\n)) 863 (insert ?\n))) 864 ;; @-, deleted 865 ((= (following-char) ?-) 866 (delete-region (1- (point)) (1+ (point)))) 867 ;; @<space>, @<tab>, @<newline>: produce a single space, 868 ;; unless followed by a newline. 869 ((= (following-char) ? ) 870 (delete-region (1- (point)) (1+ (point))) 871 ;; insert single space if not at end of line; 872 ;; else line is already broken. 873 (if (not (= (following-char) ?\n)) 874 (insert ? ))) 875 ((= (following-char) ?\t) 876 (delete-region (1- (point)) (1+ (point))) 877 ;; insert single space if not at end of line; 878 ;; else line is already broken. 879 (if (not (= (following-char) ?\n)) 880 (insert ? ))) 881 ;; following char is a carriage return 882 ((= (following-char) ?\n) 883 ;; remove command 884 (delete-region (1- (point)) (1+ (point))) 885 ;; insert single space if not at end of line; 886 ;; else line is already broken. 887 (if (not (= (following-char) ?\n)) 888 (insert ? ))) 889 ;; Otherwise: the other characters are simply quoted. Delete the @. 890 (t 891 (delete-char -1) 892 ;; Be compatible with makeinfo: if @' and its ilk are 893 ;; followed by a @ without a brace, barf. 894 (if (looking-at "[\"'^`~=]") 895 (progn 896 (if (= (char-after (1+ (point))) ?@) 897 (error "Use braces to give a command as an argument to @%c" 898 (following-char))) 899 (forward-char 1) 900 ;; @' etc. can optionally accept their argument in 901 ;; braces (makeinfo supports that). 902 (when (looking-at "{") 903 (let ((start (point))) 904 (forward-list 1) 905 (delete-char -1) 906 (goto-char start) 907 (delete-char 1)))) 908 (forward-char 1)))) 909 ;; @ is followed by a command-word; find the end of the word. 910 (setq texinfo-command-start (1- (point))) 911 (if (= (char-syntax (following-char)) ?w) 912 (forward-word 1) 913 (forward-char 1)) 914 (setq texinfo-command-end (point)) 915 ;; Detect the case of two @-commands in a row; 916 ;; process just the first one. 917 (goto-char (1+ texinfo-command-start)) 918 (skip-chars-forward "^@" texinfo-command-end) 919 (setq texinfo-command-end (point)) 920 ;; Handle let aliasing 921 (setq texinfo-command-name 922 (let (trial 923 (cmdname 924 (buffer-substring-no-properties 925 (1+ texinfo-command-start) texinfo-command-end))) 926 (while (setq trial (assoc cmdname texinfo-alias-list)) 927 (setq cmdname (cdr trial))) 928 (intern cmdname))) 929 ;; Call the handler for this command. 930 (let ((enclosure-type 931 (assoc 932 (symbol-name texinfo-command-name) 933 texinfo-enclosure-list))) 934 (if enclosure-type 935 (progn 936 (insert 937 (car (car (cdr enclosure-type))) 938 (texinfo-parse-arg-discard) 939 (car (cdr (car (cdr enclosure-type))))) 940 (goto-char texinfo-command-start)) 941 (let ((cmd (get texinfo-command-name 'texinfo-format))) 942 (if cmd (funcall cmd) (texinfo-unsupported))))))) 943 944 (cond (texinfo-stack 945 (goto-char (nth 2 (car texinfo-stack))) 946 (error "Unterminated @%s" (car (car texinfo-stack))))) 947 948 ;; Remove excess whitespace 949 (let ((whitespace-silent t)) 950 (whitespace-cleanup))) 951 952(defvar texinfo-copying-text "" 953 "Text of the copyright notice and copying permissions.") 954 955(defun texinfo-copying () 956 "Copy the copyright notice and copying permissions from the Texinfo file, 957as indicated by the @copying ... @end copying command; 958insert the text with the @insertcopying command." 959 (let ((beg (progn (beginning-of-line) (point))) 960 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point)))) 961 (setq texinfo-copying-text 962 (buffer-substring-no-properties 963 (save-excursion (goto-char beg) (forward-line 1) (point)) 964 (save-excursion (goto-char end) (forward-line -1) (point)))) 965 (delete-region beg end))) 966 967(defun texinfo-insertcopying () 968 "Insert the copyright notice and copying permissions from the Texinfo file, 969which are indicated by the @copying ... @end copying command." 970 (insert (concat "\n" texinfo-copying-text))) 971 972(put 'begin 'texinfo-format 'texinfo-format-begin) 973(defun texinfo-format-begin () 974 (texinfo-format-begin-end 'texinfo-format)) 975 976(put 'end 'texinfo-format 'texinfo-format-end) 977(defun texinfo-format-end () 978 (texinfo-format-begin-end 'texinfo-end)) 979 980(defun texinfo-format-begin-end (prop) 981 (setq texinfo-command-name (intern (texinfo-parse-line-arg))) 982 (let ((cmd (get texinfo-command-name prop))) 983 (if cmd (funcall cmd) 984 (texinfo-unsupported)))) 985 986;;; Parsing functions 987 988(defun texinfo-parse-line-arg () 989 "Return argument of @-command as string. 990Argument is separated from command either by a space or by a brace. 991If a space, return rest of line, with beginning and ending white 992space removed. If a brace, return string between braces. 993Leave point after argument." 994 (goto-char texinfo-command-end) 995 (let ((start (point))) 996 (cond ((looking-at " ") 997 (skip-chars-forward " ") 998 (setq start (point)) 999 (end-of-line) 1000 (skip-chars-backward " ") 1001 (delete-region (point) (progn (end-of-line) (point))) 1002 (setq texinfo-command-end (1+ (point)))) 1003 ((looking-at "{") 1004 (setq start (1+ (point))) 1005 (forward-list 1) 1006 (setq texinfo-command-end (point)) 1007 (forward-char -1)) 1008 (t 1009 (error "Invalid texinfo command arg format"))) 1010 (prog1 (buffer-substring-no-properties start (point)) 1011 (if (eolp) (forward-char 1))))) 1012 1013(defun texinfo-parse-expanded-arg () 1014 (goto-char texinfo-command-end) 1015 (let ((start (point)) 1016 marker) 1017 (cond ((looking-at " ") 1018 (skip-chars-forward " ") 1019 (setq start (point)) 1020 (end-of-line) 1021 (setq texinfo-command-end (1+ (point)))) 1022 ((looking-at "{") 1023 (setq start (1+ (point))) 1024 (forward-list 1) 1025 (setq texinfo-command-end (point)) 1026 (forward-char -1)) 1027 (t 1028 (error "Invalid texinfo command arg format"))) 1029 (setq marker (move-marker (make-marker) texinfo-command-end)) 1030 (texinfo-format-expand-region start (point)) 1031 (setq texinfo-command-end (marker-position marker)) 1032 (move-marker marker nil) 1033 (prog1 (buffer-substring-no-properties start (point)) 1034 (if (eolp) (forward-char 1))))) 1035 1036(defun texinfo-format-expand-region (start end) 1037 (save-restriction 1038 (narrow-to-region start end) 1039 (let (texinfo-command-start 1040 texinfo-command-end 1041 texinfo-command-name 1042 texinfo-stack) 1043 (texinfo-format-scan)) 1044 (goto-char (point-max)))) 1045 1046(defun texinfo-parse-arg-discard () 1047 "Delete command and argument; return argument of command." 1048 (prog1 (texinfo-parse-line-arg) 1049 (texinfo-discard-command))) 1050 1051(defun texinfo-discard-command () 1052 (delete-region texinfo-command-start texinfo-command-end)) 1053 1054(defun texinfo-optional-braces-discard () 1055 "Discard braces following command, if any." 1056 (goto-char texinfo-command-end) 1057 (let ((start (point))) 1058 (cond ((looking-at "[ \t]*\n")) ; do nothing 1059 ((looking-at "{") ; remove braces, if any 1060 (forward-list 1) 1061 (setq texinfo-command-end (point))) 1062 (t 1063 (error 1064 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)"))) 1065 (delete-region texinfo-command-start texinfo-command-end))) 1066 1067(defun texinfo-format-parse-line-args () 1068 (let ((start (1- (point))) 1069 next beg end 1070 args) 1071 (skip-chars-forward " ") 1072 (while (not (eolp)) 1073 (setq beg (point)) 1074 (re-search-forward "[\n,]") 1075 (setq next (point)) 1076 (if (bolp) (setq next (1- next))) 1077 (forward-char -1) 1078 (skip-chars-backward " ") 1079 (setq end (point)) 1080 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end)) 1081 args)) 1082 (goto-char next) 1083 (skip-chars-forward " ")) 1084 (if (eolp) (forward-char 1)) 1085 (setq texinfo-command-end (point)) 1086 (nreverse args))) 1087 1088(defun texinfo-format-parse-args () 1089 (let ((start (1- (point))) 1090 next beg end 1091 args) 1092 (search-forward "{") 1093 (save-excursion 1094 (texinfo-format-expand-region 1095 (point) 1096 (save-excursion (up-list 1) (1- (point))))) 1097 ;; The following does not handle cross references of the form: 1098 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the 1099 ;; re-search-forward finds the first right brace after the second 1100 ;; comma. 1101 (while (/= (preceding-char) ?\}) 1102 (skip-chars-forward " \t\n") 1103 (setq beg (point)) 1104 (re-search-forward "[},]") 1105 (setq next (point)) 1106 (forward-char -1) 1107 (skip-chars-backward " \t\n") 1108 (setq end (point)) 1109 (cond ((< beg end) 1110 (goto-char beg) 1111 (while (search-forward "\n" end t) 1112 (replace-match " ")))) 1113 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end)) 1114 args)) 1115 (goto-char next)) 1116 ;;(if (eolp) (forward-char 1)) 1117 (setq texinfo-command-end (point)) 1118 (nreverse args))) 1119 1120(defun texinfo-format-parse-defun-args () 1121 (goto-char texinfo-command-end) 1122 (let ((start (point))) 1123 (end-of-line) 1124 (setq texinfo-command-end (1+ (point))) 1125 (let ((marker (move-marker (make-marker) texinfo-command-end))) 1126 (texinfo-format-expand-region start (point)) 1127 (setq texinfo-command-end (marker-position marker)) 1128 (move-marker marker nil)) 1129 (goto-char start) 1130 (let ((args '()) 1131 beg end) 1132 (skip-chars-forward " ") 1133 (while (not (eolp)) 1134 (cond ((looking-at "{") 1135 (setq beg (1+ (point))) 1136 (forward-list 1) 1137 (setq end (1- (point)))) 1138 (t 1139 (setq beg (point)) 1140 (re-search-forward "[\n ]") 1141 (forward-char -1) 1142 (setq end (point)))) 1143 (setq args (cons (buffer-substring-no-properties beg end) args)) 1144 (skip-chars-forward " ")) 1145 (forward-char 1) 1146 (nreverse args)))) 1147 1148(defun texinfo-discard-line () 1149 (goto-char texinfo-command-end) 1150 (skip-chars-forward " \t") 1151 (or (eolp) 1152 (error "Extraneous text at end of command line")) 1153 (goto-char texinfo-command-start) 1154 (or (bolp) 1155 (error "Extraneous text at beginning of command line")) 1156 (delete-region (point) (progn (forward-line 1) (point)))) 1157 1158(defun texinfo-discard-line-with-args () 1159 (goto-char texinfo-command-start) 1160 (delete-region (point) (progn (forward-line 1) (point)))) 1161 1162 1163;;; @setfilename 1164 1165;; Only `texinfo-format-buffer' handles @setfilename with this 1166;; definition; `texinfo-format-region' handles @setfilename, if any, 1167;; specially. 1168(put 'setfilename 'texinfo-format 'texinfo-format-setfilename) 1169(defun texinfo-format-setfilename () 1170 (texinfo-parse-arg-discard)) 1171 1172;;; @node, @menu, @detailmenu 1173 1174(put 'node 'texinfo-format 'texinfo-format-node) 1175(put 'nwnode 'texinfo-format 'texinfo-format-node) 1176(defun texinfo-format-node () 1177 (let* ((args (texinfo-format-parse-line-args)) 1178 (name (nth 0 args)) 1179 (next (nth 1 args)) 1180 (prev (nth 2 args)) 1181 (up (nth 3 args))) 1182 (texinfo-discard-command) 1183 (setq texinfo-last-node name) 1184 (let ((tem (if texinfo-fold-nodename-case (downcase name) name))) 1185 (if (assoc tem texinfo-node-names) 1186 (error "Duplicate node name: %s" name) 1187 (setq texinfo-node-names (cons (list tem) texinfo-node-names)))) 1188 (setq texinfo-footnote-number 0) 1189 ;; insert "\n\^_" unconditionally since this is what info is looking for 1190 (insert "\n\^_\nFile: " texinfo-format-filename 1191 ", Node: " name) 1192 (if next 1193 (insert ", Next: " next)) 1194 (if prev 1195 (insert ", Prev: " prev)) 1196 (if up 1197 (insert ", Up: " up)) 1198 (insert ?\n) 1199 (setq texinfo-last-node-pos (point)))) 1200 1201(put 'anchor 'texinfo-format 'texinfo-anchor) 1202(defun texinfo-anchor () 1203 (let (anchor-string 1204 (here (- (point) 7)) ; save location of beginning of `@anchor' 1205 (arg (texinfo-parse-arg-discard))) 1206 (if (looking-at " ") ; since a space may be left after -discard 1207 (delete-char 1)) 1208 (forward-paragraph) 1209 (let ((end (point))) 1210 (if (save-excursion 1211 (backward-word 1) 1212 (search-forward "@refill" end t)) 1213 (setq anchor-string "@anchor-yes-refill") 1214 (setq anchor-string "@anchor-no-refill"))) 1215 (goto-char here) 1216 (insert anchor-string "{" arg "}"))) 1217 1218(put 'menu 'texinfo-format 'texinfo-format-menu) 1219(defun texinfo-format-menu () 1220 (texinfo-discard-line) 1221 (insert "* Menu:\n\n")) 1222 1223(put 'menu 'texinfo-end 'texinfo-discard-command) 1224 1225;; The @detailmenu should be removed eventually. 1226 1227;; According to Karl Berry, 31 August 1996: 1228;; 1229;; You don't like, I don't like it. I agree, it would be better just to 1230;; fix the bug [in `makeinfo']. .. At this point, since inserting those 1231;; two commands in the Elisp fn is trivial, I don't especially want to 1232;; expend more effort... 1233;; 1234;; I added a couple sentences of documentation to the manual (putting the 1235;; blame on makeinfo where it belongs :-(). 1236 1237(put 'detailmenu 'texinfo-format 'texinfo-discard-line) 1238(put 'detailmenu 'texinfo-end 'texinfo-discard-command) 1239 1240;; (Also see `texnfo-upd.el') 1241 1242 1243;;; Cross references 1244 1245;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT} 1246;; -> *Note FNAME: (FILE)NODE 1247;; If FILE is missing, 1248;; *Note FNAME: NODE 1249;; If FNAME is empty and NAME is present 1250;; *Note NAME: Node 1251;; If both NAME and FNAME are missing 1252;; *Note NODE:: 1253;; texinfo ignores the DOCUMENT argument. 1254;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE> 1255;; If FILE is specified, (FILE)NODE is used for xrefs. 1256;; If fifth argument DOCUMENT is specified, produces 1257;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE> 1258;; of DOCUMENT 1259 1260;; @ref a reference that does not put `See' or `see' in 1261;; the hardcopy and is the same as @xref in Info 1262(put 'ref 'texinfo-format 'texinfo-format-xref) 1263 1264(put 'xref 'texinfo-format 'texinfo-format-xref) 1265(defun texinfo-format-xref () 1266 (let ((args (texinfo-format-parse-args))) 1267 (texinfo-discard-command) 1268 (insert "*Note ") 1269 (let ((fname (or (nth 1 args) (nth 2 args)))) 1270 (if (null (or fname (nth 3 args))) 1271 (insert (car args) "::") 1272 (insert (or fname (car args)) ": ") 1273 (if (nth 3 args) 1274 (insert "(" (nth 3 args) ")")) 1275 (and (car args) (insert (car args))))))) 1276 1277(put 'pxref 'texinfo-format 'texinfo-format-pxref) 1278(defun texinfo-format-pxref () 1279 (texinfo-format-xref) 1280 (or (save-excursion 1281 (forward-char -2) 1282 (looking-at "::")) 1283 (insert "."))) 1284 1285;; @inforef{NODE, FNAME, FILE} 1286;; Like @xref{NODE, FNAME,,FILE} in texinfo. 1287;; In Tex, generates "See Info file FILE, node NODE" 1288(put 'inforef 'texinfo-format 'texinfo-format-inforef) 1289(defun texinfo-format-inforef () 1290 (let ((args (texinfo-format-parse-args))) 1291 (texinfo-discard-command) 1292 (if (nth 1 args) 1293 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args)) 1294 (insert "*Note " "(" (nth 2 args) ")" (car args) "::")))) 1295 1296 1297;;; URL Reference: @uref 1298 1299;; @uref produces a reference to a uniform resource locator (URL). 1300;; It takes one mandatory argument, the URL, and one optional argument, 1301;; the text to display (the default is the URL itself). 1302 1303(put 'uref 'texinfo-format 'texinfo-format-uref) 1304(defun texinfo-format-uref () 1305 "Format URL and optional URL-TITLE. 1306Insert ` ... ' around URL if no URL-TITLE argument; 1307otherwise, insert URL-TITLE followed by URL in parentheses." 1308 (let ((args (texinfo-format-parse-args))) 1309 (texinfo-discard-command) 1310 ;; if url-title 1311 (if (nth 1 args) 1312 (insert (nth 1 args) " (" (nth 0 args) ")") 1313 (insert "`" (nth 0 args) "'")) 1314 (goto-char texinfo-command-start))) 1315 1316 1317;;; Section headings 1318 1319(put 'majorheading 'texinfo-format 'texinfo-format-chapter) 1320(put 'chapheading 'texinfo-format 'texinfo-format-chapter) 1321(put 'ichapter 'texinfo-format 'texinfo-format-chapter) 1322(put 'chapter 'texinfo-format 'texinfo-format-chapter) 1323(put 'iappendix 'texinfo-format 'texinfo-format-chapter) 1324(put 'appendix 'texinfo-format 'texinfo-format-chapter) 1325(put 'iunnumbered 'texinfo-format 'texinfo-format-chapter) 1326(put 'top 'texinfo-format 'texinfo-format-chapter) 1327(put 'unnumbered 'texinfo-format 'texinfo-format-chapter) 1328(put 'centerchap 'texinfo-format 'texinfo-format-chapter) 1329(defun texinfo-format-chapter () 1330 (texinfo-format-chapter-1 ?*)) 1331 1332(put 'heading 'texinfo-format 'texinfo-format-section) 1333(put 'isection 'texinfo-format 'texinfo-format-section) 1334(put 'section 'texinfo-format 'texinfo-format-section) 1335(put 'iappendixsection 'texinfo-format 'texinfo-format-section) 1336(put 'appendixsection 'texinfo-format 'texinfo-format-section) 1337(put 'iappendixsec 'texinfo-format 'texinfo-format-section) 1338(put 'appendixsec 'texinfo-format 'texinfo-format-section) 1339(put 'iunnumberedsec 'texinfo-format 'texinfo-format-section) 1340(put 'unnumberedsec 'texinfo-format 'texinfo-format-section) 1341(defun texinfo-format-section () 1342 (texinfo-format-chapter-1 ?=)) 1343 1344(put 'subheading 'texinfo-format 'texinfo-format-subsection) 1345(put 'isubsection 'texinfo-format 'texinfo-format-subsection) 1346(put 'subsection 'texinfo-format 'texinfo-format-subsection) 1347(put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection) 1348(put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection) 1349(put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection) 1350(put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection) 1351(defun texinfo-format-subsection () 1352 (texinfo-format-chapter-1 ?-)) 1353 1354(put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection) 1355(put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection) 1356(put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection) 1357(put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) 1358(put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection) 1359(put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) 1360(put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection) 1361(defun texinfo-format-subsubsection () 1362 (texinfo-format-chapter-1 ?.)) 1363 1364(defun texinfo-format-chapter-1 (belowchar) 1365 (let ((arg (texinfo-parse-arg-discard))) 1366 (message "Formatting: %s ... " arg) ; So we can see where we are. 1367 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n) 1368 (forward-line -2))) 1369 1370(put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad) 1371(defun texinfo-format-sectionpad () 1372 (let ((str (texinfo-parse-arg-discard))) 1373 (forward-char -1) 1374 (let ((column (current-column))) 1375 (forward-char 1) 1376 (while (> column 0) 1377 (insert str) 1378 (setq column (1- column)))) 1379 (insert ?\n))) 1380 1381 1382;;; Space controlling commands: @. and @:, and the soft hyphen. 1383 1384(put '\. 'texinfo-format 'texinfo-format-\.) 1385(defun texinfo-format-\. () 1386 (texinfo-discard-command) 1387 (insert ".")) 1388 1389(put '\: 'texinfo-format 'texinfo-format-\:) 1390(defun texinfo-format-\: () 1391 (texinfo-discard-command)) 1392 1393(put '\- 'texinfo-format 'texinfo-format-soft-hyphen) 1394(defun texinfo-format-soft-hyphen () 1395 (texinfo-discard-command)) 1396 1397 1398;;; @kbdinputstyle, @vskip, headings & footings 1399;; These commands for not for Info and should never 1400;; appear in an Info environment; but if they do, 1401;; this causes them to be discarded. 1402 1403;; @kbdinputstyle 1404(put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args) 1405 1406;; @vskip 1407(put 'vskip 'texinfo-format 'texinfo-discard-line-with-args) 1408 1409;; headings & footings 1410(put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args) 1411(put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args) 1412(put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args) 1413(put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args) 1414(put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args) 1415(put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args) 1416 1417 1418;;; @documentdescription ... @end documentdescription 1419;; This command is for HTML output and should never 1420;; appear in an Info environment; but if it does, 1421;; this causes it to be discarded. 1422 1423(put 'documentdescription 'texinfo-format 'texinfo-format-documentdescription) 1424(defun texinfo-format-documentdescription () 1425 (delete-region texinfo-command-start 1426 (progn (re-search-forward "^@end documentdescription[ \t]*\n") 1427 (point)))) 1428 1429 1430 1431;;; @center, @sp, and @br 1432 1433(put 'center 'texinfo-format 'texinfo-format-center) 1434(defun texinfo-format-center () 1435 (let ((arg (texinfo-parse-expanded-arg))) 1436 (texinfo-discard-command) 1437 (insert arg) 1438 (insert ?\n) 1439 (save-restriction 1440 (goto-char (1- (point))) 1441 (let ((indent-tabs-mode nil)) 1442 (center-line))))) 1443 1444(put 'sp 'texinfo-format 'texinfo-format-sp) 1445(defun texinfo-format-sp () 1446 (let* ((arg (texinfo-parse-arg-discard)) 1447 (num (read arg))) 1448 (insert-char ?\n num))) 1449 1450(put 'br 'texinfo-format 'texinfo-format-paragraph-break) 1451(defun texinfo-format-paragraph-break () 1452 "Force a paragraph break. 1453If used within a line, follow `@br' with braces." 1454 (texinfo-optional-braces-discard) 1455 ;; insert one return if at end of line; 1456 ;; else insert two returns, to generate a blank line. 1457 (if (= (following-char) ?\n) 1458 (insert ?\n) 1459 (insert-char ?\n 2))) 1460 1461 1462;;; @footnote and @footnotestyle 1463 1464;; In Texinfo, footnotes are created with the `@footnote' command. 1465;; This command is followed immediately by a left brace, then by the text of 1466;; the footnote, and then by a terminating right brace. The 1467;; template for a footnote is: 1468;; 1469;; @footnote{TEXT} 1470;; 1471;; Info has two footnote styles: 1472;; 1473;; * In the End of node style, all the footnotes for a single node 1474;; are placed at the end of that node. The footnotes are 1475;; separated from the rest of the node by a line of dashes with 1476;; the word `Footnotes' within it. 1477;; 1478;; * In the Separate node style, all the footnotes for a single node 1479;; are placed in an automatically constructed node of their own. 1480 1481;; Footnote style is specified by the @footnotestyle command, either 1482;; @footnotestyle separate 1483;; or 1484;; @footnotestyle end 1485;; 1486;; The default is separate 1487 1488(defvar texinfo-footnote-style "separate" 1489 "Footnote style, either separate or end.") 1490 1491(put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle) 1492(defun texinfo-footnotestyle () 1493 "Specify whether footnotes are at end of node or in separate nodes. 1494Argument is either end or separate." 1495 (setq texinfo-footnote-style (texinfo-parse-arg-discard))) 1496 1497(defvar texinfo-footnote-number) 1498 1499(put 'footnote 'texinfo-format 'texinfo-format-footnote) 1500(defun texinfo-format-footnote () 1501 "Format a footnote in either end of node or separate node style. 1502The texinfo-footnote-style variable controls which style is used." 1503 (setq texinfo-footnote-number (1+ texinfo-footnote-number)) 1504 (cond ((string= texinfo-footnote-style "end") 1505 (texinfo-format-end-node)) 1506 ((string= texinfo-footnote-style "separate") 1507 (texinfo-format-separate-node)))) 1508 1509(defun texinfo-format-separate-node () 1510 "Format footnote in Separate node style, with notes in own node. 1511The node is constructed automatically." 1512 (let* (start 1513 (arg (texinfo-parse-line-arg)) 1514 (node-name-beginning 1515 (save-excursion 1516 (re-search-backward 1517 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:") 1518 (match-end 0))) 1519 (node-name 1520 (save-excursion 1521 (buffer-substring-no-properties 1522 (progn (goto-char node-name-beginning) ; skip over node command 1523 (skip-chars-forward " \t") ; and over spaces 1524 (point)) 1525 (if (search-forward 1526 "," 1527 (save-excursion (end-of-line) (point)) t) ; bound search 1528 (1- (point)) 1529 (end-of-line) (point)))))) 1530 (texinfo-discard-command) ; remove or insert whitespace, as needed 1531 (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) 1532 (point)) 1533 (insert (format " (%d) (*Note %s-Footnotes::)" 1534 texinfo-footnote-number node-name)) 1535 (fill-paragraph nil) 1536 (save-excursion 1537 (if (re-search-forward "^@node" nil 'move) 1538 (forward-line -1)) 1539 1540 ;; two cases: for the first footnote, we must insert a node header; 1541 ;; for the second and subsequent footnotes, we need only insert 1542 ;; the text of the footnote. 1543 1544 (if (save-excursion 1545 (search-backward 1546 (concat node-name "-Footnotes, Up: ") 1547 node-name-beginning 1548 t)) 1549 (progn ; already at least one footnote 1550 (setq start (point)) 1551 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) 1552 (fill-region start (point))) 1553 ;; else not yet a footnote 1554 (insert "\n\^_\nFile: " texinfo-format-filename 1555 " Node: " node-name "-Footnotes, Up: " node-name "\n") 1556 (setq start (point)) 1557 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) 1558 (narrow-to-region (save-excursion (goto-char start) (point)) (point)) 1559 (fill-region (point-min) (point-max)) 1560 (widen))))) 1561 1562(defun texinfo-format-end-node () 1563 "Format footnote in the End of node style, with notes at end of node." 1564 (let (start 1565 (arg (texinfo-parse-line-arg))) 1566 (texinfo-discard-command) ; remove or insert whitespace, as needed 1567 (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) 1568 (point)) 1569 (insert (format " (%d) " texinfo-footnote-number)) 1570 (fill-paragraph nil) 1571 (save-excursion 1572 (if (search-forward "\n--------- Footnotes ---------\n" nil t) 1573 (progn ; already have footnote, put new one before end of node 1574 (if (re-search-forward "^@node" nil 'move) 1575 (forward-line -1)) 1576 (setq start (point)) 1577 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)) 1578 (fill-region start (point))) 1579 ;; else no prior footnote 1580 (if (re-search-forward "^@node" nil 'move) 1581 (forward-line -1)) 1582 (insert "\n--------- Footnotes ---------\n") 1583 (setq start (point)) 1584 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg)))))) 1585 1586 1587;;; @itemize, @enumerate, and similar commands 1588 1589;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack. 1590;; @enumerate pushes (enumerate 0 STARTPOS). 1591;; @item dispatches to the texinfo-item prop of the first elt of the list. 1592;; For itemize, this puts in and rescans the COMMANDS. 1593;; For enumerate, this increments the number and puts it in. 1594;; In either case, it puts a Backspace at the front of the line 1595;; which marks it not to be indented later. 1596;; All other lines get indented by 5 when the @end is reached. 1597 1598(defvar texinfo-stack-depth 0 1599 "Count of number of unpopped texinfo-push-stack calls. 1600Used by @refill indenting command to avoid indenting within lists, etc.") 1601 1602(defun texinfo-push-stack (check arg) 1603 (setq texinfo-stack-depth (1+ texinfo-stack-depth)) 1604 (setq texinfo-stack 1605 (cons (list check arg texinfo-command-start) 1606 texinfo-stack))) 1607 1608(defun texinfo-pop-stack (check) 1609 (setq texinfo-stack-depth (1- texinfo-stack-depth)) 1610 (if (null texinfo-stack) 1611 (error "Unmatched @end %s" check)) 1612 (if (not (eq (car (car texinfo-stack)) check)) 1613 (error "@end %s matches @%s" 1614 check (car (car texinfo-stack)))) 1615 (prog1 (cdr (car texinfo-stack)) 1616 (setq texinfo-stack (cdr texinfo-stack)))) 1617 1618(put 'itemize 'texinfo-format 'texinfo-itemize) 1619(defun texinfo-itemize () 1620 (texinfo-push-stack 1621 'itemize 1622 (progn (skip-chars-forward " \t") 1623 (if (eolp) 1624 "@bullet" 1625 (texinfo-parse-line-arg)))) 1626 (texinfo-discard-line-with-args) 1627 (setq fill-column (- fill-column 5))) 1628 1629(put 'itemize 'texinfo-end 'texinfo-end-itemize) 1630(defun texinfo-end-itemize () 1631 (setq fill-column (+ fill-column 5)) 1632 (texinfo-discard-command) 1633 (let ((stacktop 1634 (texinfo-pop-stack 'itemize))) 1635 (texinfo-do-itemize (nth 1 stacktop)))) 1636 1637(put 'enumerate 'texinfo-format 'texinfo-enumerate) 1638(defun texinfo-enumerate () 1639 (texinfo-push-stack 1640 'enumerate 1641 (progn (skip-chars-forward " \t") 1642 (if (eolp) 1643 1 1644 (read (current-buffer))))) 1645 (if (and (symbolp (car (cdr (car texinfo-stack)))) 1646 (> 1 (length (symbol-name (car (cdr (car texinfo-stack))))))) 1647 (error 1648 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." )) 1649 (texinfo-discard-line-with-args) 1650 (setq fill-column (- fill-column 5))) 1651 1652(put 'enumerate 'texinfo-end 'texinfo-end-enumerate) 1653(defun texinfo-end-enumerate () 1654 (setq fill-column (+ fill-column 5)) 1655 (texinfo-discard-command) 1656 (let ((stacktop 1657 (texinfo-pop-stack 'enumerate))) 1658 (texinfo-do-itemize (nth 1 stacktop)))) 1659 1660;; @alphaenumerate never became a standard part of Texinfo 1661(put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate) 1662(defun texinfo-alphaenumerate () 1663 (texinfo-push-stack 'alphaenumerate (1- ?a)) 1664 (setq fill-column (- fill-column 5)) 1665 (texinfo-discard-line)) 1666 1667(put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate) 1668(defun texinfo-end-alphaenumerate () 1669 (setq fill-column (+ fill-column 5)) 1670 (texinfo-discard-command) 1671 (let ((stacktop 1672 (texinfo-pop-stack 'alphaenumerate))) 1673 (texinfo-do-itemize (nth 1 stacktop)))) 1674 1675;; @capsenumerate never became a standard part of Texinfo 1676(put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate) 1677(defun texinfo-capsenumerate () 1678 (texinfo-push-stack 'capsenumerate (1- ?A)) 1679 (setq fill-column (- fill-column 5)) 1680 (texinfo-discard-line)) 1681 1682(put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate) 1683(defun texinfo-end-capsenumerate () 1684 (setq fill-column (+ fill-column 5)) 1685 (texinfo-discard-command) 1686 (let ((stacktop 1687 (texinfo-pop-stack 'capsenumerate))) 1688 (texinfo-do-itemize (nth 1 stacktop)))) 1689 1690;; At the @end, indent all the lines within the construct 1691;; except those marked with backspace. FROM says where 1692;; construct started. 1693(defun texinfo-do-itemize (from) 1694 (save-excursion 1695 (while (progn (forward-line -1) 1696 (>= (point) from)) 1697 (if (= (following-char) ?\b) 1698 (save-excursion 1699 (delete-char 1) 1700 (end-of-line) 1701 (delete-char 6)) 1702 (if (not (looking-at "[ \t]*$")) 1703 (save-excursion (insert " "))))))) 1704 1705(put 'item 'texinfo-format 'texinfo-item) 1706(put 'itemx 'texinfo-format 'texinfo-item) 1707(defun texinfo-item () 1708 (funcall (get (car (car texinfo-stack)) 'texinfo-item))) 1709 1710(put 'itemize 'texinfo-item 'texinfo-itemize-item) 1711(defun texinfo-itemize-item () 1712 ;; (texinfo-discard-line) ; Did not handle text on same line as @item. 1713 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point))) 1714 (if (looking-at "[ \t]*[^ \t\n]+") 1715 ;; Text on same line as @item command. 1716 (insert "\b " (nth 1 (car texinfo-stack)) " \n") 1717 ;; Else text on next line. 1718 (insert "\b " (nth 1 (car texinfo-stack)) " ")) 1719 (forward-line -1)) 1720 1721(put 'enumerate 'texinfo-item 'texinfo-enumerate-item) 1722(defun texinfo-enumerate-item () 1723 (texinfo-discard-line) 1724 (let (enumerating-symbol) 1725 (cond ((integerp (car (cdr (car texinfo-stack)))) 1726 (setq enumerating-symbol (car (cdr (car texinfo-stack)))) 1727 (insert ?\b (format "%3d. " enumerating-symbol) ?\n) 1728 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol))) 1729 ((symbolp (car (cdr (car texinfo-stack)))) 1730 (setq enumerating-symbol 1731 (symbol-name (car (cdr (car texinfo-stack))))) 1732 (if (or (equal ?\[ (string-to-char enumerating-symbol)) 1733 (equal ?\{ (string-to-char enumerating-symbol))) 1734 (error 1735 "Too many items in enumerated list; alphabet ends at Z.")) 1736 (insert ?\b (format "%3s. " enumerating-symbol) ?\n) 1737 (setcar (cdr (car texinfo-stack)) 1738 (make-symbol 1739 (char-to-string 1740 (1+ 1741 (string-to-char enumerating-symbol)))))) 1742 (t 1743 (error 1744 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." ))) 1745 (forward-line -1))) 1746 1747(put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item) 1748(defun texinfo-alphaenumerate-item () 1749 (texinfo-discard-line) 1750 (let ((next (1+ (car (cdr (car texinfo-stack)))))) 1751 (if (> next ?z) 1752 (error "More than 26 items in @alphaenumerate; get a bigger alphabet")) 1753 (setcar (cdr (car texinfo-stack)) next) 1754 (insert "\b " next ". \n")) 1755 (forward-line -1)) 1756 1757(put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item) 1758(defun texinfo-capsenumerate-item () 1759 (texinfo-discard-line) 1760 (let ((next (1+ (car (cdr (car texinfo-stack)))))) 1761 (if (> next ?Z) 1762 (error "More than 26 items in @capsenumerate; get a bigger alphabet")) 1763 (setcar (cdr (car texinfo-stack)) next) 1764 (insert "\b " next ". \n")) 1765 (forward-line -1)) 1766 1767 1768;;; @table 1769 1770;; The `@table' command produces two-column tables. 1771 1772(put 'table 'texinfo-format 'texinfo-table) 1773(defun texinfo-table () 1774 (texinfo-push-stack 1775 'table 1776 (progn (skip-chars-forward " \t") 1777 (if (eolp) 1778 "@asis" 1779 (texinfo-parse-line-arg)))) 1780 (texinfo-discard-line-with-args) 1781 (setq fill-column (- fill-column 5))) 1782 1783(put 'table 'texinfo-item 'texinfo-table-item) 1784(defun texinfo-table-item () 1785 (let ((arg (texinfo-parse-arg-discard)) 1786 (itemfont (car (cdr (car texinfo-stack))))) 1787 (insert ?\b itemfont ?\{ arg "}\n \n")) 1788 (forward-line -2)) 1789 1790(put 'table 'texinfo-end 'texinfo-end-table) 1791(defun texinfo-end-table () 1792 (setq fill-column (+ fill-column 5)) 1793 (texinfo-discard-command) 1794 (let ((stacktop 1795 (texinfo-pop-stack 'table))) 1796 (texinfo-do-itemize (nth 1 stacktop)))) 1797 1798;; @description appears to be an undocumented variant on @table that 1799;; does not require an arg. It fails in texinfo.tex 2.58 and is not 1800;; part of makeinfo.c The command appears to be a relic of the past. 1801(put 'description 'texinfo-end 'texinfo-end-table) 1802(put 'description 'texinfo-format 'texinfo-description) 1803(defun texinfo-description () 1804 (texinfo-push-stack 'table "@asis") 1805 (setq fill-column (- fill-column 5)) 1806 (texinfo-discard-line)) 1807 1808 1809;;; @ftable, @vtable 1810 1811;; The `@ftable' and `@vtable' commands are like the `@table' command 1812;; but they also insert each entry in the first column of the table 1813;; into the function or variable index. 1814 1815;; Handle the @ftable and @vtable commands: 1816 1817(put 'ftable 'texinfo-format 'texinfo-ftable) 1818(put 'vtable 'texinfo-format 'texinfo-vtable) 1819 1820(defun texinfo-ftable () (texinfo-indextable 'ftable)) 1821(defun texinfo-vtable () (texinfo-indextable 'vtable)) 1822 1823(defun texinfo-indextable (table-type) 1824 (texinfo-push-stack table-type (texinfo-parse-arg-discard)) 1825 (setq fill-column (- fill-column 5))) 1826 1827;; Handle the @item commands within ftable and vtable: 1828 1829(put 'ftable 'texinfo-item 'texinfo-ftable-item) 1830(put 'vtable 'texinfo-item 'texinfo-vtable-item) 1831 1832(defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex)) 1833(defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex)) 1834 1835(defun texinfo-indextable-item (index-type) 1836 (let ((item (texinfo-parse-arg-discard)) 1837 (itemfont (car (cdr (car texinfo-stack)))) 1838 (indexvar index-type)) 1839 (insert ?\b itemfont ?\{ item "}\n \n") 1840 (set indexvar 1841 (cons 1842 (list item texinfo-last-node) 1843 (symbol-value indexvar))) 1844 (forward-line -2))) 1845 1846;; Handle @end ftable, @end vtable 1847 1848(put 'ftable 'texinfo-end 'texinfo-end-ftable) 1849(put 'vtable 'texinfo-end 'texinfo-end-vtable) 1850 1851(defun texinfo-end-ftable () (texinfo-end-indextable 'ftable)) 1852(defun texinfo-end-vtable () (texinfo-end-indextable 'vtable)) 1853 1854(defun texinfo-end-indextable (table-type) 1855 (setq fill-column (+ fill-column 5)) 1856 (texinfo-discard-command) 1857 (let ((stacktop 1858 (texinfo-pop-stack table-type))) 1859 (texinfo-do-itemize (nth 1 stacktop)))) 1860 1861 1862;;; @multitable ... @end multitable 1863 1864;; Produce a multi-column table, with as many columns as desired. 1865;; 1866;; A multi-column table has this template: 1867;; 1868;; @multitable {A1} {A2} {A3} 1869;; @item A1 @tab A2 @tab A3 1870;; @item B1 @tab B2 @tab B3 1871;; @item C1 @tab C2 @tab C3 1872;; @end multitable 1873;; 1874;; where the width of the text in brackets specifies the width of the 1875;; respective column. 1876;; 1877;; Or else: 1878;; 1879;; @multitable @columnfractions .25 .3 .45 1880;; @item A1 @tab A2 @tab A3 1881;; @item B1 @tab B2 @tab B3 1882;; @end multitable 1883;; 1884;; where the fractions specify the width of each column as a percent 1885;; of the current width of the text (i.e., of the fill-column). 1886;; 1887;; Long lines of text are filled within columns. 1888;; 1889;; Using the Emacs Lisp formatter, texinfmt.el, 1890;; the whitespace between columns can be increased by setting 1891;; `texinfo-extra-inter-column-width' to a value greater than 0. By default, 1892;; there is at least one blank space between columns. 1893;; 1894;; The Emacs Lisp formatter, texinfmt.el, ignores the following four 1895;; commands that are defined in texinfo.tex for printed output. 1896;; 1897;; @multitableparskip, 1898;; @multitableparindent, 1899;; @multitablecolmargin, 1900;; @multitablelinespace. 1901 1902;; How @multitable works. 1903;; ===================== 1904;; 1905;; `texinfo-multitable' reads the @multitable line and determines from it 1906;; how wide each column should be. 1907;; 1908;; Also, it pushes this information, along with an identifying symbol, 1909;; onto the `texinfo-stack'. At the @end multitable command, the stack 1910;; is checked for its matching @multitable command, and then popped, or 1911;; else an error is signaled. Also, this command pushes the location of 1912;; the start of the table onto the stack. 1913;; 1914;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end 1915;; multitable truly is ending a corresponding beginning, and if it is, 1916;; pops the stack. 1917;; 1918;; `texinfo-multitable-widths' is called by `texinfo-multitable'. 1919;; The function returns a list of the widths of each column in a 1920;; multi-column table, based on the information supplied by the arguments 1921;; to the @multitable command (by arguments, I mean the text on the rest 1922;; of the @multitable line, not the remainder of the multi-column table 1923;; environment). 1924;; 1925;; `texinfo-multitable-item' formats a row within a multicolumn table. 1926;; This command is executed when texinfmt sees @item inside @multitable. 1927;; Cells in row are separated by `@tab's. Widths of cells are specified 1928;; by the arguments in the @multitable line. Cells are filled. All cells 1929;; are made to be the same height by padding their bottoms, as needed, 1930;; with blanks. 1931;; 1932;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'. 1933;; This function returns the text in a multitable row, as a string. 1934;; The start of a row is marked by an @item and the end of row is the 1935;; beginning of next @item or beginning of the @end multitable line. 1936;; Cells within a row are separated by @tab. 1937;; 1938;; Note that @tab, the cell separators, are not treated as independent 1939;; Texinfo commands. 1940 1941(defvar texinfo-extra-inter-column-width 0 1942 "*Number of extra spaces between entries (columns) in @multitable.") 1943 1944(defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*") 1945(defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-") 1946 1947;; These commands are defined in texinfo.tex for printed output. 1948(put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args) 1949(put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args) 1950(put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args) 1951(put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args) 1952 1953(put 'multitable 'texinfo-format 'texinfo-multitable) 1954 1955(defun texinfo-multitable () 1956 "Produce multi-column tables. 1957 1958A multi-column table has this template: 1959 1960 @multitable {A1} {A2} {A3} 1961 @item A1 @tab A2 @tab A3 1962 @item B1 @tab B2 @tab B3 1963 @item C1 @tab C2 @tab C3 1964 @end multitable 1965 1966where the width of the text in brackets specifies the width of the 1967respective column. 1968 1969Or else: 1970 1971 @multitable @columnfractions .25 .3 .45 1972 @item A1 @tab A2 @tab A3 1973 @item B1 @tab B2 @tab B3 1974 @end multitable 1975 1976where the fractions specify the width of each column as a percent 1977of the current width of the text (i.e., of the fill-column). 1978 1979Long lines of text are filled within columns. 1980 1981Using the Emacs Lisp formatter, texinfmt.el, 1982the whitespace between columns can be increased by setting 1983`texinfo-extra-inter-column-width' to a value greater than 0. By default, 1984there is at least one blank space between columns. 1985 1986The Emacs Lisp formatter, texinfmt.el, ignores the following four 1987commands that are defined in texinfo.tex for printed output. 1988 1989 @multitableparskip, 1990 @multitableparindent, 1991 @multitablecolmargin, 1992 @multitablelinespace." 1993 1994;; This function pushes information onto the `texinfo-stack'. 1995;; A stack element consists of: 1996;; - type-of-command, i.e., multitable 1997;; - the information about column widths, and 1998;; - the position of texinfo-command-start. 1999;; e.g., ('multitable (1 2 3 4) 123) 2000;; The command line is then deleted. 2001 (texinfo-push-stack 2002 'multitable 2003 ;; push width information on stack 2004 (texinfo-multitable-widths)) 2005 (texinfo-discard-line-with-args)) 2006 2007(put 'multitable 'texinfo-end 'texinfo-end-multitable) 2008(defun texinfo-end-multitable () 2009 "Discard the @end multitable line and pop the stack of multitable." 2010 (texinfo-discard-command) 2011 (texinfo-pop-stack 'multitable)) 2012 2013(defun texinfo-multitable-widths () 2014 "Return list of widths of each column in a multi-column table." 2015 (let (texinfo-multitable-width-list) 2016 ;; Fractions format: 2017 ;; @multitable @columnfractions .25 .3 .45 2018 ;; 2019 ;; Template format: 2020 ;; @multitable {Column 1 template} {Column 2} {Column 3 example} 2021 ;; Place point before first argument 2022 (skip-chars-forward " \t") 2023 (cond 2024 ;; Check for common misspelling 2025 ((looking-at "@columnfraction ") 2026 (error "In @multitable, @columnfractions misspelled")) 2027 ;; Case 1: @columnfractions .25 .3 .45 2028 ((looking-at "@columnfractions") 2029 (forward-word 1) 2030 (while (not (eolp)) 2031 (setq texinfo-multitable-width-list 2032 (cons 2033 (truncate 2034 (1- 2035 (* fill-column (read (get-buffer (current-buffer)))))) 2036 texinfo-multitable-width-list)))) 2037 ;; 2038 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example} 2039 ((looking-at "{") 2040 (let ((start-of-templates (point))) 2041 (while (not (eolp)) 2042 (skip-chars-forward " \t") 2043 (let* ((start-of-template (1+ (point))) 2044 (end-of-template 2045 ;; forward-sexp works with braces in Texinfo mode 2046 (progn (forward-sexp 1) (1- (point))))) 2047 (setq texinfo-multitable-width-list 2048 (cons (- end-of-template start-of-template) 2049 texinfo-multitable-width-list)) 2050 ;; Remove carriage return from within a template, if any. 2051 ;; This helps those those who want to use more than 2052 ;; one line's worth of words in @multitable line. 2053 (narrow-to-region start-of-template end-of-template) 2054 (goto-char (point-min)) 2055 (while (search-forward " 2056" nil t) 2057 (delete-char -1)) 2058 (goto-char (point-max)) 2059 (widen) 2060 (forward-char 1))))) 2061 ;; 2062 ;; Case 3: Trouble 2063 (t 2064 (error 2065 "You probably need to specify column widths for @multitable correctly."))) 2066 ;; Check whether columns fit on page. 2067 (let ((desired-columns 2068 (+ 2069 ;; between column spaces 2070 (length texinfo-multitable-width-list) 2071 ;; additional between column spaces, if any 2072 texinfo-extra-inter-column-width 2073 ;; sum of spaces for each entry 2074 (apply '+ texinfo-multitable-width-list)))) 2075 (if (> desired-columns fill-column) 2076 (error 2077 (format 2078 "Multi-column table width, %d chars, is greater than page width, %d chars." 2079 desired-columns fill-column)))) 2080 texinfo-multitable-width-list)) 2081 2082;; @item A1 @tab A2 @tab A3 2083(defun texinfo-multitable-extract-row () 2084 "Return multitable row, as a string. 2085End of row is beginning of next @item or beginning of @end. 2086Cells within rows are separated by @tab." 2087 (skip-chars-forward " \t") 2088 (let* ((start (point)) 2089 (end (progn 2090 (re-search-forward "@item\\|@end") 2091 (match-beginning 0))) 2092 (row (progn (goto-char end) 2093 (skip-chars-backward " ") 2094 ;; remove whitespace at end of argument 2095 (delete-region (point) end) 2096 (buffer-substring-no-properties start (point))))) 2097 (delete-region texinfo-command-start end) 2098 row)) 2099 2100(put 'multitable 'texinfo-item 'texinfo-multitable-item) 2101(defun texinfo-multitable-item () 2102 "Format a row within a multicolumn table. 2103Cells in row are separated by @tab. 2104Widths of cells are specified by the arguments in the @multitable line. 2105All cells are made to be the same height. 2106This command is executed when texinfmt sees @item inside @multitable." 2107 (let ((original-buffer (current-buffer)) 2108 (table-widths (reverse (car (cdr (car texinfo-stack))))) 2109 (existing-fill-column fill-column) 2110 start 2111 end 2112 (table-column 0) 2113 (table-entry-height 0) 2114 ;; unformatted row looks like: A1 @tab A2 @tab A3 2115 ;; extract-row command deletes the source line in the table. 2116 (unformated-row (texinfo-multitable-extract-row))) 2117 ;; Use a temporary buffer 2118 (set-buffer (get-buffer-create texinfo-multitable-buffer-name)) 2119 (delete-region (point-min) (point-max)) 2120 (insert unformated-row) 2121 (goto-char (point-min)) 2122;; 1. Check for correct number of @tab in line. 2123 (let ((tab-number 1)) ; one @tab between two columns 2124 (while (search-forward "@tab" nil t) 2125 (setq tab-number (1+ tab-number))) 2126 (let ((needed-tabs (- (length table-widths) tab-number))) 2127 (when (> needed-tabs 0) 2128 (goto-char (point-min)) 2129 (end-of-line) 2130 (while (> needed-tabs 0) 2131 (insert "@w{ }\n@tab") 2132 (setq needed-tabs (1- needed-tabs)) 2133 (message 2134 "Added @tabs and empty spaces to a @multitable row"))))) 2135 (goto-char (point-min)) 2136;; 2. Format each cell, and copy to a rectangle 2137 ;; buffer looks like this: A1 @tab A2 @tab A3 2138 ;; Cell #1: format up to @tab 2139 ;; Cell #2: format up to @tab 2140 ;; Cell #3: format up to eob 2141 (while (not (eobp)) 2142 (setq start (point)) 2143 (setq end (save-excursion 2144 (if (search-forward "@tab" nil 'move) 2145 ;; Delete the @tab command, including the @-sign 2146 (delete-region 2147 (point) 2148 (progn (forward-word -1) (1- (point))))) 2149 (point))) 2150 ;; Set fill-column *wider* than needed to produce inter-column space 2151 (setq fill-column (+ 1 2152 texinfo-extra-inter-column-width 2153 (nth table-column table-widths))) 2154 (narrow-to-region start end) 2155 ;; Remove whitespace before and after entry. 2156 (skip-chars-forward " ") 2157 (delete-region (point) (save-excursion (beginning-of-line) (point))) 2158 (goto-char (point-max)) 2159 (skip-chars-backward " ") 2160 (delete-region (point) (save-excursion (end-of-line) (point))) 2161 ;; Temporarily set texinfo-stack to nil so texinfo-format-scan 2162 ;; does not see an unterminated @multitable. 2163 (let (texinfo-stack) ; nil 2164 (texinfo-format-scan)) 2165 (let (fill-prefix) ; no fill prefix 2166 (fill-region (point-min) (point-max))) 2167 (setq table-entry-height 2168 (max table-entry-height (count-lines (point-min) (point-max)))) 2169;; 3. Move point to end of bottom line, and pad that line to fill column. 2170 (goto-char (point-min)) 2171 (forward-line (1- table-entry-height)) 2172 (let* ((beg (point)) ; beginning of line 2173 ;; add one more space for inter-column spacing 2174 (needed-whitespace 2175 (1+ 2176 (- fill-column 2177 (- 2178 (progn (end-of-line) (point)) ; end of existing line 2179 beg))))) 2180 (insert (make-string 2181 (if (> needed-whitespace 0) needed-whitespace 1) 2182 ? ))) 2183 ;; now, put formatted cell into a rectangle 2184 (set (intern (concat texinfo-multitable-rectangle-name 2185 (int-to-string table-column))) 2186 (extract-rectangle (point-min) (point))) 2187 (delete-region (point-min) (point)) 2188 (goto-char (point-max)) 2189 (setq table-column (1+ table-column)) 2190 (widen)) 2191;; 4. Add extra lines to rectangles so all are of same height 2192 (let ((total-number-of-columns table-column) 2193 (column-number 0) 2194 here) 2195 (while (> table-column 0) 2196 (let ((this-rectangle (int-to-string table-column))) 2197 (while (< (length this-rectangle) table-entry-height) 2198 (setq this-rectangle (append this-rectangle '(""))))) 2199 (setq table-column (1- table-column))) 2200;; 5. Insert formatted rectangles in original buffer 2201 (switch-to-buffer original-buffer) 2202 (open-line table-entry-height) 2203 (while (< column-number total-number-of-columns) 2204 (setq here (point)) 2205 (insert-rectangle 2206 (eval (intern 2207 (concat texinfo-multitable-rectangle-name 2208 (int-to-string column-number))))) 2209 (goto-char here) 2210 (end-of-line) 2211 (setq column-number (1+ column-number)))) 2212 (kill-buffer texinfo-multitable-buffer-name) 2213 (setq fill-column existing-fill-column))) 2214 2215 2216;;; @image 2217;; Use only the FILENAME argument to the command. 2218;; In Info, ignore the other arguments. 2219 2220(put 'image 'texinfo-format 'texinfo-format-image) 2221(defun texinfo-format-image () 2222 "Insert an image from an an file ending in .txt. 2223Use only the FILENAME arg; for Info, ignore the other arguments to @image." 2224 (let ((args (texinfo-format-parse-args)) 2225 filename) 2226 (when (null (nth 0 args)) 2227 (error "Invalid image command")) 2228 (texinfo-discard-command) 2229 ;; makeinfo uses FILENAME.txt 2230 (setq filename (format "%s.txt" (nth 0 args))) 2231 (message "Reading included file: %s" filename) 2232 ;; verbatim for Info output 2233 (goto-char (+ (point) (cadr (insert-file-contents filename)))) 2234 (message "Reading included file: %s...done" filename))) 2235 2236 2237;;; @ifinfo, @iftex, @tex, @ifhtml, @html, @ifplaintext, @ifxml, @xml 2238;; @ifnottex, @ifnotinfo, @ifnothtml, @ifnotplaintext, @ifnotxml 2239 2240(put 'ifinfo 'texinfo-format 'texinfo-discard-line) 2241(put 'ifinfo 'texinfo-end 'texinfo-discard-command) 2242 2243(put 'iftex 'texinfo-format 'texinfo-format-iftex) 2244(defun texinfo-format-iftex () 2245 (delete-region texinfo-command-start 2246 (re-search-forward "@end iftex[ \t]*\n"))) 2247 2248(put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml) 2249(defun texinfo-format-ifhtml () 2250 (delete-region texinfo-command-start 2251 (re-search-forward "@end ifhtml[ \t]*\n"))) 2252 2253(put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext) 2254(defun texinfo-format-ifplaintext () 2255 (delete-region texinfo-command-start 2256 (re-search-forward "@end ifplaintext[ \t]*\n"))) 2257 2258(put 'ifxml 'texinfo-format 'texinfo-format-ifxml) 2259(defun texinfo-format-ifxml () 2260 (delete-region texinfo-command-start 2261 (progn (re-search-forward "^@end ifxml[ \t]*\n") 2262 (point)))) 2263 2264(put 'tex 'texinfo-format 'texinfo-format-tex) 2265(defun texinfo-format-tex () 2266 (delete-region texinfo-command-start 2267 (re-search-forward "@end tex[ \t]*\n"))) 2268 2269(put 'html 'texinfo-format 'texinfo-format-html) 2270(defun texinfo-format-html () 2271 (delete-region texinfo-command-start 2272 (re-search-forward "@end html[ \t]*\n"))) 2273 2274(put 'xml 'texinfo-format 'texinfo-format-xml) 2275(defun texinfo-format-xml () 2276 (delete-region texinfo-command-start 2277 (progn (re-search-forward "^@end xml[ \t]*\n") 2278 (point)))) 2279 2280(put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo) 2281(defun texinfo-format-ifnotinfo () 2282 (delete-region texinfo-command-start 2283 (re-search-forward "@end ifnotinfo[ \t]*\n"))) 2284 2285(put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line) 2286(put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command) 2287 2288(put 'ifnottex 'texinfo-format 'texinfo-discard-line) 2289(put 'ifnottex 'texinfo-end 'texinfo-discard-command) 2290 2291(put 'ifnothtml 'texinfo-format 'texinfo-discard-line) 2292(put 'ifnothtml 'texinfo-end 'texinfo-discard-command) 2293 2294(put 'ifnotxml 'texinfo-format 'texinfo-discard-line) 2295(put 'ifnotxml 'texinfo-end 'texinfo-discard-command) 2296 2297 2298;;; @titlepage 2299 2300(put 'titlepage 'texinfo-format 'texinfo-format-titlepage) 2301(defun texinfo-format-titlepage () 2302 (delete-region texinfo-command-start 2303 (re-search-forward "@end titlepage[ \t]*\n"))) 2304 2305(put 'endtitlepage 'texinfo-format 'texinfo-discard-line) 2306 2307;; @titlespec an alternative titling command; ignored by Info 2308 2309(put 'titlespec 'texinfo-format 'texinfo-format-titlespec) 2310(defun texinfo-format-titlespec () 2311 (delete-region texinfo-command-start 2312 (re-search-forward "@end titlespec[ \t]*\n"))) 2313 2314(put 'endtitlespec 'texinfo-format 'texinfo-discard-line) 2315 2316 2317;;; @today 2318 2319(put 'today 'texinfo-format 'texinfo-format-today) 2320 2321;; Produces Day Month Year style of output. eg `1 Jan 1900' 2322;; The `@today{}' command requires a pair of braces, like `@dots{}'. 2323(defun texinfo-format-today () 2324 (texinfo-parse-arg-discard) 2325 (insert (format-time-string "%e %b %Y"))) 2326 2327 2328;;; @timestamp{} 2329;; Produce `Day Month Year Hour:Min' style of output. 2330;; eg `1 Jan 1900 13:52' 2331 2332(put 'timestamp 'texinfo-format 'texinfo-format-timestamp) 2333 2334;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'. 2335(defun texinfo-format-timestamp () 2336 "Insert the current local time and date." 2337 (texinfo-parse-arg-discard) 2338 ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z" 2339 (insert (format-time-string "%e %b %Y %R"))) 2340 2341 2342;;; @ignore 2343 2344(put 'ignore 'texinfo-format 'texinfo-format-ignore) 2345(defun texinfo-format-ignore () 2346 (delete-region texinfo-command-start 2347 (re-search-forward "@end ignore[ \t]*\n"))) 2348 2349(put 'endignore 'texinfo-format 'texinfo-discard-line) 2350 2351 2352;;; Define the Info enclosure command: @definfoenclose 2353 2354;; A `@definfoenclose' command may be used to define a highlighting 2355;; command for Info, but not for TeX. A command defined using 2356;; `@definfoenclose' marks text by enclosing it in strings that precede 2357;; and follow the text. 2358;; 2359;; Presumably, if you define a command with `@definfoenclose` for Info, 2360;; you will also define the same command in the TeX definitions file, 2361;; `texinfo.tex' in a manner appropriate for typesetting. 2362;; 2363;; Write a `@definfoenclose' command on a line and follow it with three 2364;; arguments separated by commas (commas are used as separators in an 2365;; `@node' line in the same way). The first argument to 2366;; `@definfoenclose' is the @-command name \(without the `@'\); the 2367;; second argument is the Info start delimiter string; and the third 2368;; argument is the Info end delimiter string. The latter two arguments 2369;; enclose the highlighted text in the Info file. A delimiter string 2370;; may contain spaces. Neither the start nor end delimiter is 2371;; required. However, if you do not provide a start delimiter, you 2372;; must follow the command name with two commas in a row; otherwise, 2373;; the Info formatting commands will misinterpret the end delimiter 2374;; string as a start delimiter string. 2375;; 2376;; If you do a @definfoenclose{} on the name of a pre-defined macro (such 2377;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will 2378;; override the built-in definition. 2379;; 2380;; An enclosure command defined this way takes one argument in braces. 2381;; 2382;; For example, you can write: 2383;; 2384;; @ifinfo 2385;; @definfoenclose phoo, //, \\ 2386;; @end ifinfo 2387;; 2388;; near the beginning of a Texinfo file at the beginning of the lines 2389;; to define `@phoo' as an Info formatting command that inserts `//' 2390;; before and `\\' after the argument to `@phoo'. You can then write 2391;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info. 2392;; 2393;; Also, for TeX formatting, you could write 2394;; 2395;; @iftex 2396;; @global@let@phoo=@i 2397;; @end iftex 2398;; 2399;; to define `@phoo' as a command that causes TeX to typeset 2400;; the argument to `@phoo' in italics. 2401;; 2402;; Note that each definition applies to its own formatter: one for TeX, 2403;; the other for texinfo-format-buffer or texinfo-format-region. 2404;; 2405;; Here is another example: write 2406;; 2407;; @definfoenclose headword, , : 2408;; 2409;; near the beginning of the file, to define `@headword' as an Info 2410;; formatting command that inserts nothing before and a colon after the 2411;; argument to `@headword'. 2412 2413(put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure) 2414(defun texinfo-define-info-enclosure () 2415 (let* ((args (texinfo-format-parse-line-args)) 2416 (command-name (nth 0 args)) 2417 (beginning-delimiter (or (nth 1 args) "")) 2418 (end-delimiter (or (nth 2 args) ""))) 2419 (texinfo-discard-command) 2420 (setq texinfo-enclosure-list 2421 (cons 2422 (list command-name 2423 (list 2424 beginning-delimiter 2425 end-delimiter)) 2426 texinfo-enclosure-list)))) 2427 2428 2429;;; @alias 2430 2431(put 'alias 'texinfo-format 'texinfo-alias) 2432(defun texinfo-alias () 2433 (let ((start (1- (point))) 2434 args) 2435 (skip-chars-forward " ") 2436 (save-excursion (end-of-line) (setq texinfo-command-end (point))) 2437 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) 2438 (error "Invalid alias command") 2439 (setq texinfo-alias-list 2440 (cons 2441 (cons 2442 (match-string-no-properties 1) 2443 (match-string-no-properties 2)) 2444 texinfo-alias-list)) 2445 (texinfo-discard-command)) 2446 ) 2447 ) 2448 2449 2450;;; @var, @code and the like 2451 2452(put 'var 'texinfo-format 'texinfo-format-var) 2453;; @sc a small caps font for TeX; formatted as `var' in Info 2454(put 'sc 'texinfo-format 'texinfo-format-var) 2455;; @acronym for abbreviations in all caps, such as `NASA'. 2456;; Convert all letters to uppercase if they are not already. 2457(put 'acronym 'texinfo-format 'texinfo-format-var) 2458(defun texinfo-format-var () 2459 (let ((arg (texinfo-parse-expanded-arg))) 2460 (texinfo-discard-command) 2461 (insert (upcase arg)))) 2462 2463(put 'cite 'texinfo-format 'texinfo-format-code) 2464(put 'code 'texinfo-format 'texinfo-format-code) 2465;; @command (for command names) 2466(put 'command 'texinfo-format 'texinfo-format-code) 2467;; @env (for environment variables) 2468(put 'env 'texinfo-format 'texinfo-format-code) 2469(put 'file 'texinfo-format 'texinfo-format-code) 2470(put 'samp 'texinfo-format 'texinfo-format-code) 2471(put 'url 'texinfo-format 'texinfo-format-code) 2472(defun texinfo-format-code () 2473 (insert "`" (texinfo-parse-arg-discard) "'") 2474 (goto-char texinfo-command-start)) 2475 2476;; @option (for command-line options) must be different from @code 2477;; because of its special formatting in @table; namely that it does 2478;; not lead to inserted ` ... ' in a table, but does elsewhere. 2479(put 'option 'texinfo-format 'texinfo-format-option) 2480(defun texinfo-format-option () 2481 "Insert ` ... ' around arg unless inside a table; in that case, no quotes." 2482 ;; `looking-at-backward' not available in v. 18.57, 20.2 2483 (if (not (search-backward "" ; searched-for character is a control-H 2484 (save-excursion (beginning-of-line) (point)) 2485 t)) 2486 (insert "`" (texinfo-parse-arg-discard) "'") 2487 (insert (texinfo-parse-arg-discard))) 2488 (goto-char texinfo-command-start)) 2489 2490(put 'emph 'texinfo-format 'texinfo-format-emph) 2491(put 'strong 'texinfo-format 'texinfo-format-emph) 2492(defun texinfo-format-emph () 2493 (insert "*" (texinfo-parse-arg-discard) "*") 2494 (goto-char texinfo-command-start)) 2495 2496(put 'dfn 'texinfo-format 'texinfo-format-defn) 2497(put 'defn 'texinfo-format 'texinfo-format-defn) 2498(defun texinfo-format-defn () 2499 (insert "\"" (texinfo-parse-arg-discard) "\"") 2500 (goto-char texinfo-command-start)) 2501 2502(put 'email 'texinfo-format 'texinfo-format-email) 2503(defun texinfo-format-email () 2504 "Format email address and optional following full name. 2505Insert full name, if present, followed by email address 2506surrounded by in angle brackets." 2507 (let ((args (texinfo-format-parse-args))) 2508 (texinfo-discard-command) 2509 ;; if full-name 2510 (if (nth 1 args) 2511 (insert (nth 1 args) " ")) 2512 (insert "<" (nth 0 args) ">"))) 2513 2514(put 'key 'texinfo-format 'texinfo-format-key) 2515;; I've decided not want to have angle brackets around these -- rms. 2516(defun texinfo-format-key () 2517 (insert (texinfo-parse-arg-discard)) 2518 (goto-char texinfo-command-start)) 2519 2520;; @verb{<char>TEXT<char>} (in `makeinfo' 4.1 and later) 2521(put 'verb 'texinfo-format 'texinfo-format-verb) 2522(defun texinfo-format-verb () 2523 "Format text between non-quoted unique delimiter characters verbatim. 2524Enclose the verbatim text, including the delimiters, in braces. Print 2525text exactly as written (but not the delimiters) in a fixed-width. 2526 2527For example, @verb\{|@|\} results in @ and 2528@verb\{+@'e?`!`+} results in @'e?`!`." 2529 2530 (let ((delimiter (buffer-substring-no-properties 2531 (1+ texinfo-command-end) (+ 2 texinfo-command-end)))) 2532 (unless (looking-at "{") 2533 (error "Not found: @verb start brace")) 2534 (delete-region texinfo-command-start (+ 2 texinfo-command-end)) 2535 (search-forward delimiter)) 2536 (delete-backward-char 1) 2537 (unless (looking-at "}") 2538 (error "Not found: @verb end brace")) 2539 (delete-char 1)) 2540 2541;; as of 2002 Dec 10 2542;; see (texinfo)Block Enclosing Commands 2543;; need: @verbatim 2544 2545;; as of 2002 Dec 10 2546;; see (texinfo)verbatiminclude 2547;; need: @verbatiminclude FILENAME 2548 2549(put 'bullet 'texinfo-format 'texinfo-format-bullet) 2550(defun texinfo-format-bullet () 2551 "Insert an asterisk. 2552If used within a line, follow `@bullet' with braces." 2553 (texinfo-optional-braces-discard) 2554 (insert "*")) 2555 2556 2557;;; @kbd 2558 2559;; Inside of @example ... @end example and similar environments, 2560;; @kbd does nothing; but outside of such environments, it places 2561;; single quotation marks around its argument. 2562 2563(defvar texinfo-format-kbd-regexp 2564 (concat 2565 "^@" 2566 "\\(" 2567 "display\\|" 2568 "example\\|" 2569 "smallexample\\|" 2570 "lisp\\|" 2571 "smalllisp" 2572 "\\)") 2573 "Regexp specifying environments in which @kbd does not put `...' 2574 around argument.") 2575 2576(defvar texinfo-format-kbd-end-regexp 2577 (concat 2578 "^@end " 2579 "\\(" 2580 "display\\|" 2581 "example\\|" 2582 "smallexample\\|" 2583 "lisp\\|" 2584 "smalllisp" 2585 "\\)") 2586 "Regexp specifying end of environments in which @kbd does not put `...' 2587 around argument. (See `texinfo-format-kbd-regexp')") 2588 2589(put 'kbd 'texinfo-format 'texinfo-format-kbd) 2590(defun texinfo-format-kbd () 2591 "Place single quote marks around arg, except in @example and similar." 2592 ;; Search forward for @end example closer than an @example. 2593 ;; Can stop search at nearest @node or texinfo-section-types-regexp 2594 (let* ((stop 2595 (save-excursion 2596 (re-search-forward 2597 (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)") 2598 nil 2599 'move-to-end) ; if necessary, return point at end of buffer 2600 (point))) 2601 (example-location 2602 (save-excursion 2603 (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end) 2604 (point))) 2605 (end-example-location 2606 (save-excursion 2607 (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end) 2608 (point)))) 2609 ;; If inside @example, @end example will be closer than @example 2610 ;; or end of search i.e., end-example-location less than example-location 2611 (if (>= end-example-location example-location) 2612 ;; outside an @example or equivalent 2613 (insert "`" (texinfo-parse-arg-discard) "'") 2614 ;; else, in @example; do not surround with `...' 2615 (insert (texinfo-parse-arg-discard))) 2616 (goto-char texinfo-command-start))) 2617 2618 2619;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample, 2620;; @smalldisplay 2621 2622(put 'display 'texinfo-format 'texinfo-format-example) 2623(put 'smalldisplay 'texinfo-format 'texinfo-format-example) 2624(put 'example 'texinfo-format 'texinfo-format-example) 2625(put 'lisp 'texinfo-format 'texinfo-format-example) 2626(put 'quotation 'texinfo-format 'texinfo-format-example) 2627(put 'smallexample 'texinfo-format 'texinfo-format-example) 2628(put 'smalllisp 'texinfo-format 'texinfo-format-example) 2629(defun texinfo-format-example () 2630 (texinfo-push-stack 'example nil) 2631 (setq fill-column (- fill-column 5)) 2632 (texinfo-discard-line)) 2633 2634(put 'example 'texinfo-end 'texinfo-end-example) 2635(put 'display 'texinfo-end 'texinfo-end-example) 2636(put 'smalldisplay 'texinfo-end 'texinfo-end-example) 2637(put 'lisp 'texinfo-end 'texinfo-end-example) 2638(put 'quotation 'texinfo-end 'texinfo-end-example) 2639(put 'smallexample 'texinfo-end 'texinfo-end-example) 2640(put 'smalllisp 'texinfo-end 'texinfo-end-example) 2641(defun texinfo-end-example () 2642 (setq fill-column (+ fill-column 5)) 2643 (texinfo-discard-command) 2644 (let ((stacktop 2645 (texinfo-pop-stack 'example))) 2646 (texinfo-do-itemize (nth 1 stacktop)))) 2647 2648(put 'exdent 'texinfo-format 'texinfo-format-exdent) 2649(defun texinfo-format-exdent () 2650 (texinfo-discard-command) 2651 (delete-region (point) 2652 (progn 2653 (skip-chars-forward " ") 2654 (point))) 2655 (insert ?\b) 2656 ;; Cancel out the deletion that texinfo-do-itemize 2657 ;; is going to do at the end of this line. 2658 (save-excursion 2659 (end-of-line) 2660 (insert "\n "))) 2661 2662 2663;; @direntry and @dircategory 2664 2665(put 'direntry 'texinfo-format 'texinfo-format-direntry) 2666(defun texinfo-format-direntry () 2667 (texinfo-push-stack 'direntry nil) 2668 (texinfo-discard-line) 2669 (insert "START-INFO-DIR-ENTRY\n")) 2670 2671(put 'direntry 'texinfo-end 'texinfo-end-direntry) 2672(defun texinfo-end-direntry () 2673 (texinfo-discard-command) 2674 (insert "END-INFO-DIR-ENTRY\n\n") 2675 (texinfo-pop-stack 'direntry)) 2676 2677(put 'dircategory 'texinfo-format 'texinfo-format-dircategory) 2678(defun texinfo-format-dircategory () 2679 (let ((str (texinfo-parse-arg-discard))) 2680 (delete-region (point) 2681 (progn 2682 (skip-chars-forward " ") 2683 (point))) 2684 (insert "INFO-DIR-SECTION " str "\n"))) 2685 2686;;; @cartouche 2687 2688;; The @cartouche command is a noop in Info; in a printed manual, 2689;; it makes a box with rounded corners. 2690 2691(put 'cartouche 'texinfo-format 'texinfo-discard-line) 2692(put 'cartouche 'texinfo-end 'texinfo-discard-command) 2693 2694 2695;;; @flushleft and @format 2696 2697;; The @flushleft command left justifies every line but leaves the 2698;; right end ragged. As far as Info is concerned, @flushleft is a 2699;; `do-nothing' command 2700 2701;; The @format command is similar to @example except that it does not 2702;; indent; this means that in Info, @format is similar to @flushleft. 2703 2704(put 'format 'texinfo-format 'texinfo-format-flushleft) 2705(put 'smallformat 'texinfo-format 'texinfo-format-flushleft) 2706(put 'flushleft 'texinfo-format 'texinfo-format-flushleft) 2707(defun texinfo-format-flushleft () 2708 (texinfo-discard-line)) 2709 2710(put 'format 'texinfo-end 'texinfo-end-flushleft) 2711(put 'smallformat 'texinfo-end 'texinfo-end-flushleft) 2712(put 'flushleft 'texinfo-end 'texinfo-end-flushleft) 2713(defun texinfo-end-flushleft () 2714 (texinfo-discard-command)) 2715 2716 2717;;; @flushright 2718 2719;; The @flushright command right justifies every line but leaves the 2720;; left end ragged. Spaces and tabs at the right ends of lines are 2721;; removed so that visible text lines up on the right side. 2722 2723(put 'flushright 'texinfo-format 'texinfo-format-flushright) 2724(defun texinfo-format-flushright () 2725 (texinfo-push-stack 'flushright nil) 2726 (texinfo-discard-line)) 2727 2728(put 'flushright 'texinfo-end 'texinfo-end-flushright) 2729(defun texinfo-end-flushright () 2730 (texinfo-discard-command) 2731 2732 (let ((stacktop 2733 (texinfo-pop-stack 'flushright))) 2734 2735 (texinfo-do-flushright (nth 1 stacktop)))) 2736 2737(defun texinfo-do-flushright (from) 2738 (save-excursion 2739 (while (progn (forward-line -1) 2740 (>= (point) from)) 2741 2742 (beginning-of-line) 2743 (insert 2744 (make-string 2745 (- fill-column 2746 (save-excursion 2747 (end-of-line) 2748 (skip-chars-backward " \t") 2749 (delete-region (point) (progn (end-of-line) (point))) 2750 (current-column))) 2751 ? ))))) 2752 2753 2754;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds 2755 2756(put 'ctrl 'texinfo-format 'texinfo-format-ctrl) 2757(defun texinfo-format-ctrl () 2758 (let ((str (texinfo-parse-arg-discard))) 2759 (insert (logand 31 (aref str 0))))) 2760 2761(put 'TeX 'texinfo-format 'texinfo-format-TeX) 2762(defun texinfo-format-TeX () 2763 (texinfo-parse-arg-discard) 2764 (insert "TeX")) 2765 2766(put 'copyright 'texinfo-format 'texinfo-format-copyright) 2767(defun texinfo-format-copyright () 2768 (texinfo-parse-arg-discard) 2769 (insert "(C)")) 2770 2771(put 'minus 'texinfo-format 'texinfo-format-minus) 2772(defun texinfo-format-minus () 2773 "Insert a minus sign. 2774If used within a line, follow `@minus' with braces." 2775 (texinfo-optional-braces-discard) 2776 (insert "-")) 2777 2778(put 'dots 'texinfo-format 'texinfo-format-dots) 2779(defun texinfo-format-dots () 2780 (texinfo-parse-arg-discard) 2781 (insert "...")) 2782 2783(put 'enddots 'texinfo-format 'texinfo-format-enddots) 2784(defun texinfo-format-enddots () 2785 (texinfo-parse-arg-discard) 2786 (insert "....")) 2787 2788(put 'pounds 'texinfo-format 'texinfo-format-pounds) 2789(defun texinfo-format-pounds () 2790 (texinfo-parse-arg-discard) 2791 (insert "#")) 2792 2793 2794;;; Refilling and indenting: @refill, @paragraphindent, @noindent 2795 2796;;; Indent only those paragraphs that are refilled as a result of an 2797;;; @refill command. 2798 2799;; * If the value is `asis', do not change the existing indentation at 2800;; the starts of paragraphs. 2801 2802;; * If the value zero, delete any existing indentation. 2803 2804;; * If the value is greater than zero, indent each paragraph by that 2805;; number of spaces. 2806 2807;;; But do not refill paragraphs with an @refill command that are 2808;;; preceded by @noindent or are part of a table, list, or deffn. 2809 2810(defvar texinfo-paragraph-indent "asis" 2811 "Number of spaces for @refill to indent a paragraph; else to leave as is.") 2812 2813(put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent) 2814 2815(defun texinfo-paragraphindent () 2816 "Specify the number of spaces for @refill to indent a paragraph. 2817Default is to leave the number of spaces as is." 2818 (let ((arg (texinfo-parse-arg-discard))) 2819 (if (string= "asis" arg) 2820 (setq texinfo-paragraph-indent "asis") 2821 (setq texinfo-paragraph-indent (string-to-number arg))))) 2822 2823(put 'refill 'texinfo-format 'texinfo-format-refill) 2824(defun texinfo-format-refill () 2825 "Refill paragraph. Also, indent first line as set by @paragraphindent. 2826Default is to leave paragraph indentation as is." 2827 (texinfo-discard-command) 2828 (let ((position (point-marker))) 2829 (forward-paragraph -1) 2830 (if (looking-at "[ \t\n]*$") (forward-line 1)) 2831 ;; Do not indent if an entry in a list, table, or deffn, 2832 ;; or if paragraph is preceded by @noindent. 2833 ;; Otherwise, indent 2834 (cond 2835 ;; delete a @noindent line and do not indent paragraph 2836 ((save-excursion (forward-line -1) 2837 (looking-at "^@noindent")) 2838 (forward-line -1) 2839 (delete-region (point) (progn (forward-line 1) (point)))) 2840 ;; do nothing if "asis" 2841 ((equal texinfo-paragraph-indent "asis")) 2842 ;; do no indenting in list, etc. 2843 ((> texinfo-stack-depth 0)) 2844 ;; otherwise delete existing whitespace and indent 2845 (t 2846 (delete-region (point) (progn (skip-chars-forward " \t") (point))) 2847 (insert (make-string texinfo-paragraph-indent ? )))) 2848 (forward-paragraph 1) 2849 (forward-line -1) 2850 (end-of-line) 2851 ;; Do not fill a section title line with asterisks, hyphens, etc. that 2852 ;; are used to underline it. This could occur if the line following 2853 ;; the underlining is not an index entry and has text within it. 2854 (let* ((previous-paragraph-separate paragraph-separate) 2855 (paragraph-separate 2856 (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+")) 2857 (previous-paragraph-start paragraph-start) 2858 (paragraph-start 2859 (concat paragraph-start "\\|[-=.]+\\|\\*\\*+"))) 2860 (unwind-protect 2861 (fill-paragraph nil) 2862 (setq paragraph-separate previous-paragraph-separate) 2863 (setq paragraph-start previous-paragraph-start))) 2864 (goto-char position))) 2865 2866(put 'noindent 'texinfo-format 'texinfo-noindent) 2867(defun texinfo-noindent () 2868 (save-excursion 2869 (forward-paragraph 1) 2870 (if (search-backward "@refill" 2871 (save-excursion (forward-line -1) (point)) t) 2872 () ; leave @noindent command so @refill command knows not to indent 2873 ;; else 2874 (texinfo-discard-line)))) 2875 2876 2877;;; Index generation 2878 2879(put 'vindex 'texinfo-format 'texinfo-format-vindex) 2880(defun texinfo-format-vindex () 2881 (texinfo-index 'texinfo-vindex)) 2882 2883(put 'cindex 'texinfo-format 'texinfo-format-cindex) 2884(defun texinfo-format-cindex () 2885 (texinfo-index 'texinfo-cindex)) 2886 2887(put 'findex 'texinfo-format 'texinfo-format-findex) 2888(defun texinfo-format-findex () 2889 (texinfo-index 'texinfo-findex)) 2890 2891(put 'pindex 'texinfo-format 'texinfo-format-pindex) 2892(defun texinfo-format-pindex () 2893 (texinfo-index 'texinfo-pindex)) 2894 2895(put 'tindex 'texinfo-format 'texinfo-format-tindex) 2896(defun texinfo-format-tindex () 2897 (texinfo-index 'texinfo-tindex)) 2898 2899(put 'kindex 'texinfo-format 'texinfo-format-kindex) 2900(defun texinfo-format-kindex () 2901 (texinfo-index 'texinfo-kindex)) 2902 2903(defun texinfo-index (indexvar) 2904 (let ((arg (texinfo-parse-expanded-arg))) 2905 (texinfo-discard-command) 2906 (set indexvar 2907 (cons (list arg 2908 texinfo-last-node 2909 ;; Region formatting may not provide last node position. 2910 (if texinfo-last-node-pos 2911 (1+ (count-lines texinfo-last-node-pos (point))) 2912 1)) 2913 (symbol-value indexvar))))) 2914 2915(defvar texinfo-indexvar-alist 2916 '(("cp" . texinfo-cindex) 2917 ("fn" . texinfo-findex) 2918 ("vr" . texinfo-vindex) 2919 ("tp" . texinfo-tindex) 2920 ("pg" . texinfo-pindex) 2921 ("ky" . texinfo-kindex))) 2922 2923 2924;;; @defindex @defcodeindex 2925(put 'defindex 'texinfo-format 'texinfo-format-defindex) 2926(put 'defcodeindex 'texinfo-format 'texinfo-format-defindex) 2927 2928(defun texinfo-format-defindex () 2929 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa' 2930 (indexing-command (intern (concat index-name "index"))) 2931 (index-formatting-command ; eg: `texinfo-format-aaindex' 2932 (intern (concat "texinfo-format-" index-name "index"))) 2933 (index-alist-name ; eg: `texinfo-aaindex' 2934 (intern (concat "texinfo-" index-name "index")))) 2935 2936 (set index-alist-name nil) 2937 2938 (put indexing-command ; eg, aaindex 2939 'texinfo-format 2940 index-formatting-command) ; eg, texinfo-format-aaindex 2941 2942 ;; eg: "aa" . texinfo-aaindex 2943 (or (assoc index-name texinfo-indexvar-alist) 2944 (setq texinfo-indexvar-alist 2945 (cons 2946 (cons index-name 2947 index-alist-name) 2948 texinfo-indexvar-alist))) 2949 2950 (fset index-formatting-command 2951 (list 'lambda 'nil 2952 (list 'texinfo-index 2953 (list 'quote index-alist-name)))))) 2954 2955 2956;;; @synindex @syncodeindex 2957 2958(put 'synindex 'texinfo-format 'texinfo-format-synindex) 2959(put 'syncodeindex 'texinfo-format 'texinfo-format-synindex) 2960 2961(defun texinfo-format-synindex () 2962 (let* ((args (texinfo-parse-arg-discard)) 2963 (second (cdr (read-from-string args))) 2964 (joiner (symbol-name (car (read-from-string args)))) 2965 (joined (symbol-name (car (read-from-string args second))))) 2966 2967 (if (assoc joiner texinfo-short-index-cmds-alist) 2968 (put 2969 (cdr (assoc joiner texinfo-short-index-cmds-alist)) 2970 'texinfo-format 2971 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist)) 2972 (intern (concat "texinfo-format-" joined "index")))) 2973 (put 2974 (intern (concat joiner "index")) 2975 'texinfo-format 2976 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist)) 2977 (intern (concat "texinfo-format-" joined "index"))))))) 2978 2979(defconst texinfo-short-index-cmds-alist 2980 '(("cp" . cindex) 2981 ("fn" . findex) 2982 ("vr" . vindex) 2983 ("tp" . tindex) 2984 ("pg" . pindex) 2985 ("ky" . kindex))) 2986 2987(defconst texinfo-short-index-format-cmds-alist 2988 '(("cp" . texinfo-format-cindex) 2989 ("fn" . texinfo-format-findex) 2990 ("vr" . texinfo-format-vindex) 2991 ("tp" . texinfo-format-tindex) 2992 ("pg" . texinfo-format-pindex) 2993 ("ky" . texinfo-format-kindex))) 2994 2995 2996;;; Sort and index (for VMS) 2997 2998;; Sort an index which is in the current buffer between START and END. 2999;; Used on VMS, where the `sort' utility is not available. 3000(defun texinfo-sort-region (start end) 3001 (require 'sort) 3002 (save-restriction 3003 (narrow-to-region start end) 3004 (goto-char (point-min)) 3005 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun))) 3006 3007;; Subroutine for sorting an index. 3008;; At start of a line, return a string to sort the line under. 3009(defun texinfo-sort-startkeyfun () 3010 (let ((line (buffer-substring-no-properties (point) (line-end-position)))) 3011 ;; Canonicalize whitespace and eliminate funny chars. 3012 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line) 3013 (setq line (concat (substring line 0 (match-beginning 0)) 3014 " " 3015 (substring line (match-end 0))))) 3016 line)) 3017 3018 3019;;; @printindex 3020 3021(put 'printindex 'texinfo-format 'texinfo-format-printindex) 3022 3023(defun texinfo-format-printindex () 3024 (let ((indexelts (symbol-value 3025 (cdr (assoc (texinfo-parse-arg-discard) 3026 texinfo-indexvar-alist)))) 3027 opoint) 3028 (insert "\n* Menu:\n\n") 3029 (setq opoint (point)) 3030 (texinfo-print-index nil indexelts) 3031 3032 (if (memq system-type '(vax-vms windows-nt ms-dos)) 3033 (texinfo-sort-region opoint (point)) 3034 (shell-command-on-region opoint (point) "sort -fd" 1)))) 3035 3036(defun texinfo-print-index (file indexelts) 3037 (while indexelts 3038 (if (stringp (car (car indexelts))) 3039 (progn 3040 (insert "* " (car (car indexelts)) ": " ) 3041 (indent-to 32) 3042 (insert 3043 (if file (concat "(" file ")") "") 3044 (nth 1 (car indexelts)) ".") 3045 (indent-to 54) 3046 (insert 3047 (if (nth 2 (car indexelts)) 3048 (format " (line %3d)" (1+ (nth 2 (car indexelts)))) 3049 "") 3050 "\n")) 3051 ;; index entries from @include'd file 3052 (texinfo-print-index (nth 1 (car indexelts)) 3053 (nth 2 (car indexelts)))) 3054 (setq indexelts (cdr indexelts)))) 3055 3056 3057;;; Glyphs: @equiv, @error, etc 3058 3059;; @equiv to show that two expressions are equivalent 3060;; @error to show an error message 3061;; @expansion to show what a macro expands to 3062;; @point to show the location of point in an example 3063;; @print to show what an evaluated expression prints 3064;; @result to indicate the value returned by an expression 3065 3066(put 'equiv 'texinfo-format 'texinfo-format-equiv) 3067(defun texinfo-format-equiv () 3068 (texinfo-parse-arg-discard) 3069 (insert "==")) 3070 3071(put 'error 'texinfo-format 'texinfo-format-error) 3072(defun texinfo-format-error () 3073 (texinfo-parse-arg-discard) 3074 (insert "error-->")) 3075 3076(put 'expansion 'texinfo-format 'texinfo-format-expansion) 3077(defun texinfo-format-expansion () 3078 (texinfo-parse-arg-discard) 3079 (insert "==>")) 3080 3081(put 'point 'texinfo-format 'texinfo-format-point) 3082(defun texinfo-format-point () 3083 (texinfo-parse-arg-discard) 3084 (insert "-!-")) 3085 3086(put 'print 'texinfo-format 'texinfo-format-print) 3087(defun texinfo-format-print () 3088 (texinfo-parse-arg-discard) 3089 (insert "-|")) 3090 3091(put 'result 'texinfo-format 'texinfo-format-result) 3092(defun texinfo-format-result () 3093 (texinfo-parse-arg-discard) 3094 (insert "=>")) 3095 3096 3097;;; Accent commands 3098 3099;; Info presumes a plain ASCII output, so the accented characters do 3100;; not look as they would if typeset, or output with a different 3101;; character set. 3102 3103;; See the `texinfo-accent-commands' variable 3104;; in the section for `texinfo-append-refill'. 3105;; Also, see the defun for `texinfo-format-scan' 3106;; for single-character accent commands. 3107 3108;; Command Info output Name 3109 3110;; These do not have braces: 3111;; @^ ==> ^ circumflex accent 3112;; @` ==> ` grave accent 3113;; @' ==> ' acute accent 3114;; @" ==> " umlaut accent 3115;; @= ==> = overbar accent 3116;; @~ ==> ~ tilde accent 3117 3118;; These have braces, but take no argument: 3119;; @OE{} ==> OE French-OE-ligature 3120;; @oe{} ==> oe 3121;; @AA{} ==> AA Scandinavian-A-with-circle 3122;; @aa{} ==> aa 3123;; @AE{} ==> AE Latin-Scandinavian-AE 3124;; @ae{} ==> ae 3125;; @ss{} ==> ss German-sharp-S 3126 3127;; @questiondown{} ==> ? upside-down-question-mark 3128;; @exclamdown{} ==> ! upside-down-exclamation-mark 3129;; @L{} ==> L/ Polish suppressed-L (Lslash) 3130;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case) 3131;; @O{} ==> O/ Scandinavian O-with-slash 3132;; @o{} ==> o/ Scandinavian O-with-slash (lower case) 3133 3134;; These have braces, and take an argument: 3135;; @,{c} ==> c, cedilla accent 3136;; @dotaccent{o} ==> .o overdot-accent 3137;; @ubaraccent{o} ==> _o underbar-accent 3138;; @udotaccent{o} ==> o-. underdot-accent 3139;; @H{o} ==> ""o long Hungarian umlaut 3140;; @ringaccent{o} ==> *o ring accent 3141;; @tieaccent{oo} ==> [oo tie after accent 3142;; @u{o} ==> (o breve accent 3143;; @v{o} ==> <o hacek accent 3144;; @dotless{i} ==> i dotless i and dotless j 3145 3146;; ========== 3147 3148;; Note: The defun texinfo-format-scan 3149;; looks at "[@{}^'`\",=~ *?!-]" 3150;; In the case of @*, a line break is inserted; 3151;; in the other cases, the characters are simply quoted and the @ is deleted. 3152;; Thus, `texinfo-format-scan' handles the following 3153;; single-character accent commands: @^ @` @' @" @, @- @= @~ 3154 3155;; @^ ==> ^ circumflex accent 3156;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent) 3157;; (defun texinfo-format-circumflex-accent () 3158;; (texinfo-discard-command) 3159;; (insert "^")) 3160;; 3161;; @` ==> ` grave accent 3162;; (put '\` 'texinfo-format 'texinfo-format-grave-accent) 3163;; (defun texinfo-format-grave-accent () 3164;; (texinfo-discard-command) 3165;; (insert "\`")) 3166;; 3167;; @' ==> ' acute accent 3168;; (put '\' 'texinfo-format 'texinfo-format-acute-accent) 3169;; (defun texinfo-format-acute-accent () 3170;; (texinfo-discard-command) 3171;; (insert "'")) 3172;; 3173;; @" ==> " umlaut accent 3174;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent) 3175;; (defun texinfo-format-umlaut-accent () 3176;; (texinfo-discard-command) 3177;; (insert "\"")) 3178;; 3179;; @= ==> = overbar accent 3180;; (put '= 'texinfo-format 'texinfo-format-overbar-accent) 3181;; (defun texinfo-format-overbar-accent () 3182;; (texinfo-discard-command) 3183;; (insert "=")) 3184;; 3185;; @~ ==> ~ tilde accent 3186;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent) 3187;; (defun texinfo-format-tilde-accent () 3188;; (texinfo-discard-command) 3189;; (insert "~")) 3190 3191;; @OE{} ==> OE French-OE-ligature 3192(put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature) 3193(defun texinfo-format-French-OE-ligature () 3194 (insert "OE" (texinfo-parse-arg-discard)) 3195 (goto-char texinfo-command-start)) 3196 3197;; @oe{} ==> oe 3198(put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature) 3199(defun texinfo-format-French-oe-ligature () ; lower case 3200 (insert "oe" (texinfo-parse-arg-discard)) 3201 (goto-char texinfo-command-start)) 3202 3203;; @AA{} ==> AA Scandinavian-A-with-circle 3204(put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle) 3205(defun texinfo-format-Scandinavian-A-with-circle () 3206 (insert "AA" (texinfo-parse-arg-discard)) 3207 (goto-char texinfo-command-start)) 3208 3209;; @aa{} ==> aa 3210(put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle) 3211(defun texinfo-format-Scandinavian-a-with-circle () ; lower case 3212 (insert "aa" (texinfo-parse-arg-discard)) 3213 (goto-char texinfo-command-start)) 3214 3215;; @AE{} ==> AE Latin-Scandinavian-AE 3216(put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE) 3217(defun texinfo-format-Latin-Scandinavian-AE () 3218 (insert "AE" (texinfo-parse-arg-discard)) 3219 (goto-char texinfo-command-start)) 3220 3221;; @ae{} ==> ae 3222(put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae) 3223(defun texinfo-format-Latin-Scandinavian-ae () ; lower case 3224 (insert "ae" (texinfo-parse-arg-discard)) 3225 (goto-char texinfo-command-start)) 3226 3227;; @ss{} ==> ss German-sharp-S 3228(put 'ss 'texinfo-format 'texinfo-format-German-sharp-S) 3229(defun texinfo-format-German-sharp-S () 3230 (insert "ss" (texinfo-parse-arg-discard)) 3231 (goto-char texinfo-command-start)) 3232 3233;; @questiondown{} ==> ? upside-down-question-mark 3234(put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark) 3235(defun texinfo-format-upside-down-question-mark () 3236 (insert "?" (texinfo-parse-arg-discard)) 3237 (goto-char texinfo-command-start)) 3238 3239;; @exclamdown{} ==> ! upside-down-exclamation-mark 3240(put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark) 3241(defun texinfo-format-upside-down-exclamation-mark () 3242 (insert "!" (texinfo-parse-arg-discard)) 3243 (goto-char texinfo-command-start)) 3244 3245;; @L{} ==> L/ Polish suppressed-L (Lslash) 3246(put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L) 3247(defun texinfo-format-Polish-suppressed-L () 3248 (insert (texinfo-parse-arg-discard) "/L") 3249 (goto-char texinfo-command-start)) 3250 3251;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case) 3252(put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case) 3253(defun texinfo-format-Polish-suppressed-l-lower-case () 3254 (insert (texinfo-parse-arg-discard) "/l") 3255 (goto-char texinfo-command-start)) 3256 3257 3258;; @O{} ==> O/ Scandinavian O-with-slash 3259(put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash) 3260(defun texinfo-format-Scandinavian-O-with-slash () 3261 (insert (texinfo-parse-arg-discard) "O/") 3262 (goto-char texinfo-command-start)) 3263 3264;; @o{} ==> o/ Scandinavian O-with-slash (lower case) 3265(put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case) 3266(defun texinfo-format-Scandinavian-o-with-slash-lower-case () 3267 (insert (texinfo-parse-arg-discard) "o/") 3268 (goto-char texinfo-command-start)) 3269 3270;; Take arguments 3271 3272;; @,{c} ==> c, cedilla accent 3273(put ', 'texinfo-format 'texinfo-format-cedilla-accent) 3274(defun texinfo-format-cedilla-accent () 3275 (insert (texinfo-parse-arg-discard) ",") 3276 (goto-char texinfo-command-start)) 3277 3278 3279;; @dotaccent{o} ==> .o overdot-accent 3280(put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent) 3281(defun texinfo-format-overdot-accent () 3282 (insert "." (texinfo-parse-arg-discard)) 3283 (goto-char texinfo-command-start)) 3284 3285;; @ubaraccent{o} ==> _o underbar-accent 3286(put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent) 3287(defun texinfo-format-underbar-accent () 3288 (insert "_" (texinfo-parse-arg-discard)) 3289 (goto-char texinfo-command-start)) 3290 3291;; @udotaccent{o} ==> o-. underdot-accent 3292(put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent) 3293(defun texinfo-format-underdot-accent () 3294 (insert (texinfo-parse-arg-discard) "-.") 3295 (goto-char texinfo-command-start)) 3296 3297;; @H{o} ==> ""o long Hungarian umlaut 3298(put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut) 3299(defun texinfo-format-long-Hungarian-umlaut () 3300 (insert "\"\"" (texinfo-parse-arg-discard)) 3301 (goto-char texinfo-command-start)) 3302 3303;; @ringaccent{o} ==> *o ring accent 3304(put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent) 3305(defun texinfo-format-ring-accent () 3306 (insert "*" (texinfo-parse-arg-discard)) 3307 (goto-char texinfo-command-start)) 3308 3309;; @tieaccent{oo} ==> [oo tie after accent 3310(put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent) 3311(defun texinfo-format-tie-after-accent () 3312 (insert "[" (texinfo-parse-arg-discard)) 3313 (goto-char texinfo-command-start)) 3314 3315 3316;; @u{o} ==> (o breve accent 3317(put 'u 'texinfo-format 'texinfo-format-breve-accent) 3318(defun texinfo-format-breve-accent () 3319 (insert "(" (texinfo-parse-arg-discard)) 3320 (goto-char texinfo-command-start)) 3321 3322;; @v{o} ==> <o hacek accent 3323(put 'v 'texinfo-format 'texinfo-format-hacek-accent) 3324(defun texinfo-format-hacek-accent () 3325 (insert "<" (texinfo-parse-arg-discard)) 3326 (goto-char texinfo-command-start)) 3327 3328 3329;; @dotless{i} ==> i dotless i and dotless j 3330(put 'dotless 'texinfo-format 'texinfo-format-dotless) 3331(defun texinfo-format-dotless () 3332 (insert (texinfo-parse-arg-discard)) 3333 (goto-char texinfo-command-start)) 3334 3335 3336;;; Definition formatting: @deffn, @defun, etc 3337 3338;; What definition formatting produces: 3339;; 3340;; @deffn category name args... 3341;; In Info, `Category: name ARGS' 3342;; In index: name: node. line#. 3343;; 3344;; @defvr category name 3345;; In Info, `Category: name' 3346;; In index: name: node. line#. 3347;; 3348;; @deftp category name attributes... 3349;; `category name attributes...' Note: @deftp args in lower case. 3350;; In index: name: node. line#. 3351;; 3352;; Specialized function-like or variable-like entity: 3353;; 3354;; @defun, @defmac, @defspec, @defvar, @defopt 3355;; 3356;; @defun name args In Info, `Function: name ARGS' 3357;; @defmac name args In Info, `Macro: name ARGS' 3358;; @defvar name In Info, `Variable: name' 3359;; etc. 3360;; In index: name: node. line#. 3361;; 3362;; Generalized typed-function-like or typed-variable-like entity: 3363;; @deftypefn category data-type name args... 3364;; In Info, `Category: data-type name args...' 3365;; @deftypevr category data-type name 3366;; In Info, `Category: data-type name' 3367;; In index: name: node. line#. 3368;; 3369;; Specialized typed-function-like or typed-variable-like entity: 3370;; @deftypefun data-type name args... 3371;; In Info, `Function: data-type name ARGS' 3372;; In index: name: node. line#. 3373;; 3374;; @deftypevar data-type name 3375;; In Info, `Variable: data-type name' 3376;; In index: name: node. line#. but include args after name!? 3377;; 3378;; Generalized object oriented entity: 3379;; @defop category class name args... 3380;; In Info, `Category on class: name ARG' 3381;; In index: name on class: node. line#. 3382;; 3383;; @defcv category class name 3384;; In Info, `Category of class: name' 3385;; In index: name of class: node. line#. 3386;; 3387;; Specialized object oriented entity: 3388;; @defmethod class name args... 3389;; In Info, `Method on class: name ARGS' 3390;; In index: name on class: node. line#. 3391;; 3392;; @defivar class name 3393;; In Info, `Instance variable of class: name' 3394;; In index: name of class: node. line#. 3395 3396 3397;;; The definition formatting functions 3398 3399(defun texinfo-format-defun () 3400 (texinfo-push-stack 'defun nil) 3401 (setq fill-column (- fill-column 5)) 3402 (texinfo-format-defun-1 t)) 3403 3404(defun texinfo-end-defun () 3405 (setq fill-column (+ fill-column 5)) 3406 (texinfo-discard-command) 3407 (let ((start (nth 1 (texinfo-pop-stack 'defun)))) 3408 (texinfo-do-itemize start) 3409 ;; Delete extra newline inserted after header. 3410 (save-excursion 3411 (goto-char start) 3412 (delete-char -1)))) 3413 3414(defun texinfo-format-defunx () 3415 (texinfo-format-defun-1 nil)) 3416 3417(defun texinfo-format-defun-1 (first-p) 3418 (let ((parse-args (texinfo-format-parse-defun-args)) 3419 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type))) 3420 (texinfo-discard-command) 3421 ;; Delete extra newline inserted after previous header line. 3422 (if (not first-p) 3423 (delete-char -1)) 3424 (funcall 3425 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args) 3426 ;; Insert extra newline so that paragraph filling does not mess 3427 ;; with header line. 3428 (insert "\n\n") 3429 (rplaca (cdr (cdr (car texinfo-stack))) (point)) 3430 (funcall 3431 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args))) 3432 3433;;; Formatting the first line of a definition 3434 3435;; @deffn, @defvr, @deftp 3436(put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3437(put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3438(put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3439(put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3440(put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3441(put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn) 3442(defun texinfo-format-deffn (parsed-args) 3443 ;; Generalized function-like, variable-like, or generic data-type entity: 3444 ;; @deffn category name args... 3445 ;; In Info, `Category: name ARGS' 3446 ;; @deftp category name attributes... 3447 ;; `category name attributes...' Note: @deftp args in lower case. 3448 (let ((category (car parsed-args)) 3449 (name (car (cdr parsed-args))) 3450 (args (cdr (cdr parsed-args)))) 3451 (insert " -- " category ": " name) 3452 (while args 3453 (insert " " 3454 (if (or (= ?& (aref (car args) 0)) 3455 (eq (eval (car texinfo-defun-type)) 'deftp-type)) 3456 (car args) 3457 (upcase (car args)))) 3458 (setq args (cdr args))))) 3459 3460;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple 3461(put 'defun 'texinfo-deffn-formatting-property 3462 'texinfo-format-specialized-defun) 3463(put 'defunx 'texinfo-deffn-formatting-property 3464 'texinfo-format-specialized-defun) 3465(put 'defmac 'texinfo-deffn-formatting-property 3466 'texinfo-format-specialized-defun) 3467(put 'defmacx 'texinfo-deffn-formatting-property 3468 'texinfo-format-specialized-defun) 3469(put 'defspec 'texinfo-deffn-formatting-property 3470 'texinfo-format-specialized-defun) 3471(put 'defspecx 'texinfo-deffn-formatting-property 3472 'texinfo-format-specialized-defun) 3473(put 'defvar 'texinfo-deffn-formatting-property 3474 'texinfo-format-specialized-defun) 3475(put 'defvarx 'texinfo-deffn-formatting-property 3476 'texinfo-format-specialized-defun) 3477(put 'defopt 'texinfo-deffn-formatting-property 3478 'texinfo-format-specialized-defun) 3479(put 'defoptx 'texinfo-deffn-formatting-property 3480 'texinfo-format-specialized-defun) 3481(defun texinfo-format-specialized-defun (parsed-args) 3482 ;; Specialized function-like or variable-like entity: 3483 ;; @defun name args In Info, `Function: Name ARGS' 3484 ;; @defmac name args In Info, `Macro: Name ARGS' 3485 ;; @defvar name In Info, `Variable: Name' 3486 ;; Use cdr of texinfo-defun-type to determine category: 3487 (let ((category (car (cdr texinfo-defun-type))) 3488 (name (car parsed-args)) 3489 (args (cdr parsed-args))) 3490 (insert " -- " category ": " name) 3491 (while args 3492 (insert " " 3493 (if (= ?& (aref (car args) 0)) 3494 (car args) 3495 (upcase (car args)))) 3496 (setq args (cdr args))))) 3497 3498;; @deftypefn, @deftypevr: Generalized typed 3499(put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) 3500(put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) 3501(put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) 3502(put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn) 3503(defun texinfo-format-deftypefn (parsed-args) 3504 ;; Generalized typed-function-like or typed-variable-like entity: 3505 ;; @deftypefn category data-type name args... 3506 ;; In Info, `Category: data-type name args...' 3507 ;; @deftypevr category data-type name 3508 ;; In Info, `Category: data-type name' 3509 ;; Note: args in lower case, unless modified in command line. 3510 (let ((category (car parsed-args)) 3511 (data-type (car (cdr parsed-args))) 3512 (name (car (cdr (cdr parsed-args)))) 3513 (args (cdr (cdr (cdr parsed-args))))) 3514 (insert " -- " category ": " data-type " " name) 3515 (while args 3516 (insert " " (car args)) 3517 (setq args (cdr args))))) 3518 3519;; @deftypefun, @deftypevar: Specialized typed 3520(put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun) 3521(put 'deftypefunx 'texinfo-deffn-formatting-property 3522 'texinfo-format-deftypefun) 3523(put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun) 3524(put 'deftypevarx 'texinfo-deffn-formatting-property 3525 'texinfo-format-deftypefun) 3526(defun texinfo-format-deftypefun (parsed-args) 3527 ;; Specialized typed-function-like or typed-variable-like entity: 3528 ;; @deftypefun data-type name args... 3529 ;; In Info, `Function: data-type name ARGS' 3530 ;; @deftypevar data-type name 3531 ;; In Info, `Variable: data-type name' 3532 ;; Note: args in lower case, unless modified in command line. 3533 ;; Use cdr of texinfo-defun-type to determine category: 3534 (let ((category (car (cdr texinfo-defun-type))) 3535 (data-type (car parsed-args)) 3536 (name (car (cdr parsed-args))) 3537 (args (cdr (cdr parsed-args)))) 3538 (insert " -- " category ": " data-type " " name) 3539 (while args 3540 (insert " " (car args)) 3541 (setq args (cdr args))))) 3542 3543;; @defop: Generalized object-oriented 3544(put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop) 3545(put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop) 3546(defun texinfo-format-defop (parsed-args) 3547 ;; Generalized object oriented entity: 3548 ;; @defop category class name args... 3549 ;; In Info, `Category on class: name ARG' 3550 ;; Note: args in upper case; use of `on' 3551 (let ((category (car parsed-args)) 3552 (class (car (cdr parsed-args))) 3553 (name (car (cdr (cdr parsed-args)))) 3554 (args (cdr (cdr (cdr parsed-args))))) 3555 (insert " -- " category " on " class ": " name) 3556 (while args 3557 (insert " " (upcase (car args))) 3558 (setq args (cdr args))))) 3559 3560;; @defcv: Generalized object-oriented 3561(put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv) 3562(put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv) 3563(defun texinfo-format-defcv (parsed-args) 3564 ;; Generalized object oriented entity: 3565 ;; @defcv category class name 3566 ;; In Info, `Category of class: name' 3567 ;; Note: args in upper case; use of `of' 3568 (let ((category (car parsed-args)) 3569 (class (car (cdr parsed-args))) 3570 (name (car (cdr (cdr parsed-args)))) 3571 (args (cdr (cdr (cdr parsed-args))))) 3572 (insert " -- " category " of " class ": " name) 3573 (while args 3574 (insert " " (upcase (car args))) 3575 (setq args (cdr args))))) 3576 3577;; @defmethod: Specialized object-oriented 3578(put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod) 3579(put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod) 3580(defun texinfo-format-defmethod (parsed-args) 3581 ;; Specialized object oriented entity: 3582 ;; @defmethod class name args... 3583 ;; In Info, `Method on class: name ARGS' 3584 ;; Note: args in upper case; use of `on' 3585 ;; Use cdr of texinfo-defun-type to determine category: 3586 (let ((category (car (cdr texinfo-defun-type))) 3587 (class (car parsed-args)) 3588 (name (car (cdr parsed-args))) 3589 (args (cdr (cdr parsed-args)))) 3590 (insert " -- " category " on " class ": " name) 3591 (while args 3592 (insert " " (upcase (car args))) 3593 (setq args (cdr args))))) 3594 3595;; @defivar: Specialized object-oriented 3596(put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar) 3597(put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar) 3598(defun texinfo-format-defivar (parsed-args) 3599 ;; Specialized object oriented entity: 3600 ;; @defivar class name 3601 ;; In Info, `Instance variable of class: name' 3602 ;; Note: args in upper case; use of `of' 3603 ;; Use cdr of texinfo-defun-type to determine category: 3604 (let ((category (car (cdr texinfo-defun-type))) 3605 (class (car parsed-args)) 3606 (name (car (cdr parsed-args))) 3607 (args (cdr (cdr parsed-args)))) 3608 (insert " -- " category " of " class ": " name) 3609 (while args 3610 (insert " " (upcase (car args))) 3611 (setq args (cdr args))))) 3612 3613 3614;;; Indexing for definitions 3615 3616;; An index entry has three parts: the `entry proper', the node name, and the 3617;; line number. Depending on the which command is used, the entry is 3618;; formatted differently: 3619;; 3620;; @defun, 3621;; @defmac, 3622;; @defspec, 3623;; @defvar, 3624;; @defopt all use their 1st argument as the entry-proper 3625;; 3626;; @deffn, 3627;; @defvr, 3628;; @deftp 3629;; @deftypefun 3630;; @deftypevar all use their 2nd argument as the entry-proper 3631;; 3632;; @deftypefn, 3633;; @deftypevr both use their 3rd argument as the entry-proper 3634;; 3635;; @defmethod uses its 2nd and 1st arguments as an entry-proper 3636;; formatted: NAME on CLASS 3637 3638;; @defop uses its 3rd and 2nd arguments as an entry-proper 3639;; formatted: NAME on CLASS 3640;; 3641;; @defivar uses its 2nd and 1st arguments as an entry-proper 3642;; formatted: NAME of CLASS 3643;; 3644;; @defcv uses its 3rd and 2nd argument as an entry-proper 3645;; formatted: NAME of CLASS 3646 3647(put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun) 3648(put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun) 3649(put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun) 3650(put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun) 3651(put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun) 3652(put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun) 3653(put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun) 3654(put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun) 3655(put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun) 3656(put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun) 3657(defun texinfo-index-defun (parsed-args) 3658 ;; use 1st parsed-arg as entry-proper 3659 ;; `index-list' will be texinfo-findex or the like 3660 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3661 (set index-list 3662 (cons 3663 ;; Three elements: entry-proper, node-name, line-number 3664 (list 3665 (car parsed-args) 3666 texinfo-last-node 3667 ;; Region formatting may not provide last node position. 3668 (if texinfo-last-node-pos 3669 (1+ (count-lines texinfo-last-node-pos (point))) 3670 1)) 3671 (symbol-value index-list))))) 3672 3673(put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3674(put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3675(put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3676(put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3677(put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3678(put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3679(put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3680(put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3681(put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3682(put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn) 3683(defun texinfo-index-deffn (parsed-args) 3684 ;; use 2nd parsed-arg as entry-proper 3685 ;; `index-list' will be texinfo-findex or the like 3686 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3687 (set index-list 3688 (cons 3689 ;; Three elements: entry-proper, node-name, line-number 3690 (list 3691 (car (cdr parsed-args)) 3692 texinfo-last-node 3693 ;; Region formatting may not provide last node position. 3694 (if texinfo-last-node-pos 3695 (1+ (count-lines texinfo-last-node-pos (point))) 3696 1)) 3697 (symbol-value index-list))))) 3698 3699(put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) 3700(put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) 3701(put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) 3702(put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn) 3703(defun texinfo-index-deftypefn (parsed-args) 3704 ;; use 3rd parsed-arg as entry-proper 3705 ;; `index-list' will be texinfo-findex or the like 3706 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3707 (set index-list 3708 (cons 3709 ;; Three elements: entry-proper, node-name, line-number 3710 (list 3711 (car (cdr (cdr parsed-args))) 3712 texinfo-last-node 3713 ;; Region formatting may not provide last node position. 3714 (if texinfo-last-node-pos 3715 (1+ (count-lines texinfo-last-node-pos (point))) 3716 1)) 3717 (symbol-value index-list))))) 3718 3719(put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod) 3720(put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod) 3721(defun texinfo-index-defmethod (parsed-args) 3722 ;; use 2nd on 1st parsed-arg as entry-proper 3723 ;; `index-list' will be texinfo-findex or the like 3724 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3725 (set index-list 3726 (cons 3727 ;; Three elements: entry-proper, node-name, line-number 3728 (list 3729 (format "%s on %s" 3730 (car (cdr parsed-args)) 3731 (car parsed-args)) 3732 texinfo-last-node 3733 ;; Region formatting may not provide last node position. 3734 (if texinfo-last-node-pos 3735 (1+ (count-lines texinfo-last-node-pos (point))) 3736 1)) 3737 (symbol-value index-list))))) 3738 3739(put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop) 3740(put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop) 3741(defun texinfo-index-defop (parsed-args) 3742 ;; use 3rd on 2nd parsed-arg as entry-proper 3743 ;; `index-list' will be texinfo-findex or the like 3744 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3745 (set index-list 3746 (cons 3747 ;; Three elements: entry-proper, node-name, line-number 3748 (list 3749 (format "%s on %s" 3750 (car (cdr (cdr parsed-args))) 3751 (car (cdr parsed-args))) 3752 texinfo-last-node 3753 ;; Region formatting may not provide last node position. 3754 (if texinfo-last-node-pos 3755 (1+ (count-lines texinfo-last-node-pos (point))) 3756 1)) 3757 (symbol-value index-list))))) 3758 3759(put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar) 3760(put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar) 3761(defun texinfo-index-defivar (parsed-args) 3762 ;; use 2nd of 1st parsed-arg as entry-proper 3763 ;; `index-list' will be texinfo-findex or the like 3764 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3765 (set index-list 3766 (cons 3767 ;; Three elements: entry-proper, node-name, line-number 3768 (list 3769 (format "%s of %s" 3770 (car (cdr parsed-args)) 3771 (car parsed-args)) 3772 texinfo-last-node 3773 ;; Region formatting may not provide last node position. 3774 (if texinfo-last-node-pos 3775 (1+ (count-lines texinfo-last-node-pos (point))) 3776 1)) 3777 (symbol-value index-list))))) 3778 3779(put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv) 3780(put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv) 3781(defun texinfo-index-defcv (parsed-args) 3782 ;; use 3rd of 2nd parsed-arg as entry-proper 3783 ;; `index-list' will be texinfo-findex or the like 3784 (let ((index-list (get texinfo-command-name 'texinfo-defun-index))) 3785 (set index-list 3786 (cons 3787 ;; Three elements: entry-proper, node-name, line-number 3788 (list 3789 (format "%s of %s" 3790 (car (cdr (cdr parsed-args))) 3791 (car (cdr parsed-args))) 3792 texinfo-last-node 3793 ;; Region formatting may not provide last node position. 3794 (if texinfo-last-node-pos 3795 (1+ (count-lines texinfo-last-node-pos (point))) 3796 1)) 3797 (symbol-value index-list))))) 3798 3799 3800;;; Properties for definitions 3801 3802;; Each definition command has six properties: 3803;; 3804;; 1. texinfo-deffn-formatting-property to format definition line 3805;; 2. texinfo-defun-indexing-property to create index entry 3806;; 3. texinfo-format formatting command 3807;; 4. texinfo-end end formatting command 3808;; 5. texinfo-defun-type type of deffn to format 3809;; 6. texinfo-defun-index type of index to use 3810;; 3811;; The `x' forms of each definition command are used for the second 3812;; and subsequent header lines. 3813 3814;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property 3815;; are listed just before the appropriate formatting and indexing commands. 3816 3817(put 'deffn 'texinfo-format 'texinfo-format-defun) 3818(put 'deffnx 'texinfo-format 'texinfo-format-defunx) 3819(put 'deffn 'texinfo-end 'texinfo-end-defun) 3820(put 'deffn 'texinfo-defun-type '('deffn-type nil)) 3821(put 'deffnx 'texinfo-defun-type '('deffn-type nil)) 3822(put 'deffn 'texinfo-defun-index 'texinfo-findex) 3823(put 'deffnx 'texinfo-defun-index 'texinfo-findex) 3824 3825(put 'defun 'texinfo-format 'texinfo-format-defun) 3826(put 'defunx 'texinfo-format 'texinfo-format-defunx) 3827(put 'defun 'texinfo-end 'texinfo-end-defun) 3828(put 'defun 'texinfo-defun-type '('defun-type "Function")) 3829(put 'defunx 'texinfo-defun-type '('defun-type "Function")) 3830(put 'defun 'texinfo-defun-index 'texinfo-findex) 3831(put 'defunx 'texinfo-defun-index 'texinfo-findex) 3832 3833(put 'defmac 'texinfo-format 'texinfo-format-defun) 3834(put 'defmacx 'texinfo-format 'texinfo-format-defunx) 3835(put 'defmac 'texinfo-end 'texinfo-end-defun) 3836(put 'defmac 'texinfo-defun-type '('defun-type "Macro")) 3837(put 'defmacx 'texinfo-defun-type '('defun-type "Macro")) 3838(put 'defmac 'texinfo-defun-index 'texinfo-findex) 3839(put 'defmacx 'texinfo-defun-index 'texinfo-findex) 3840 3841(put 'defspec 'texinfo-format 'texinfo-format-defun) 3842(put 'defspecx 'texinfo-format 'texinfo-format-defunx) 3843(put 'defspec 'texinfo-end 'texinfo-end-defun) 3844(put 'defspec 'texinfo-defun-type '('defun-type "Special form")) 3845(put 'defspecx 'texinfo-defun-type '('defun-type "Special form")) 3846(put 'defspec 'texinfo-defun-index 'texinfo-findex) 3847(put 'defspecx 'texinfo-defun-index 'texinfo-findex) 3848 3849(put 'defvr 'texinfo-format 'texinfo-format-defun) 3850(put 'defvrx 'texinfo-format 'texinfo-format-defunx) 3851(put 'defvr 'texinfo-end 'texinfo-end-defun) 3852(put 'defvr 'texinfo-defun-type '('deffn-type nil)) 3853(put 'defvrx 'texinfo-defun-type '('deffn-type nil)) 3854(put 'defvr 'texinfo-defun-index 'texinfo-vindex) 3855(put 'defvrx 'texinfo-defun-index 'texinfo-vindex) 3856 3857(put 'defvar 'texinfo-format 'texinfo-format-defun) 3858(put 'defvarx 'texinfo-format 'texinfo-format-defunx) 3859(put 'defvar 'texinfo-end 'texinfo-end-defun) 3860(put 'defvar 'texinfo-defun-type '('defun-type "Variable")) 3861(put 'defvarx 'texinfo-defun-type '('defun-type "Variable")) 3862(put 'defvar 'texinfo-defun-index 'texinfo-vindex) 3863(put 'defvarx 'texinfo-defun-index 'texinfo-vindex) 3864 3865(put 'defconst 'texinfo-format 'texinfo-format-defun) 3866(put 'defconstx 'texinfo-format 'texinfo-format-defunx) 3867(put 'defconst 'texinfo-end 'texinfo-end-defun) 3868(put 'defconst 'texinfo-defun-type '('defun-type "Constant")) 3869(put 'defconstx 'texinfo-defun-type '('defun-type "Constant")) 3870(put 'defconst 'texinfo-defun-index 'texinfo-vindex) 3871(put 'defconstx 'texinfo-defun-index 'texinfo-vindex) 3872 3873(put 'defcmd 'texinfo-format 'texinfo-format-defun) 3874(put 'defcmdx 'texinfo-format 'texinfo-format-defunx) 3875(put 'defcmd 'texinfo-end 'texinfo-end-defun) 3876(put 'defcmd 'texinfo-defun-type '('defun-type "Command")) 3877(put 'defcmdx 'texinfo-defun-type '('defun-type "Command")) 3878(put 'defcmd 'texinfo-defun-index 'texinfo-findex) 3879(put 'defcmdx 'texinfo-defun-index 'texinfo-findex) 3880 3881(put 'defopt 'texinfo-format 'texinfo-format-defun) 3882(put 'defoptx 'texinfo-format 'texinfo-format-defunx) 3883(put 'defopt 'texinfo-end 'texinfo-end-defun) 3884(put 'defopt 'texinfo-defun-type '('defun-type "User Option")) 3885(put 'defoptx 'texinfo-defun-type '('defun-type "User Option")) 3886(put 'defopt 'texinfo-defun-index 'texinfo-vindex) 3887(put 'defoptx 'texinfo-defun-index 'texinfo-vindex) 3888 3889(put 'deftp 'texinfo-format 'texinfo-format-defun) 3890(put 'deftpx 'texinfo-format 'texinfo-format-defunx) 3891(put 'deftp 'texinfo-end 'texinfo-end-defun) 3892(put 'deftp 'texinfo-defun-type '('deftp-type nil)) 3893(put 'deftpx 'texinfo-defun-type '('deftp-type nil)) 3894(put 'deftp 'texinfo-defun-index 'texinfo-tindex) 3895(put 'deftpx 'texinfo-defun-index 'texinfo-tindex) 3896 3897;;; Object-oriented stuff is a little hairier. 3898 3899(put 'defop 'texinfo-format 'texinfo-format-defun) 3900(put 'defopx 'texinfo-format 'texinfo-format-defunx) 3901(put 'defop 'texinfo-end 'texinfo-end-defun) 3902(put 'defop 'texinfo-defun-type '('defop-type nil)) 3903(put 'defopx 'texinfo-defun-type '('defop-type nil)) 3904(put 'defop 'texinfo-defun-index 'texinfo-findex) 3905(put 'defopx 'texinfo-defun-index 'texinfo-findex) 3906 3907(put 'defmethod 'texinfo-format 'texinfo-format-defun) 3908(put 'defmethodx 'texinfo-format 'texinfo-format-defunx) 3909(put 'defmethod 'texinfo-end 'texinfo-end-defun) 3910(put 'defmethod 'texinfo-defun-type '('defmethod-type "Method")) 3911(put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method")) 3912(put 'defmethod 'texinfo-defun-index 'texinfo-findex) 3913(put 'defmethodx 'texinfo-defun-index 'texinfo-findex) 3914 3915(put 'defcv 'texinfo-format 'texinfo-format-defun) 3916(put 'defcvx 'texinfo-format 'texinfo-format-defunx) 3917(put 'defcv 'texinfo-end 'texinfo-end-defun) 3918(put 'defcv 'texinfo-defun-type '('defop-type nil)) 3919(put 'defcvx 'texinfo-defun-type '('defop-type nil)) 3920(put 'defcv 'texinfo-defun-index 'texinfo-vindex) 3921(put 'defcvx 'texinfo-defun-index 'texinfo-vindex) 3922 3923(put 'defivar 'texinfo-format 'texinfo-format-defun) 3924(put 'defivarx 'texinfo-format 'texinfo-format-defunx) 3925(put 'defivar 'texinfo-end 'texinfo-end-defun) 3926(put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable")) 3927(put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable")) 3928(put 'defivar 'texinfo-defun-index 'texinfo-vindex) 3929(put 'defivarx 'texinfo-defun-index 'texinfo-vindex) 3930 3931;;; Typed functions and variables 3932 3933(put 'deftypefn 'texinfo-format 'texinfo-format-defun) 3934(put 'deftypefnx 'texinfo-format 'texinfo-format-defunx) 3935(put 'deftypefn 'texinfo-end 'texinfo-end-defun) 3936(put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil)) 3937(put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil)) 3938(put 'deftypefn 'texinfo-defun-index 'texinfo-findex) 3939(put 'deftypefnx 'texinfo-defun-index 'texinfo-findex) 3940 3941(put 'deftypefun 'texinfo-format 'texinfo-format-defun) 3942(put 'deftypefunx 'texinfo-format 'texinfo-format-defunx) 3943(put 'deftypefun 'texinfo-end 'texinfo-end-defun) 3944(put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function")) 3945(put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function")) 3946(put 'deftypefun 'texinfo-defun-index 'texinfo-findex) 3947(put 'deftypefunx 'texinfo-defun-index 'texinfo-findex) 3948 3949(put 'deftypevr 'texinfo-format 'texinfo-format-defun) 3950(put 'deftypevrx 'texinfo-format 'texinfo-format-defunx) 3951(put 'deftypevr 'texinfo-end 'texinfo-end-defun) 3952(put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil)) 3953(put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil)) 3954(put 'deftypevr 'texinfo-defun-index 'texinfo-vindex) 3955(put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex) 3956 3957(put 'deftypevar 'texinfo-format 'texinfo-format-defun) 3958(put 'deftypevarx 'texinfo-format 'texinfo-format-defunx) 3959(put 'deftypevar 'texinfo-end 'texinfo-end-defun) 3960(put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable")) 3961(put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable")) 3962(put 'deftypevar 'texinfo-defun-index 'texinfo-vindex) 3963(put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex) 3964 3965 3966;;; @set, @clear, @ifset, @ifclear 3967 3968;; If a flag is set with @set FLAG, then text between @ifset and @end 3969;; ifset is formatted normally, but if the flag is is cleared with 3970;; @clear FLAG, then the text is not formatted; it is ignored. 3971 3972;; If a flag is cleared with @clear FLAG, then text between @ifclear 3973;; and @end ifclear is formatted normally, but if the flag is is set with 3974;; @set FLAG, then the text is not formatted; it is ignored. @ifclear 3975;; is the opposite of @ifset. 3976 3977;; If a flag is set to a string with @set FLAG, 3978;; replace @value{FLAG} with the string. 3979;; If a flag with a value is cleared, 3980;; @value{FLAG} is invalid, 3981;; as if there had never been any @set FLAG previously. 3982 3983(put 'clear 'texinfo-format 'texinfo-clear) 3984(defun texinfo-clear () 3985 "Clear the value of the flag." 3986 (let* ((arg (texinfo-parse-arg-discard)) 3987 (flag (car (read-from-string arg))) 3988 (value (substring arg (cdr (read-from-string arg))))) 3989 (put flag 'texinfo-whether-setp 'flag-cleared) 3990 (put flag 'texinfo-set-value ""))) 3991 3992(put 'set 'texinfo-format 'texinfo-set) 3993(defun texinfo-set () 3994 "Set the value of the flag, optionally to a string. 3995The command `@set foo This is a string.' 3996sets flag foo to the value: `This is a string.' 3997The command `@value{foo}' expands to the value." 3998 (let* ((arg (texinfo-parse-arg-discard)) 3999 (flag (car (read-from-string arg))) 4000 (value (substring arg (cdr (read-from-string arg))))) 4001 (if (string-match "^[ \t]+" value) 4002 (setq value (substring value (match-end 0)))) 4003 (put flag 'texinfo-whether-setp 'flag-set) 4004 (put flag 'texinfo-set-value value))) 4005 4006(put 'value 'texinfo-format 'texinfo-value) 4007(defun texinfo-value () 4008 "Insert the string to which the flag is set. 4009The command `@set foo This is a string.' 4010sets flag foo to the value: `This is a string.' 4011The command `@value{foo}' expands to the value." 4012 (let ((arg (texinfo-parse-arg-discard))) 4013 (cond ((and 4014 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4015 'flag-set) 4016 (get (car (read-from-string arg)) 'texinfo-set-value)) 4017 (insert (get (car (read-from-string arg)) 'texinfo-set-value))) 4018 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4019 'flag-cleared) 4020 (insert (format "{No value for \"%s\"}" arg))) 4021 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil) 4022 (insert (format "{No value for \"%s\"}" arg)))))) 4023 4024(put 'ifset 'texinfo-end 'texinfo-discard-command) 4025(put 'ifset 'texinfo-format 'texinfo-if-set) 4026(defun texinfo-if-set () 4027 "If set, continue formatting; else do not format region up to @end ifset" 4028 (let ((arg (texinfo-parse-arg-discard))) 4029 (cond 4030 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4031 'flag-set) 4032 ;; Format the text (i.e., do not remove it); do nothing here. 4033 ()) 4034 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4035 'flag-cleared) 4036 ;; Clear region (i.e., cause the text to be ignored). 4037 (delete-region texinfo-command-start 4038 (re-search-forward "@end ifset[ \t]*\n"))) 4039 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4040 nil) 4041 ;; In this case flag is neither set nor cleared. 4042 ;; Act as if set, i.e. do nothing. 4043 ())))) 4044 4045(put 'ifclear 'texinfo-end 'texinfo-discard-command) 4046(put 'ifclear 'texinfo-format 'texinfo-if-clear) 4047(defun texinfo-if-clear () 4048 "If clear, continue formatting; if set, do not format up to @end ifset" 4049 (let ((arg (texinfo-parse-arg-discard))) 4050 (cond 4051 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4052 'flag-set) 4053 ;; Clear region (i.e., cause the text to be ignored). 4054 (delete-region texinfo-command-start 4055 (re-search-forward "@end ifclear[ \t]*\n"))) 4056 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4057 'flag-cleared) 4058 ;; Format the text (i.e., do not remove it); do nothing here. 4059 ()) 4060 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 4061 nil) 4062 ;; In this case flag is neither set nor cleared. 4063 ;; Act as if clear, i.e. do nothing. 4064 ())))) 4065 4066;;; @ifeq 4067 4068(put 'ifeq 'texinfo-format 'texinfo-format-ifeq) 4069(defun texinfo-format-ifeq () 4070 "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND. 4071Otherwise produces no output. 4072 4073Thus: 4074 @ifeq{ arg1 , arg1 , @code{foo}} bar 4075 4076 ==> `foo' bar. 4077but 4078 @ifeq{ arg1 , arg2 , @code{foo}} bar 4079 4080 ==> bar 4081 4082Note that the Texinfo command and its arguments must be arguments to 4083the @ifeq command." 4084 ;; compare-buffer-substrings does not exist in version 18; don't use 4085 (goto-char texinfo-command-end) 4086 (let* ((case-fold-search t) 4087 (stop (save-excursion (forward-sexp 1) (point))) 4088 start end 4089 ;; @ifeq{arg1, arg2, @command{optional-args}} 4090 (arg1 4091 (progn 4092 (forward-char 1) 4093 (skip-chars-forward " ") 4094 (setq start (point)) 4095 (search-forward "," stop t) 4096 (skip-chars-backward ", ") 4097 (buffer-substring-no-properties start (point)))) 4098 (arg2 4099 (progn 4100 (search-forward "," stop t) 4101 (skip-chars-forward " ") 4102 (setq start (point)) 4103 (search-forward "," stop t) 4104 (skip-chars-backward ", ") 4105 (buffer-substring-no-properties start (point)))) 4106 (texinfo-command 4107 (progn 4108 (search-forward "," stop t) 4109 (skip-chars-forward " ") 4110 (setq start (point)) 4111 (goto-char (1- stop)) 4112 (skip-chars-backward " ") 4113 (buffer-substring-no-properties start (point))))) 4114 (delete-region texinfo-command-start stop) 4115 (if (equal arg1 arg2) 4116 (insert texinfo-command)) 4117 (goto-char texinfo-command-start))) 4118 4119 4120;;; Process included files: `@include' command 4121 4122;; Updated 19 October 1990 4123;; In the original version, include files were ignored by Info but 4124;; incorporated in to the printed manual. To make references to the 4125;; included file, the Texinfo source file has to refer to the included 4126;; files using the `(filename)nodename' format for referring to other 4127;; Info files. Also, the included files had to be formatted on their 4128;; own. It was just like they were another file. 4129 4130;; Currently, include files are inserted into the buffer that is 4131;; formatted for Info. If large, the resulting info file is split and 4132;; tagified. For current include files to work, the master menu must 4133;; refer to all the nodes, and the highest level nodes in the include 4134;; files must have the correct next, prev, and up pointers. 4135 4136;; The included file may have an @setfilename and even an @settitle, 4137;; but not an `\input texinfo' line. 4138 4139;; Updated 24 March 1993 4140;; In order for @raisesections and @lowersections to work, included 4141;; files must be inserted into the buffer holding the outer file 4142;; before other Info formatting takes place. So @include is no longer 4143;; is treated like other @-commands. 4144(put 'include 'texinfo-format 'texinfo-format-noop) 4145 4146;; Original definition: 4147;; (defun texinfo-format-include () 4148;; (let ((filename (texinfo-parse-arg-discard)) 4149;; (default-directory input-directory) 4150;; subindex) 4151;; (setq subindex 4152;; (save-excursion 4153;; (progn (find-file 4154;; (cond ((file-readable-p (concat filename ".texinfo")) 4155;; (concat filename ".texinfo")) 4156;; ((file-readable-p (concat filename ".texi")) 4157;; (concat filename ".texi")) 4158;; ((file-readable-p (concat filename ".tex")) 4159;; (concat filename ".tex")) 4160;; ((file-readable-p filename) 4161;; filename) 4162;; (t (error "@include'd file %s not found" 4163;; filename)))) 4164;; (texinfo-format-buffer-1)))) 4165;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex)) 4166;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex)) 4167;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex)) 4168;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex)) 4169;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex)) 4170;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex)))) 4171;; 4172;;(defun texinfo-subindex (indexvar file content) 4173;; (set indexvar (cons (list 'recurse file content) 4174;; (symbol-value indexvar)))) 4175 4176;; Second definition: 4177;; (put 'include 'texinfo-format 'texinfo-format-include) 4178;; (defun texinfo-format-include () 4179;; (let ((filename (concat input-directory 4180;; (texinfo-parse-arg-discard))) 4181;; (default-directory input-directory)) 4182;; (message "Reading: %s" filename) 4183;; (save-excursion 4184;; (save-restriction 4185;; (narrow-to-region 4186;; (point) 4187;; (+ (point) (car (cdr (insert-file-contents filename))))) 4188;; (goto-char (point-min)) 4189;; (texinfo-append-refill) 4190;; (texinfo-format-convert (point-min) (point-max)))) 4191;; (setq last-input-buffer input-buffer) ; to bypass setfilename 4192;; )) 4193 4194 4195;;; Numerous commands do nothing in Info 4196;; These commands are defined in texinfo.tex for printed output. 4197 4198 4199;;; various noops, such as @b{foo}, that take arguments in braces 4200 4201(put 'b 'texinfo-format 'texinfo-format-noop) 4202(put 'i 'texinfo-format 'texinfo-format-noop) 4203(put 'r 'texinfo-format 'texinfo-format-noop) 4204(put 't 'texinfo-format 'texinfo-format-noop) 4205(put 'w 'texinfo-format 'texinfo-format-noop) 4206(put 'asis 'texinfo-format 'texinfo-format-noop) 4207(put 'dmn 'texinfo-format 'texinfo-format-noop) 4208(put 'math 'texinfo-format 'texinfo-format-noop) 4209(put 'titlefont 'texinfo-format 'texinfo-format-noop) 4210(defun texinfo-format-noop () 4211 (insert (texinfo-parse-arg-discard)) 4212 (goto-char texinfo-command-start)) 4213 4214;; @hyphenation command discards an argument within braces 4215(put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg) 4216(defun texinfo-discard-command-and-arg () 4217 "Discard both @-command and its argument in braces." 4218 (goto-char texinfo-command-end) 4219 (forward-list 1) 4220 (setq texinfo-command-end (point)) 4221 (delete-region texinfo-command-start texinfo-command-end)) 4222 4223 4224;;; Do nothing commands, such as @smallbook, that have no args and no braces 4225;; These must appear on a line of their own 4226 4227(put 'bye 'texinfo-format 'texinfo-discard-line) 4228(put 'smallbook 'texinfo-format 'texinfo-discard-line) 4229(put 'finalout 'texinfo-format 'texinfo-discard-line) 4230(put 'overfullrule 'texinfo-format 'texinfo-discard-line) 4231(put 'smallbreak 'texinfo-format 'texinfo-discard-line) 4232(put 'medbreak 'texinfo-format 'texinfo-discard-line) 4233(put 'bigbreak 'texinfo-format 'texinfo-discard-line) 4234(put 'afourpaper 'texinfo-format 'texinfo-discard-line) 4235(put 'afivepaper 'texinfo-format 'texinfo-discard-line) 4236(put 'afourlatex 'texinfo-format 'texinfo-discard-line) 4237(put 'afourwide 'texinfo-format 'texinfo-discard-line) 4238 4239 4240;;; These noop commands discard the rest of the line. 4241 4242(put 'c 'texinfo-format 'texinfo-discard-line-with-args) 4243(put 'comment 'texinfo-format 'texinfo-discard-line-with-args) 4244(put 'contents 'texinfo-format 'texinfo-discard-line-with-args) 4245(put 'group 'texinfo-end 'texinfo-discard-line-with-args) 4246(put 'group 'texinfo-format 'texinfo-discard-line-with-args) 4247(put 'headings 'texinfo-format 'texinfo-discard-line-with-args) 4248(put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args) 4249(put 'hsize 'texinfo-format 'texinfo-discard-line-with-args) 4250(put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args) 4251(put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args) 4252(put 'need 'texinfo-format 'texinfo-discard-line-with-args) 4253(put 'nopara 'texinfo-format 'texinfo-discard-line-with-args) 4254 4255;; @novalidate suppresses cross-reference checking and auxiliary file 4256;; creation with TeX. The Info-validate command checks that every 4257;; node pointer points to an existing node. Since this Info command 4258;; is not invoked automatically, the @novalidate command is irrelevant 4259;; and not supported by texinfmt.el 4260(put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args) 4261 4262(put 'page 'texinfo-format 'texinfo-discard-line-with-args) 4263(put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args) 4264(put 'parindent 'texinfo-format 'texinfo-discard-line-with-args) 4265(put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args) 4266(put 'setq 'texinfo-format 'texinfo-discard-line-with-args) 4267 4268(put 'setcontentsaftertitlepage 4269 'texinfo-format 'texinfo-discard-line-with-args) 4270(put 'setshortcontentsaftertitlepage 4271 'texinfo-format 'texinfo-discard-line-with-args) 4272 4273(put 'settitle 'texinfo-format 'texinfo-discard-line-with-args) 4274(put 'setx 'texinfo-format 'texinfo-discard-line-with-args) 4275(put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args) 4276(put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args) 4277(put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args) 4278(put 'input 'texinfo-format 'texinfo-discard-line-with-args) 4279 4280(put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args) 4281(put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args) 4282 4283 4284 4285;;; Some commands cannot be handled 4286 4287(defun texinfo-unsupported () 4288 (error "%s is not handled by texinfo" 4289 (buffer-substring-no-properties texinfo-command-start texinfo-command-end))) 4290 4291;;; Batch formatting 4292 4293(defun batch-texinfo-format () 4294 "Runs texinfo-format-buffer on the files remaining on the command line. 4295Must be used only with -batch, and kills Emacs on completion. 4296Each file will be processed even if an error occurred previously. 4297For example, invoke 4298 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"." 4299 (if (not noninteractive) 4300 (error "batch-texinfo-format may only be used -batch")) 4301 (let ((version-control t) 4302 (auto-save-default nil) 4303 (find-file-run-dired nil) 4304 (kept-old-versions 259259) 4305 (kept-new-versions 259259)) 4306 (let ((error 0) 4307 file 4308 (files ())) 4309 (while command-line-args-left 4310 (setq file (expand-file-name (car command-line-args-left))) 4311 (cond ((not (file-exists-p file)) 4312 (message ">> %s does not exist!" file) 4313 (setq error 1 4314 command-line-args-left (cdr command-line-args-left))) 4315 ((file-directory-p file) 4316 (setq command-line-args-left 4317 (nconc (directory-files file) 4318 (cdr command-line-args-left)))) 4319 (t 4320 (setq files (cons file files) 4321 command-line-args-left (cdr command-line-args-left))))) 4322 (while files 4323 (setq file (car files) 4324 files (cdr files)) 4325 (condition-case err 4326 (progn 4327 (if buffer-file-name (kill-buffer (current-buffer))) 4328 (find-file file) 4329 (buffer-disable-undo (current-buffer)) 4330 (set-buffer-modified-p nil) 4331 (texinfo-mode) 4332 (message "texinfo formatting %s..." file) 4333 (texinfo-format-buffer nil) 4334 (if (buffer-modified-p) 4335 (progn (message "Saving modified %s" (buffer-file-name)) 4336 (save-buffer)))) 4337 (error 4338 (message ">> Error: %s" (prin1-to-string err)) 4339 (message ">> point at") 4340 (let ((s (buffer-substring-no-properties (point) 4341 (min (+ (point) 100) 4342 (point-max)))) 4343 (tem 0)) 4344 (while (setq tem (string-match "\n+" s tem)) 4345 (setq s (concat (substring s 0 (match-beginning 0)) 4346 "\n>> " 4347 (substring s (match-end 0))) 4348 tem (1+ tem))) 4349 (message ">> %s" s)) 4350 (setq error 1)))) 4351 (kill-emacs error)))) 4352 4353 4354;;; Place `provide' at end of file. 4355(provide 'texinfmt) 4356 4357;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 4358;;; texinfmt.el ends here 4359