home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / AP5 / TEXINFO.TGZ / TEXINFO.tar / usr / share / emacs / site-lisp / texinfmt.el < prev    next >
Lisp/Scheme  |  1996-09-10  |  148KB  |  3,980 lines

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