home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / gnu / texinfo / texinfmt.el < prev    next >
Encoding:
Text File  |  1992-06-11  |  99.3 KB  |  2,687 lines

  1. ;;;; texinfmt.el
  2.  
  3. ;;; Emacs lisp functions to convert Texinfo files to Info files.
  4.  
  5. ;;; Version 2.23      10 June 1992
  6. ;;; Robert J. Chassell          
  7. ;;; Please send bug reports to:  bob@gnu.ai.mit.edu
  8.  
  9. ;;; Copyright (C) 1985, 1986, 1988,
  10. ;;;               1990, 1991, 1992  Free Software Foundation, Inc.
  11.  
  12.  
  13. ;;; This file is part of GNU Emacs.
  14.  
  15. ;; GNU Emacs is free software; you can redistribute it and/or modify
  16. ;; it under the terms of the GNU General Public License as published by
  17. ;; the Free Software Foundation; either version 2, or (at your option)
  18. ;; any later version.
  19.  
  20. ;; GNU Emacs is distributed in the hope that it will be useful,
  21. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. ;; GNU General Public License for more details.
  24.  
  25. ;; You should have received a copy of the GNU General Public License
  26. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  27. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  
  29.  
  30. ;;; Variable definitions
  31.  
  32. (require 'texinfo)              ; So `texinfo-footnote-style' is defined.
  33.  
  34. (defvar texinfo-format-syntax-table nil)
  35.  
  36. (defvar texinfo-vindex)
  37. (defvar texinfo-findex)
  38. (defvar texinfo-cindex)
  39. (defvar texinfo-pindex)
  40. (defvar texinfo-tindex)
  41. (defvar texinfo-kindex)
  42. (defvar texinfo-last-node)
  43. (defvar texinfo-node-names)
  44. (defvar texinfo-enclosure-list)
  45.  
  46.  
  47. ;;; Syntax table
  48.  
  49. (if texinfo-format-syntax-table
  50.     nil
  51.   (setq texinfo-format-syntax-table (make-syntax-table))
  52.   (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
  53.   (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
  54.   (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
  55.   (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
  56.   (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
  57.   (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
  58.   (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
  59.   (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
  60.   (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
  61.   (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
  62.   (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
  63.  
  64.  
  65. ;;; Top level buffer and region formatting functions
  66.  
  67. (defun texinfo-format-buffer (&optional notagify)
  68.   "Process the current buffer as texinfo code, into an Info file.
  69. The Info file output is generated in a buffer visiting the Info file
  70. names specified in the @setfilename command.
  71.  
  72. Non-nil argument (prefix, if interactive) means don't make tag table
  73. and don't split the file if large.  You can use Info-tagify and
  74. Info-split to do these manually."
  75.   (interactive "P")
  76.   (let ((lastmessage "Formatting Info file..."))
  77.     (message lastmessage)
  78.     (texinfo-format-buffer-1)
  79.     (if notagify
  80.         nil
  81.       (if (> (buffer-size) 30000)
  82.           (progn
  83.             (message (setq lastmessage "Making tags table for Info file..."))
  84.             (Info-tagify)))
  85.       (if (> (buffer-size) 100000)
  86.           (progn
  87.             (message (setq lastmessage "Splitting Info file..."))
  88.             (Info-split))))
  89.     (message (concat lastmessage
  90.                      (if (interactive-p) "done.  Now save it." "done.")))))
  91.  
  92. (defvar texinfo-region-buffer-name "*Info Region*"
  93.   "*Name of the temporary buffer used by \\[texinfo-format-region].")
  94.  
  95. (defun texinfo-format-region (region-beginning region-ending)
  96.   "Convert the current region of the Texinfo file to Info format.
  97. This lets you see what that part of the file will look like in Info.
  98. The command is bound to \\[texinfo-format-region].  The text that is
  99. converted to Info is stored in a temporary buffer."
  100.   (interactive "r")
  101.   (message "Converting region to Info format...")
  102.   (let (texinfo-command-start
  103.         texinfo-command-end
  104.         texinfo-command-name
  105.         texinfo-vindex
  106.         texinfo-findex
  107.         texinfo-cindex
  108.         texinfo-pindex
  109.         texinfo-tindex
  110.         texinfo-kindex
  111.         texinfo-stack
  112.         texinfo-format-filename
  113.         texinfo-example-start
  114.         texinfo-last-node-pos
  115.         texinfo-last-node
  116.         texinfo-node-names
  117.     (texinfo-footnote-number 0)
  118.         last-input-buffer
  119.         (fill-column-for-info fill-column)
  120.         (input-buffer (current-buffer))
  121.         (input-directory default-directory)
  122.         filename-or-header
  123.         filename-or-header-beginning
  124.         filename-or-header-end)
  125.     
  126. ;;; Find a buffer to use.
  127.     
  128.     (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
  129.     (erase-buffer)
  130.  
  131.     ;; Insert the region into the buffer.
  132.     
  133.     ;; First, find file name or tell of its absence.
  134.     ;; Second, insert lines between beginning and end of header lines, 
  135.     ;;    if any, or else insert the filename.
  136.     ;; Third, insert region.
  137.     
  138.     (save-excursion
  139.       (set-buffer input-buffer)
  140.       (save-excursion
  141.         (save-restriction
  142.           (widen)
  143.           (goto-char (point-min))
  144.           (let ((search-end (save-excursion (forward-line 100) (point))))
  145.             
  146.             ;; Find the filename or else explain that a filename is needed.
  147.             (or (search-forward "@setfilename" search-end t)
  148.                 (error
  149.                  "The texinfo file needs a line saying: @setfilename <name>"))
  150.             
  151.             ;; Find header and copy it into buffer; or copy just the 
  152.             ;;     filename if no header.
  153.             (goto-char (point-min))
  154.             (if (and 
  155.                  (prog1 
  156.                      (search-forward texinfo-start-of-header search-end t)
  157.                    (beginning-of-line)
  158.                    ;; Mark beginning of header.
  159.                    (setq filename-or-header-beginning (point)))
  160.                  (prog1 
  161.                      (search-forward texinfo-end-of-header nil t)
  162.                    (beginning-of-line)
  163.                    ;; Mark end of header
  164.                    (setq filename-or-header-end (point)))) 
  165.                 
  166.                 ;; Copy header  
  167.                 (setq filename-or-header 
  168.                       (buffer-substring
  169.                        (min filename-or-header-beginning region-beginning)
  170.                       filename-or-header-end))
  171.               ;; Else no header; insert @filename line in buffer
  172.               (goto-char (point-min))
  173.               (search-forward "@setfilename" search-end t)
  174.               (beginning-of-line)
  175.               (setq filename-or-header-beginning (point))
  176.               (forward-line 1)
  177.               (setq filename-or-header-end (point))
  178.               (setq filename-or-header 
  179.                     (buffer-substring 
  180.                      (min filename-or-header-beginning region-beginning)  
  181.                      filename-or-header-end)))))))
  182.     
  183.     ;; Insert the filename or header into the buffer.
  184.     (insert filename-or-header)
  185.     ;; Insert the region into the buffer.
  186.     (insert-buffer-substring
  187.      input-buffer
  188.      (max region-beginning filename-or-header-end)
  189.      region-ending)
  190.     ;; Make sure region ends in a newline.
  191.     (or (= (preceding-char) ?\n)
  192.         (insert "\n"))
  193.     
  194.     (texinfo-mode)
  195.     (setq fill-column fill-column-for-info)
  196.  
  197.     ;; Install a syntax table useful for scanning command operands.
  198.     (set-syntax-table texinfo-format-syntax-table)
  199.     ;; Append @refill to appropriate paragraphs
  200.     (goto-char (point-min))
  201.     (message "Converting region to Info format...")
  202.     (texinfo-append-refill)
  203.     ;; If the region includes the effective end of the data,
  204.     ;; discard everything after that.
  205.     (goto-char (point-max))
  206.     (if (re-search-backward "^@bye" nil t)
  207.         (delete-region (point) (point-max)))
  208.     ;; Make sure buffer ends in a newline.
  209.     (or (= (preceding-char) ?\n)
  210.         (insert "\n"))
  211.     ;; Don't use a previous value of texinfo-enclosure-list.
  212.     (setq texinfo-enclosure-list nil)
  213.  
  214.     ;; Now convert for real.
  215.     (goto-char (point-min))
  216.     (texinfo-format-scan)
  217.     (goto-char (point-min))
  218.     
  219.     (message "Done.")))
  220.  
  221.  
  222. ;;; Primary internal formatting function for the whole buffer.
  223.  
  224. (defun texinfo-format-buffer-1 ()
  225.   (let (texinfo-format-filename
  226.         texinfo-example-start
  227.         texinfo-command-start
  228.         texinfo-command-end
  229.         texinfo-command-name
  230.         texinfo-last-node
  231.         texinfo-last-node-pos
  232.         texinfo-vindex
  233.         texinfo-findex
  234.         texinfo-cindex
  235.         texinfo-pindex
  236.         texinfo-tindex
  237.         texinfo-kindex
  238.         texinfo-stack
  239.         texinfo-node-names
  240.     (texinfo-footnote-number 0)
  241.         last-input-buffer
  242.         outfile
  243.         (fill-column-for-info fill-column)
  244.         (input-buffer (current-buffer))
  245.         (input-directory default-directory))
  246.     (setq texinfo-enclosure-list nil)
  247.     (save-excursion
  248.       (goto-char (point-min))
  249.       (search-forward "@setfilename")
  250.       (setq texinfo-command-end (point))
  251.       (setq outfile (texinfo-parse-line-arg)))
  252.     (find-file outfile)
  253.     (texinfo-mode)
  254.     (setq fill-column fill-column-for-info)
  255.     (set-syntax-table texinfo-format-syntax-table)
  256.     (erase-buffer)
  257.     (insert-buffer-substring input-buffer)
  258.     ;; Append @refill to appropriate paragraphs
  259.     (goto-char (point-min))
  260.     (message "Converting %s to Info format..." (buffer-name input-buffer))
  261.     (texinfo-append-refill)
  262.     (goto-char (point-min))
  263.     (search-forward "@setfilename")
  264.     (beginning-of-line)
  265.     (delete-region (point-min) (point))
  266.     ;; Remove @bye at end of file, if it is there.
  267.     (goto-char (point-max))
  268.     (if (search-backward "@bye" nil t)
  269.         (delete-region (point) (point-max)))
  270.     ;; Make sure buffer ends in a newline.
  271.     (or (= (preceding-char) ?\n)
  272.         (insert "\n"))
  273.     ;; Scan the whole buffer, converting to Info format.
  274.     (texinfo-format-scan)
  275.     ;; Return data for indices.
  276.     (goto-char (point-min))
  277.     (list outfile
  278.           texinfo-vindex texinfo-findex texinfo-cindex
  279.           texinfo-pindex texinfo-tindex texinfo-kindex)))
  280.  
  281.  
  282. ;;; Perform non-@-command file conversions
  283.  
  284. (defun texinfo-format-convert (min max)
  285.   ;; Convert left and right quotes to typewriter font quotes.
  286.   (goto-char min)
  287.   (while (search-forward "``" max t)
  288.     (replace-match "\""))
  289.   (goto-char min)
  290.   (while (search-forward "''" max t)
  291.     (replace-match "\""))
  292.   ;; Convert three hyphens in a row to two.
  293.   (goto-char min)
  294.   (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
  295.     (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
  296.     2)))))
  297.  
  298. (defvar texinfo-no-refill-regexp
  299.   "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|tex\\)"
  300.   "Regexp specifying environments in which paragraphs are not filled.")
  301.  
  302. (defvar texinfo-part-of-para-regexp
  303.   "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
  304.   "Regexp specifying @-commands found within paragraphs.")
  305.  
  306. (defun texinfo-append-refill ()
  307.   "Append @refill at end of each paragraph that should be filled.
  308. Do not append @refill to paragraphs within @example and similar environments.  
  309. Do not append @refill to paragraphs containing @w{TEXT} or @*."
  310.  
  311.   ;; It is necessary to append @refill before other processing because
  312.   ;; the other processing removes information that tells Texinfo
  313.   ;; whether the text should or should not be filled.
  314.   
  315.   (while (< (point) (point-max))
  316.     (let ((refill-blank-lines "^[ \t\n]*$")
  317.           (case-fold-search nil))       ; Don't confuse @TeX and @tex....
  318.       (beginning-of-line)
  319.       ;; 1. Skip over blank lines;
  320.       ;;    skip over lines beginning with @-commands, 
  321.       ;;    but do not skip over lines
  322.       ;;      that are no-refill environments such as @example or
  323.       ;;      that begin with within-paragraph @-commands such as @code.
  324.       (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
  325.                   (not (looking-at 
  326.                         (concat
  327.                          "\\(" 
  328.                          texinfo-no-refill-regexp
  329.                          "\\|" 
  330.                          texinfo-part-of-para-regexp
  331.                          "\\)")))
  332.                   (< (point) (point-max)))
  333.         (forward-line 1))
  334.       ;; 2. Skip over @example and similar no-refill environments.
  335.       (if (looking-at texinfo-no-refill-regexp)
  336.           (let ((environment
  337.                  (buffer-substring (match-beginning 1) (match-end 1))))
  338.             (progn (re-search-forward (concat "^@end " environment) nil t)
  339.                    (forward-line 1)))
  340.         ;; 3. Do not refill a paragraph containing @w or @*
  341.         (if  (or
  342.               (>= (point) (point-max))
  343.               (re-search-forward
  344.                "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
  345.             ;; Go to end of paragraph and do nothing.
  346.             (forward-paragraph) 
  347.           ;; 4. Else go to end of paragraph and insert @refill
  348.           (forward-paragraph)
  349.           (forward-line -1)
  350.           (end-of-line)
  351.           (delete-region
  352.            (point)
  353.            (save-excursion (skip-chars-backward " \t") (point)))
  354.           ;; `looking-at-backward' not available in v. 18.57
  355.           ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
  356.           (if (not (re-search-backward
  357.                     "@refill\\|@bye"
  358.                     (save-excursion (beginning-of-line) (point))
  359.                     t))
  360.               (insert "@refill"))
  361.           (forward-line 1))))))
  362.  
  363.  
  364. ;;; Perform those texinfo-to-info conversions that apply to the whole input
  365. ;;; uniformly.
  366.  
  367. (defun texinfo-format-scan ()
  368.   (texinfo-format-convert (point-min) (point-max))
  369.   ;; Scan for @-commands.
  370.   (goto-char (point-min))
  371.   (while (search-forward "@" nil t)
  372.     (if (looking-at "[@{}'` *]")
  373.         ;; Handle a few special @-followed-by-one-char commands.
  374.         (if (= (following-char) ?*)
  375.             (progn
  376.               ;; remove command
  377.               (delete-region (1- (point)) (1+ (point)))
  378.               ;; insert return if not at end of line;
  379.               ;; else line is already broken.
  380.               (if (not (= (following-char) ?\n))
  381.                   (insert ?\n)))      
  382.           ;; The other characters are simply quoted.  Delete the @.
  383.           (delete-char -1)
  384.           (forward-char 1))
  385.       ;; @ is followed by a command-word; find the end of the word.
  386.       (setq texinfo-command-start (1- (point)))
  387.       (if (= (char-syntax (following-char)) ?w)
  388.           (forward-word 1)
  389.         (forward-char 1))
  390.       (setq texinfo-command-end (point))
  391.       ;; Call the handler for this command.
  392.       (setq texinfo-command-name
  393.             (intern (buffer-substring
  394.              (1+ texinfo-command-start) texinfo-command-end)))
  395.       (let ((enclosure-type
  396.              (assoc
  397.               (symbol-name texinfo-command-name)
  398.               texinfo-enclosure-list)))
  399.         (if enclosure-type
  400.             (progn
  401.               (insert
  402.                (car (car (cdr enclosure-type))) 
  403.                (texinfo-parse-arg-discard)
  404.                (car (cdr (car (cdr enclosure-type)))))
  405.               (goto-char texinfo-command-start))
  406.           (let ((cmd (get texinfo-command-name 'texinfo-format)))
  407.             (if cmd (funcall cmd) (texinfo-unsupported)))))))
  408.   
  409.   (cond (texinfo-stack
  410.          (goto-char (nth 2 (car texinfo-stack)))
  411.          (error "Unterminated @%s" (car (car texinfo-stack))))))
  412.  
  413. (put 'begin 'texinfo-format 'texinfo-format-begin)
  414. (defun texinfo-format-begin ()
  415.   (texinfo-format-begin-end 'texinfo-format))
  416.  
  417. (put 'end 'texinfo-format 'texinfo-format-end)
  418. (defun texinfo-format-end ()
  419.   (texinfo-format-begin-end 'texinfo-end))
  420.  
  421. (defun texinfo-format-begin-end (prop)
  422.   (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
  423.   (setq cmd (get texinfo-command-name prop))
  424.   (if cmd (funcall cmd)
  425.     (texinfo-unsupported)))
  426.  
  427. ;;; Parsing functions
  428.  
  429. (defun texinfo-parse-line-arg ()
  430.   (goto-char texinfo-command-end)
  431.   (let ((start (point)))
  432.     (cond ((looking-at " ")
  433.        (skip-chars-forward " ")
  434.        (setq start (point))
  435.        (end-of-line)
  436.            (skip-chars-backward " ")
  437.            (delete-region (point) (progn (end-of-line) (point)))
  438.        (setq texinfo-command-end (1+ (point))))
  439.       ((looking-at "{")
  440.        (setq start (1+ (point)))
  441.        (forward-list 1)
  442.        (setq texinfo-command-end (point))
  443.        (forward-char -1))
  444.       (t
  445.        (error "Invalid texinfo command arg format")))
  446.     (prog1 (buffer-substring start (point))
  447.        (if (eolp) (forward-char 1)))))
  448.  
  449. (defun texinfo-parse-expanded-arg ()
  450.   (goto-char texinfo-command-end)
  451.   (let ((start (point))
  452.     marker)
  453.     (cond ((looking-at " ")
  454.        (skip-chars-forward " ")
  455.        (setq start (point))
  456.        (end-of-line)
  457.        (setq texinfo-command-end (1+ (point))))
  458.       ((looking-at "{")
  459.        (setq start (1+ (point)))
  460.        (forward-list 1)
  461.        (setq texinfo-command-end (point))
  462.        (forward-char -1))
  463.       (t
  464.        (error "Invalid texinfo command arg format")))
  465.     (setq marker (move-marker (make-marker) texinfo-command-end))
  466.     (texinfo-format-expand-region start (point))
  467.     (setq texinfo-command-end (marker-position marker))
  468.     (move-marker marker nil)
  469.     (prog1 (buffer-substring start (point))
  470.        (if (eolp) (forward-char 1)))))
  471.  
  472. (defun texinfo-format-expand-region (start end)
  473.   (save-restriction
  474.     (narrow-to-region start end)
  475.     (let (texinfo-command-start
  476.       texinfo-command-end
  477.       texinfo-command-name
  478.       texinfo-stack)
  479.       (texinfo-format-scan))
  480.     (goto-char (point-max))))
  481.  
  482. (defun texinfo-parse-arg-discard ()
  483.   (prog1 (texinfo-parse-line-arg)
  484.      (texinfo-discard-command)))
  485.  
  486. (defun texinfo-discard-command ()
  487.   (delete-region texinfo-command-start texinfo-command-end))
  488.  
  489. (defun texinfo-optional-braces-discard ()
  490.   "Discard braces following command, if any."
  491.   (goto-char texinfo-command-end)
  492.   (let ((start (point)))
  493.     (cond ((looking-at "[ \t]*\n"))     ; do nothing
  494.           ((looking-at "{")             ; remove braces, if any
  495.        (forward-list 1)
  496.        (setq texinfo-command-end (point)))
  497.       (t
  498.            (error
  499.             "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
  500.     (delete-region texinfo-command-start texinfo-command-end)))
  501.  
  502. (defun texinfo-format-parse-line-args ()
  503.   (let ((start (1- (point)))
  504.     next beg end
  505.     args)
  506.     (skip-chars-forward " ")
  507.     (while (not (eolp))
  508.       (setq beg (point))
  509.       (re-search-forward "[\n,]")
  510.       (setq next (point))
  511.       (if (bolp) (setq next (1- next)))
  512.       (forward-char -1)
  513.       (skip-chars-backward " ")
  514.       (setq end (point))
  515.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  516.                args))
  517.       (goto-char next)
  518.       (skip-chars-forward " "))
  519.     (if (eolp) (forward-char 1))
  520.     (setq texinfo-command-end (point))
  521.     (nreverse args)))
  522.  
  523. (defun texinfo-format-parse-args ()
  524.   (let ((start (1- (point)))
  525.     next beg end
  526.     args)
  527.     (search-forward "{")
  528.     (save-excursion
  529.       (texinfo-format-expand-region 
  530.        (point)
  531.        (save-excursion (up-list 1) (1- (point)))))
  532.     ;; The following does not handle cross references of the form:
  533.     ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
  534.     ;; re-search-forward finds the first right brace after the second
  535.     ;; comma. 
  536.     (while (/= (preceding-char) ?\})
  537.       (skip-chars-forward " \t\n")
  538.       (setq beg (point))
  539.       (re-search-forward "[},]")
  540.       (setq next (point))
  541.       (forward-char -1)
  542.       (skip-chars-backward " \t\n")
  543.       (setq end (point))
  544.       (cond ((< beg end)
  545.          (goto-char beg)
  546.          (while (search-forward "\n" end t)
  547.            (replace-match " "))))
  548.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  549.                args))
  550.       (goto-char next))
  551.     (if (eolp) (forward-char 1))
  552.     (setq texinfo-command-end (point))
  553.     (nreverse args)))
  554.  
  555. (defun texinfo-format-parse-defun-args ()
  556.   (goto-char texinfo-command-end)
  557.   (let ((start (point)))
  558.     (end-of-line)
  559.     (setq texinfo-command-end (1+ (point)))
  560.     (let ((marker (move-marker (make-marker) texinfo-command-end)))
  561.       (texinfo-format-expand-region start (point))
  562.       (setq texinfo-command-end (marker-position marker))
  563.       (move-marker marker nil))
  564.     (goto-char start)
  565.     (let ((args '())
  566.       beg end)
  567.       (skip-chars-forward " ")
  568.       (while (not (eolp))
  569.     (cond ((looking-at "{")
  570.            (setq beg (1+ (point)))
  571.            (forward-list 1)
  572.            (setq end (1- (point))))
  573.           (t
  574.            (setq beg (point))
  575.            (re-search-forward "[\n ]")
  576.            (forward-char -1)
  577.            (setq end (point))))
  578.     (setq args (cons (buffer-substring beg end) args))
  579.     (skip-chars-forward " "))
  580.       (forward-char 1)
  581.       (nreverse args))))
  582.  
  583. (defun texinfo-discard-line ()
  584.   (goto-char texinfo-command-end)
  585.   (skip-chars-forward " \t")
  586.   (or (eolp)
  587.       (error "Extraneous text at end of command line."))
  588.   (goto-char texinfo-command-start)
  589.   (or (bolp)
  590.       (error "Extraneous text at beginning of command line."))
  591.   (delete-region (point) (progn (forward-line 1) (point))))
  592.  
  593. (defun texinfo-discard-line-with-args ()
  594.   (goto-char texinfo-command-start)
  595.   (delete-region (point) (progn (forward-line 1) (point))))
  596.  
  597.  
  598. ;;; @setfilename
  599.  
  600. ; 19 October 1990
  601. ; @setfilename modifed to work with include files; see @include
  602. ; (defun texinfo-format-setfilename ()
  603. ;   (let ((arg (texinfo-parse-arg-discard)))
  604. ;     (setq texinfo-format-filename
  605. ;       (file-name-nondirectory (expand-file-name arg)))
  606. ;     (insert "Info file: "
  607. ;         texinfo-format-filename ",    -*-Text-*-\n"
  608. ;         "produced by texinfo-format-buffer\nfrom "
  609. ;         (if (buffer-file-name input-buffer)
  610. ;         (concat "file: "
  611. ;             (file-name-sans-versions
  612. ;              (file-name-nondirectory
  613. ;               (buffer-file-name input-buffer))))
  614. ;           (concat "buffer " (buffer-name input-buffer)))
  615. ;         "\n\n")))
  616.  
  617. (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
  618. (defun texinfo-format-setfilename ()
  619.   (let ((arg (texinfo-parse-arg-discard)))
  620.     (if (eq input-buffer last-input-buffer)
  621.     nil                ; only use first setfilename in buffer
  622.       (message "Formatting Info file: %s" arg)
  623.       (setq texinfo-format-filename
  624.         (file-name-nondirectory (expand-file-name arg)))
  625.       (insert "Info file: "
  626.           texinfo-format-filename ",    -*-Text-*-\n"
  627.           "produced by texinfo-format-buffer\nfrom "
  628.           (if (buffer-file-name input-buffer)
  629.           (concat "file: "
  630.               (file-name-sans-versions
  631.                (file-name-nondirectory
  632.                 (buffer-file-name input-buffer))))
  633.         (concat "buffer " (buffer-name input-buffer)))
  634.           "\n\n"))))
  635.  
  636. ;;; @node, @menu
  637.  
  638. (put 'node 'texinfo-format 'texinfo-format-node)
  639. (defun texinfo-format-node ()
  640.   (let* ((args (texinfo-format-parse-line-args))
  641.      (name (nth 0 args))
  642.      (next (nth 1 args))
  643.      (prev (nth 2 args))
  644.      (up (nth 3 args)))
  645.     (texinfo-discard-command)
  646.     (setq texinfo-last-node name)
  647.     (let ((tem (downcase name)))
  648.       (if (assoc tem texinfo-node-names)
  649.       (error "Duplicate node name: %s" name)
  650.     (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
  651.     (setq texinfo-footnote-number 0)
  652.     (or (bolp)
  653.     (insert ?\n))
  654.     (insert "\^_\nFile: " texinfo-format-filename
  655.         ", Node: " name)
  656.     (if next
  657.     (insert ", Next: " next))
  658.     (if prev
  659.     (insert ", Prev: " prev))
  660.     (if up
  661.     (insert ", Up: " up))
  662.     (insert ?\n)
  663.     (setq texinfo-last-node-pos (point))))
  664.  
  665. (put 'menu 'texinfo-format 'texinfo-format-menu)
  666. (defun texinfo-format-menu ()
  667.   (texinfo-discard-line)
  668.   (insert "* Menu:\n\n"))
  669.  
  670. (put 'menu 'texinfo-end 'texinfo-discard-command)
  671.  
  672.  
  673. ;;; Cross references
  674.  
  675. ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
  676. ; -> *Note FNAME: (FILE)NODE
  677. ;   If FILE is missing,
  678. ;    *Note FNAME: NODE
  679. ;   If FNAME is empty and NAME is present
  680. ;    *Note NAME: Node
  681. ;   If both NAME and FNAME are missing
  682. ;    *Note NODE::
  683. ;   texinfo ignores the DOCUMENT argument.
  684. ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  685. ;   If FILE is specified, (FILE)NODE is used for xrefs.
  686. ;   If fifth argument DOCUMENT is specified, produces
  687. ;    See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  688. ;    of DOCUMENT
  689.  
  690. ; @ref             a reference that does not put `See' or `see' in
  691. ;                  the hardcopy and is the same as @xref in Info
  692. (put 'ref 'texinfo-format 'texinfo-format-xref)
  693.  
  694. (put 'xref 'texinfo-format 'texinfo-format-xref)
  695. (defun texinfo-format-xref ()
  696.   (let ((args (texinfo-format-parse-args)))
  697.     (texinfo-discard-command)
  698.     (insert "*Note ")
  699.     (let ((fname (or (nth 1 args) (nth 2 args))))
  700.       (if (null (or fname (nth 3 args)))
  701.       (insert (car args) "::")
  702.     (insert (or fname (car args)) ": ")
  703.     (if (nth 3 args)
  704.         (insert "(" (nth 3 args) ")"))
  705.     (insert (car args))))))
  706.  
  707. (put 'pxref 'texinfo-format 'texinfo-format-pxref)
  708. (defun texinfo-format-pxref ()
  709.   (texinfo-format-xref)
  710.   (or (save-excursion
  711.     (forward-char -2)
  712.     (looking-at "::"))
  713.       (insert ".")))
  714.  
  715. ;@inforef{NODE, FNAME, FILE}
  716. ;Like @xref{NODE, FNAME,,FILE} in texinfo.
  717. ;In Tex, generates "See Info file FILE, node NODE"
  718. (put 'inforef 'texinfo-format 'texinfo-format-inforef)
  719. (defun texinfo-format-inforef ()
  720.   (let ((args (texinfo-format-parse-args)))
  721.     (texinfo-discard-command)
  722.     (if (nth 1 args)
  723.         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
  724.       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
  725.  
  726.  
  727. ;;; Section headings
  728.  
  729. (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
  730. (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
  731. (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
  732. (put 'chapter 'texinfo-format 'texinfo-format-chapter)
  733. (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
  734. (put 'appendix 'texinfo-format 'texinfo-format-chapter)
  735. (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
  736. (put 'top 'texinfo-format 'texinfo-format-chapter)
  737. (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
  738. (defun texinfo-format-chapter ()
  739.   (texinfo-format-chapter-1 ?*))
  740.  
  741. (put 'heading 'texinfo-format 'texinfo-format-section)
  742. (put 'isection 'texinfo-format 'texinfo-format-section)
  743. (put 'section 'texinfo-format 'texinfo-format-section)
  744. (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
  745. (put 'appendixsection 'texinfo-format 'texinfo-format-section)
  746. (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
  747. (put 'appendixsec 'texinfo-format 'texinfo-format-section)
  748. (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
  749. (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
  750. (defun texinfo-format-section ()
  751.   (texinfo-format-chapter-1 ?=))
  752.  
  753. (put 'subheading 'texinfo-format 'texinfo-format-subsection)
  754. (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
  755. (put 'subsection 'texinfo-format 'texinfo-format-subsection)
  756. (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
  757. (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
  758. (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  759. (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  760. (defun texinfo-format-subsection ()
  761.   (texinfo-format-chapter-1 ?-))
  762.  
  763. (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
  764. (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
  765. (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
  766. (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  767. (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  768. (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  769. (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  770. (defun texinfo-format-subsubsection ()
  771.   (texinfo-format-chapter-1 ?.))
  772.  
  773. (defun texinfo-format-chapter-1 (belowchar)
  774.   (let ((arg (texinfo-parse-arg-discard)))
  775.     (message "Formatting: %s ... " arg)   ; So we can see where we are.
  776.     (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
  777.     (forward-line -2)))
  778.  
  779. (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
  780. (defun texinfo-format-sectionpad ()
  781.   (let ((str (texinfo-parse-arg-discard)))
  782.     (forward-char -1)
  783.     (let ((column (current-column)))
  784.       (forward-char 1)
  785.       (while (> column 0)
  786.     (insert str)
  787.     (setq column (1- column))))
  788.     (insert ?\n)))
  789.  
  790.  
  791. ;;; Space controling commands:  @. and @:   
  792. (put '\. 'texinfo-format 'texinfo-format-\.)
  793. (defun texinfo-format-\. ()
  794.   (texinfo-discard-command)
  795.   (insert "."))
  796.  
  797. (put '\: 'texinfo-format 'texinfo-format-\:)
  798. (defun texinfo-format-\: ()
  799.   (texinfo-discard-command))
  800.  
  801.  
  802. ;;; @center, @sp, and @br
  803.  
  804. (put 'center 'texinfo-format 'texinfo-format-center)
  805. (defun texinfo-format-center ()
  806.   (let ((arg (texinfo-parse-expanded-arg)))
  807.     (texinfo-discard-command)
  808.     (insert arg)
  809.     (insert ?\n)
  810.     (save-restriction
  811.       (goto-char (1- (point)))
  812.       (let ((indent-tabs-mode nil))
  813.     (center-line)))))
  814.  
  815. (put 'sp 'texinfo-format 'texinfo-format-sp)
  816. (defun texinfo-format-sp ()
  817.   (let* ((arg (texinfo-parse-arg-discard))
  818.      (num (read arg)))
  819.     (insert-char ?\n num)))
  820.  
  821. (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
  822. (defun texinfo-format-paragraph-break ()
  823.   "Force a paragraph break.
  824. If used within a line, follow `@br' with braces."
  825.   (texinfo-optional-braces-discard)
  826.   ;; insert one return if at end of line;
  827.   ;; else insert two returns, to generate a blank line.
  828.   (if (= (following-char) ?\n)
  829.       (insert ?\n)
  830.     (insert-char ?\n 2)))
  831.  
  832.  
  833. ;;; @footnote  and  @footnotestyle
  834.  
  835. ; In Texinfo, footnotes are created with the `@footnote' command.
  836. ; This command is followed immediately by a left brace, then by the text of
  837. ; the footnote, and then by a terminating right brace.  The
  838. ; template for a footnote is:
  839. ;      @footnote{TEXT}
  840. ;
  841. ; Info has two footnote styles:
  842. ;    * In the End of node style, all the footnotes for a single node
  843. ;      are placed at the end of that node.  The footnotes are
  844. ;      separated from the rest of the node by a line of dashes with
  845. ;      the word `Footnotes' within it.
  846. ;    * In the Separate node style, all the footnotes for a single node
  847. ;      are placed in an automatically constructed node of their own.
  848.  
  849. ; Footnote style is specified by the @footnotestyle command, either
  850. ;    @footnotestyle separate
  851. ; or
  852. ;    @footnotestyle end
  853. ; The default is  separate
  854.  
  855. (defvar texinfo-footnote-style "separate" 
  856.   "Footnote style, either separate or end.")
  857.  
  858. (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
  859. (defun texinfo-footnotestyle ()
  860.   "Specify whether footnotes are at end of node or in separate nodes.
  861. Argument is either end or separate."
  862.   (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
  863.  
  864. (defvar texinfo-footnote-number)
  865.  
  866. (put 'footnote 'texinfo-format 'texinfo-format-footnote)
  867. (defun texinfo-format-footnote ()
  868.   "Format a footnote in either end of node or separate node style.
  869. The   texinfo-footnote-style  variable controls which style is used."
  870.   (setq texinfo-footnote-number (1+ texinfo-footnote-number))
  871.   (cond ((string= texinfo-footnote-style "end")
  872.          (texinfo-format-end-node))
  873.         ((string= texinfo-footnote-style "separate")
  874.          (texinfo-format-separate-node))))
  875.  
  876. (defun texinfo-format-separate-node ()
  877.   "Format footnote in Separate node style, with notes in own node.
  878. The node is constructed automatically."
  879.   (let* (start
  880.          (arg (texinfo-parse-line-arg))
  881.          (node-name-beginning
  882.           (save-excursion
  883.             (re-search-backward
  884.              "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
  885.             (match-end 0)))
  886.          (node-name
  887.           (save-excursion
  888.             (buffer-substring
  889.              (progn (goto-char node-name-beginning) ; skip over node command
  890.                     (skip-chars-forward " \t")  ; and over spaces
  891.                     (point))
  892.              (if (search-forward
  893.                   ","
  894.                   (save-excursion (end-of-line) (point)) t) ; bound search
  895.                  (1- (point))
  896.                (end-of-line) (point))))))
  897.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  898.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  899.                    (point))
  900.     (insert (format " (%d) (*Note %s-Footnotes::)"
  901.             texinfo-footnote-number node-name))
  902.     (fill-paragraph nil)
  903.     (save-excursion
  904.     (if (re-search-forward "^@node" nil 'move)
  905.         (forward-line -1))
  906.  
  907.     ;; two cases: for the first footnote, we must insert a node header;
  908.     ;; for the second and subsequent footnotes, we need only insert 
  909.     ;; the text of the  footnote.
  910.  
  911.     (if (save-excursion
  912.          (re-search-backward
  913.           (concat node-name "-Footnotes, Up: ")
  914.           node-name-beginning
  915.           t))
  916.         (progn   ; already at least one footnote
  917.           (setq start (point))
  918.           (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  919.           (fill-region start (point)))
  920.       ;; else not yet a footnote
  921.       (insert "\n\^_\nFile: "  texinfo-format-filename
  922.               "  Node: " node-name "-Footnotes, Up: " node-name "\n")
  923.       (setq start (point))
  924.       (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  925.       (fill-region start (point))))))
  926.  
  927. (defun texinfo-format-end-node ()
  928.   "Format footnote in the End of node style, with notes at end of node."
  929.   (let (start
  930.         (arg (texinfo-parse-line-arg)))
  931.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  932.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  933.                    (point))
  934.     (insert (format " (%d) " texinfo-footnote-number))
  935.     (fill-paragraph nil)
  936.     (save-excursion
  937.       (if (search-forward "\n--------- Footnotes ---------\n" nil t)
  938.           (progn ; already have footnote, put new one before end of node
  939.             (if (re-search-forward "^@node" nil 'move)
  940.                 (forward-line -1))
  941.             (setq start (point))
  942.             (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  943.             (fill-region start (point)))
  944.         ;; else no prior footnote
  945.         (if (re-search-forward "^@node" nil 'move)
  946.             (forward-line -1))
  947.         (insert "\n--------- Footnotes ---------\n")
  948.         (setq start (point))
  949.         (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))))))
  950.  
  951.  
  952. ;;; @itemize, @enumerate, and similar commands
  953.  
  954. ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
  955. ;; @enumerate pushes (enumerate 0 STARTPOS).
  956. ;; @item dispatches to the texinfo-item prop of the first elt of the list.
  957. ;; For itemize, this puts in and rescans the COMMANDS.
  958. ;; For enumerate, this increments the number and puts it in.
  959. ;; In either case, it puts a Backspace at the front of the line
  960. ;; which marks it not to be indented later.
  961. ;; All other lines get indented by 5 when the @end is reached.
  962.  
  963. (defvar texinfo-stack-depth 0
  964.   "Count of number of unpopped texinfo-push-stack calls.
  965. Used by @refill indenting command to avoid indenting within lists, etc.")
  966.  
  967. (defun texinfo-push-stack (check arg)
  968.   (setq texinfo-stack-depth (1+ texinfo-stack-depth))
  969.   (setq texinfo-stack
  970.     (cons (list check arg texinfo-command-start)
  971.           texinfo-stack)))
  972.  
  973. (defun texinfo-pop-stack (check)
  974.   (setq texinfo-stack-depth (1- texinfo-stack-depth))
  975.   (if (null texinfo-stack)
  976.       (error "Unmatched @end %s" check))
  977.   (if (not (eq (car (car texinfo-stack)) check))
  978.       (error "@end %s matches @%s"
  979.          check (car (car texinfo-stack))))
  980.   (prog1 (cdr (car texinfo-stack))
  981.      (setq texinfo-stack (cdr texinfo-stack))))
  982.  
  983. (put 'itemize 'texinfo-format 'texinfo-itemize)
  984. (defun texinfo-itemize ()
  985.   (texinfo-push-stack
  986.    'itemize
  987.    (progn (skip-chars-forward " \t")
  988.           (if (eolp)
  989.               "@bullet"
  990.             (texinfo-parse-line-arg))))
  991.   (texinfo-discard-line-with-args)
  992.   (setq fill-column (- fill-column 5)))
  993.  
  994. (put 'itemize 'texinfo-end 'texinfo-end-itemize)
  995. (defun texinfo-end-itemize ()
  996.   (setq fill-column (+ fill-column 5))
  997.   (texinfo-discard-command)
  998.   (let ((stacktop
  999.      (texinfo-pop-stack 'itemize)))
  1000.     (texinfo-do-itemize (nth 1 stacktop))))
  1001.  
  1002. (put 'enumerate 'texinfo-format 'texinfo-enumerate)
  1003. (defun texinfo-enumerate ()
  1004.   (texinfo-push-stack
  1005.    'enumerate 
  1006.    (progn (skip-chars-forward " \t")
  1007.           (if (eolp)
  1008.               1
  1009.             (read (current-buffer)))))
  1010.   (if (and (symbolp (car (cdr (car texinfo-stack))))
  1011.            (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
  1012.       (error
  1013.        "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
  1014.   (texinfo-discard-line-with-args)
  1015.   (setq fill-column (- fill-column 5)))
  1016.  
  1017. (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
  1018. (defun texinfo-end-enumerate ()
  1019.   (setq fill-column (+ fill-column 5))
  1020.   (texinfo-discard-command)
  1021.   (let ((stacktop
  1022.      (texinfo-pop-stack 'enumerate)))
  1023.     (texinfo-do-itemize (nth 1 stacktop))))
  1024.  
  1025. ;; @alphaenumerate never became a standard part of Texinfo
  1026. (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
  1027. (defun texinfo-alphaenumerate ()
  1028.   (texinfo-push-stack 'alphaenumerate (1- ?a))
  1029.   (setq fill-column (- fill-column 5))
  1030.   (texinfo-discard-line))
  1031.  
  1032. (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
  1033. (defun texinfo-end-alphaenumerate ()
  1034.   (setq fill-column (+ fill-column 5))
  1035.   (texinfo-discard-command)
  1036.   (let ((stacktop
  1037.      (texinfo-pop-stack 'alphaenumerate)))
  1038.     (texinfo-do-itemize (nth 1 stacktop))))
  1039.  
  1040. ;; @capsenumerate never became a standard part of Texinfo
  1041. (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
  1042. (defun texinfo-capsenumerate ()
  1043.   (texinfo-push-stack 'capsenumerate (1- ?A))
  1044.   (setq fill-column (- fill-column 5))
  1045.   (texinfo-discard-line))
  1046.  
  1047. (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
  1048. (defun texinfo-end-capsenumerate ()
  1049.   (setq fill-column (+ fill-column 5))
  1050.   (texinfo-discard-command)
  1051.   (let ((stacktop
  1052.      (texinfo-pop-stack 'capsenumerate)))
  1053.     (texinfo-do-itemize (nth 1 stacktop))))
  1054.  
  1055. ;; At the @end, indent all the lines within the construct
  1056. ;; except those marked with backspace.  FROM says where
  1057. ;; construct started.
  1058. (defun texinfo-do-itemize (from)
  1059.   (save-excursion
  1060.    (while (progn (forward-line -1)
  1061.          (>= (point) from))
  1062.      (if (= (following-char) ?\b)
  1063.      (save-excursion
  1064.        (delete-char 1)
  1065.        (end-of-line)
  1066.        (delete-char 6))
  1067.        (if (not (looking-at "[ \t]*$"))
  1068.        (save-excursion (insert "     ")))))))
  1069.  
  1070. (put 'item 'texinfo-format 'texinfo-item)
  1071. (put 'itemx 'texinfo-format 'texinfo-item)
  1072. (defun texinfo-item ()
  1073.   (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
  1074.  
  1075. (put 'itemize 'texinfo-item 'texinfo-itemize-item)
  1076. (defun texinfo-itemize-item ()
  1077.   ;; (texinfo-discard-line)   ; Did not handle text on same line as @item.
  1078.   (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
  1079.   (if (looking-at "[ \t]*[^ \t\n]+")
  1080.       ;; Text on same line as @item command.
  1081.       (insert "\b   " (nth 1 (car texinfo-stack)) " \n")
  1082.     ;; Else text on next line.
  1083.     (insert "\b   " (nth 1 (car texinfo-stack)) " "))
  1084.   (forward-line -1))
  1085.  
  1086. (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
  1087. (defun texinfo-enumerate-item ()
  1088.   (texinfo-discard-line)
  1089.   (let (enumerating-symbol)
  1090.     (cond ((integerp (car (cdr (car texinfo-stack))))
  1091.            (setq enumerating-symbol (car (cdr (car texinfo-stack))))
  1092.            (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
  1093.            (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
  1094.           ((symbolp (car (cdr (car texinfo-stack))))
  1095.            (setq enumerating-symbol
  1096.                  (symbol-name (car (cdr (car texinfo-stack)))))
  1097.            (if (or (equal ?\[ (string-to-char enumerating-symbol))
  1098.                    (equal ?\{ (string-to-char enumerating-symbol)))
  1099.                (error
  1100.                 "Too many items in enumerated list; alphabet ends at Z."))
  1101.            (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
  1102.            (setcar (cdr (car texinfo-stack))
  1103.                    (make-symbol
  1104.                     (char-to-string
  1105.                      (1+ 
  1106.                       (string-to-char enumerating-symbol))))))
  1107.           (t
  1108.           (error
  1109.            "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
  1110.     (forward-line -1)))
  1111.  
  1112. (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
  1113. (defun texinfo-alphaenumerate-item ()
  1114.   (texinfo-discard-line)
  1115.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1116.     (if (> next ?z)
  1117.     (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
  1118.     (setcar (cdr (car texinfo-stack)) next)
  1119.     (insert "\b  " next ". \n"))
  1120.   (forward-line -1))
  1121.  
  1122. (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
  1123. (defun texinfo-capsenumerate-item ()
  1124.   (texinfo-discard-line)
  1125.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1126.     (if (> next ?Z)
  1127.     (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
  1128.     (setcar (cdr (car texinfo-stack)) next)
  1129.     (insert "\b  " next ". \n"))
  1130.   (forward-line -1))
  1131.  
  1132.  
  1133. ;;; @table
  1134.  
  1135. ; The `@table' command produces two-column tables.
  1136.  
  1137. (put 'table 'texinfo-format 'texinfo-table)
  1138. (defun texinfo-table ()
  1139.   (texinfo-push-stack 
  1140.    'table 
  1141.    (progn (skip-chars-forward " \t")
  1142.           (if (eolp)
  1143.               "@asis"
  1144.             (texinfo-parse-line-arg))))
  1145.   (texinfo-discard-line-with-args)
  1146.   (setq fill-column (- fill-column 5)))
  1147.  
  1148. (put 'table 'texinfo-item 'texinfo-table-item)
  1149. (defun texinfo-table-item ()
  1150.   (let ((arg (texinfo-parse-arg-discard))
  1151.     (itemfont (car (cdr (car texinfo-stack)))))
  1152.     (insert ?\b itemfont ?\{ arg "}\n     \n"))
  1153.   (forward-line -2))
  1154.  
  1155. (put 'table 'texinfo-end 'texinfo-end-table)
  1156. (defun texinfo-end-table ()
  1157.   (setq fill-column (+ fill-column 5))
  1158.   (texinfo-discard-command)
  1159.   (let ((stacktop
  1160.      (texinfo-pop-stack 'table)))
  1161.     (texinfo-do-itemize (nth 1 stacktop))))
  1162.  
  1163. ;; @description appears to be an undocumented variant on @table that
  1164. ;; does not require an arg.  It fails in texinfo.tex 2.58 and is not
  1165. ;; part of makeinfo.c   The command appears to be a relic of the past.
  1166. (put 'description 'texinfo-end 'texinfo-end-table)
  1167. (put 'description 'texinfo-format 'texinfo-description)
  1168. (defun texinfo-description ()
  1169.   (texinfo-push-stack 'table "@asis")
  1170.   (setq fill-column (- fill-column 5))
  1171.   (texinfo-discard-line))
  1172.  
  1173.  
  1174. ;;; @ftable, @vtable
  1175.  
  1176. ; The `@ftable' and `@vtable' commands are like the `@table' command
  1177. ; but they also insert each entry in the first column of the table
  1178. ; into the function or variable index.
  1179.  
  1180. ;; Handle the @ftable and @vtable commands:
  1181.  
  1182. (put 'ftable 'texinfo-format 'texinfo-ftable)
  1183. (put 'vtable 'texinfo-format 'texinfo-vtable)
  1184.  
  1185. (defun texinfo-ftable () (texinfo-indextable 'ftable))
  1186. (defun texinfo-vtable () (texinfo-indextable 'vtable))
  1187.  
  1188. (defun texinfo-indextable (table-type)
  1189.   (texinfo-push-stack table-type (texinfo-parse-arg-discard))
  1190.   (setq fill-column (- fill-column 5)))
  1191.  
  1192. ;; Handle the @item commands within ftable and vtable:
  1193.  
  1194. (put 'ftable 'texinfo-item 'texinfo-ftable-item)
  1195. (put 'vtable 'texinfo-item 'texinfo-vtable-item)
  1196.  
  1197. (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
  1198. (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
  1199.  
  1200. (defun texinfo-indextable-item (index-type)
  1201.   (let ((item (texinfo-parse-arg-discard))
  1202.         (itemfont (car (cdr (car texinfo-stack))))
  1203.         (indexvar index-type))
  1204.     (insert ?\b itemfont ?\{ item "}\n     \n")
  1205.     (set indexvar
  1206.          (cons
  1207.           (list item texinfo-last-node)
  1208.           (symbol-value indexvar)))
  1209.     (forward-line -2)))
  1210.  
  1211. ;; Handle @end ftable, @end vtable
  1212.  
  1213. (put 'ftable 'texinfo-end 'texinfo-end-ftable)
  1214. (put 'vtable 'texinfo-end 'texinfo-end-vtable)
  1215.  
  1216. (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
  1217. (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
  1218.  
  1219. (defun texinfo-end-indextable (table-type)
  1220.   (setq fill-column (+ fill-column 5))
  1221.   (texinfo-discard-command)
  1222.   (let ((stacktop
  1223.          (texinfo-pop-stack table-type)))
  1224.     (texinfo-do-itemize (nth 1 stacktop))))
  1225.  
  1226.  
  1227. ;;; @ifinfo,  @iftex, @tex
  1228.  
  1229. (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
  1230. (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
  1231.  
  1232. (put 'iftex 'texinfo-format 'texinfo-format-iftex)
  1233. (defun texinfo-format-iftex ()
  1234.   (delete-region texinfo-command-start
  1235.          (progn (re-search-forward "@end iftex\n")
  1236.             (point))))
  1237.  
  1238. (put 'tex 'texinfo-format 'texinfo-format-tex)
  1239. (defun texinfo-format-tex ()
  1240.   (delete-region texinfo-command-start
  1241.          (progn (re-search-forward "@end tex\n")
  1242.             (point))))
  1243.  
  1244.  
  1245. ;;; @titlepage
  1246.  
  1247. (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
  1248. (defun texinfo-format-titlepage ()
  1249.   (delete-region texinfo-command-start
  1250.          (progn (search-forward "@end titlepage\n")
  1251.             (point))))
  1252.  
  1253. (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
  1254.  
  1255. ; @titlespec         an alternative titling command; ignored by Info
  1256.  
  1257. (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
  1258. (defun texinfo-format-titlespec ()
  1259.   (delete-region texinfo-command-start
  1260.                  (progn (search-forward "@end titlespec\n")
  1261.                         (point))))
  1262.  
  1263. (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
  1264.  
  1265.  
  1266. ;;; @today
  1267.  
  1268. (put 'today 'texinfo-format 'texinfo-format-today)
  1269.  
  1270. ; Produces Day Month Year style of output.  eg `1 Jan 1900'
  1271. ; The `@today{}' command requires a pair of braces, like `@dots{}'.
  1272. (defun texinfo-format-today ()
  1273.   (texinfo-parse-arg-discard)
  1274.   (insert (format "%s %s %s"
  1275.           (substring (current-time-string) 8 10)
  1276.           (substring (current-time-string) 4 7)
  1277.           (substring (current-time-string) -4))))
  1278.  
  1279.  
  1280. ;;; @ignore
  1281.  
  1282. (put 'ignore 'texinfo-format 'texinfo-format-ignore)
  1283. (defun texinfo-format-ignore ()
  1284.   (delete-region texinfo-command-start
  1285.          (progn (search-forward "@end ignore\n")
  1286.             (point))))
  1287.  
  1288. (put 'endignore 'texinfo-format 'texinfo-discard-line)
  1289.  
  1290.  
  1291. ;;; Define the Info enclosure command: @definfoenclose
  1292.  
  1293. ; A `@definfoenclose' command may be used to define a highlighting
  1294. ; command for Info, but not for TeX.  A command defined using
  1295. ; `@definfoenclose' marks text by enclosing it in strings that precede
  1296. ; and follow the text.
  1297. ; Presumably, if you define a command with `@definfoenclose` for Info,
  1298. ; you will also define the same command in the TeX definitions file,
  1299. ; `texinfo.tex' in a manner appropriate for typesetting.
  1300. ; Write a `@definfoenclose' command on a line and follow it with three
  1301. ; arguments separated by commas (commas are used as separators in an
  1302. ; `@node' line in the same way).  The first argument to
  1303. ; `@definfoenclose' is the @-command name \(without the `@'\); the
  1304. ; second argument is the Info start delimiter string; and the third
  1305. ; argument is the Info end delimiter string.  The latter two arguments
  1306. ; enclose the highlighted text in the Info file.  A delimiter string
  1307. ; may contain spaces.  Neither the start nor end delimiter is
  1308. ; required.  However, if you do not provide a start delimiter, you
  1309. ; must follow the command name with two commas in a row; otherwise,
  1310. ; the Info formatting commands will misinterpret the end delimiter
  1311. ; string as a start delimiter string.
  1312. ; An enclosure command defined this way takes one argument in braces.
  1313. ;
  1314. ; For example, you can write:
  1315. ;
  1316. ;     @definfoenclose phonetic, //, \\
  1317. ;
  1318. ; near the beginning of a Texinfo file to define `@phonetic' as an
  1319. ; Info formatting command that inserts `//' before and `\\' after the
  1320. ; argument to '@phonetic'.  You can then write `@phonetic{bar}'
  1321. ; wherever you want `//bar\\' highlighted in Info.
  1322. ;
  1323. ; Similarly, you can write:
  1324. ;
  1325. ;     @definfoenclose headword, , :
  1326. ;
  1327. ; near the beginning of the file, to define `@headword' as an Info
  1328. ; formatting command that inserts nothing before and a colon after the
  1329. ; argument to `@headword'.  You can then write `@headword{foo}'
  1330. ; wherever you want `foo:' highlighted in Info.
  1331.  
  1332. (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
  1333. (defun texinfo-define-info-enclosure ()
  1334.   (let* ((args (texinfo-format-parse-line-args))
  1335.      (command-name (nth 0 args))
  1336.      (beginning-delimiter (or (nth 1 args) ""))
  1337.      (end-delimiter (or (nth 2 args) "")))
  1338.     (texinfo-discard-command)
  1339.     (setq texinfo-enclosure-list
  1340.     (cons
  1341.      (list command-name
  1342.            (list
  1343.         beginning-delimiter
  1344.         end-delimiter))
  1345.      texinfo-enclosure-list))))
  1346.  
  1347.  
  1348. ;;; @var, @code and the like
  1349.  
  1350. (put 'var 'texinfo-format 'texinfo-format-var)
  1351. ;  @sc  a small caps font for TeX; formatted as `var' in Info
  1352. (put 'sc 'texinfo-format 'texinfo-format-var)
  1353. (defun texinfo-format-var ()
  1354.   (insert (upcase (texinfo-parse-arg-discard)))
  1355.   (goto-char texinfo-command-start))
  1356.  
  1357. ; various noops
  1358.  
  1359. (put 'b 'texinfo-format 'texinfo-format-noop)
  1360. (put 'i 'texinfo-format 'texinfo-format-noop)
  1361. (put 'r 'texinfo-format 'texinfo-format-noop)
  1362. (put 't 'texinfo-format 'texinfo-format-noop)
  1363. (put 'w 'texinfo-format 'texinfo-format-noop)
  1364. (put 'asis 'texinfo-format 'texinfo-format-noop)
  1365. (put 'dmn 'texinfo-format 'texinfo-format-noop)
  1366. (put 'key 'texinfo-format 'texinfo-format-noop)
  1367. (put 'math 'texinfo-format 'texinfo-format-noop)
  1368. (put 'titlefont 'texinfo-format 'texinfo-format-noop)
  1369. (defun texinfo-format-noop ()
  1370.   (insert (texinfo-parse-arg-discard))
  1371.   (goto-char texinfo-command-start))
  1372.  
  1373. (put 'cite 'texinfo-format 'texinfo-format-code)
  1374. (put 'code 'texinfo-format 'texinfo-format-code)
  1375. (put 'file 'texinfo-format 'texinfo-format-code)
  1376. (put 'kbd 'texinfo-format 'texinfo-format-code)
  1377. (put 'samp 'texinfo-format 'texinfo-format-code)
  1378. (defun texinfo-format-code ()
  1379.   (insert "`" (texinfo-parse-arg-discard) "'")
  1380.   (goto-char texinfo-command-start))
  1381.  
  1382. (put 'emph 'texinfo-format 'texinfo-format-emph)
  1383. (put 'strong 'texinfo-format 'texinfo-format-emph)
  1384. (defun texinfo-format-emph ()
  1385.   (insert "*" (texinfo-parse-arg-discard) "*")
  1386.   (goto-char texinfo-command-start))
  1387.  
  1388. (put 'dfn 'texinfo-format 'texinfo-format-defn)
  1389. (put 'defn 'texinfo-format 'texinfo-format-defn)
  1390. (defun texinfo-format-defn ()
  1391.   (insert "\"" (texinfo-parse-arg-discard) "\"")
  1392.   (goto-char texinfo-command-start))
  1393.  
  1394. (put 'bullet 'texinfo-format 'texinfo-format-bullet)
  1395. (defun texinfo-format-bullet ()
  1396.   "Insert an asterisk.
  1397. If used within a line, follow `@bullet' with braces."
  1398.   (texinfo-optional-braces-discard)
  1399.   (insert "*"))
  1400.  
  1401.  
  1402. ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
  1403.  
  1404. (put 'display 'texinfo-format 'texinfo-format-example)
  1405. (put 'example 'texinfo-format 'texinfo-format-example)
  1406. (put 'lisp 'texinfo-format 'texinfo-format-example)
  1407. (put 'quotation 'texinfo-format 'texinfo-format-example)
  1408. (put 'smallexample 'texinfo-format 'texinfo-format-example)
  1409. (put 'smalllisp 'texinfo-format 'texinfo-format-example)
  1410. (defun texinfo-format-example ()
  1411.   (texinfo-push-stack 'example nil)
  1412.   (setq fill-column (- fill-column 5))
  1413.   (texinfo-discard-line))
  1414.  
  1415. (put 'example 'texinfo-end 'texinfo-end-example)
  1416. (put 'display 'texinfo-end 'texinfo-end-example)
  1417. (put 'lisp 'texinfo-end 'texinfo-end-example)
  1418. (put 'quotation 'texinfo-end 'texinfo-end-example)
  1419. (put 'smallexample 'texinfo-end 'texinfo-end-example)
  1420. (put 'smalllisp 'texinfo-end 'texinfo-end-example)
  1421. (defun texinfo-end-example ()
  1422.   (setq fill-column (+ fill-column 5))
  1423.   (texinfo-discard-command)
  1424.   (let ((stacktop
  1425.      (texinfo-pop-stack 'example)))
  1426.     (texinfo-do-itemize (nth 1 stacktop))))
  1427.  
  1428. (put 'exdent 'texinfo-format 'texinfo-format-exdent)
  1429. (defun texinfo-format-exdent ()
  1430.   (texinfo-discard-command)
  1431.   (delete-region (point)
  1432.          (progn
  1433.           (skip-chars-forward " ")
  1434.           (point)))
  1435.   (insert ?\b)
  1436.   ;; Cancel out the deletion that texinfo-do-itemize
  1437.   ;; is going to do at the end of this line.
  1438.   (save-excursion
  1439.     (end-of-line)
  1440.     (insert "\n     ")))
  1441.  
  1442.  
  1443. ;;; @cartouche 
  1444.  
  1445. ; The @cartouche command is a noop in Info; in a printed manual,
  1446. ; it makes a box with rounded corners.
  1447.  
  1448. (put 'cartouche 'texinfo-format 'texinfo-discard-line)
  1449. (put 'cartouche 'texinfo-end 'texinfo-discard-command)
  1450.  
  1451.  
  1452. ;;; @flushleft and @format
  1453.  
  1454. ; The @flushleft command left justifies every line but leaves the
  1455. ; right end ragged.  As far as Info is concerned, @flushleft is a
  1456. ; `do-nothing' command
  1457.  
  1458. ; The @format command is similar to @example except that it does not
  1459. ; indent; this means that in Info, @format is similar to @flushleft.
  1460.  
  1461. (put 'format 'texinfo-format 'texinfo-format-flushleft)
  1462. (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
  1463. (defun texinfo-format-flushleft ()
  1464.   (texinfo-discard-line))
  1465.  
  1466. (put 'format 'texinfo-end 'texinfo-end-flushleft)
  1467. (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
  1468. (defun texinfo-end-flushleft ()
  1469.   (texinfo-discard-command))
  1470.  
  1471.  
  1472. ;;; @flushright
  1473.  
  1474. ; The @flushright command right justifies every line but leaves the
  1475. ; left end ragged.  Spaces and tabs at the right ends of lines are
  1476. ; removed so that visible text lines up on the right side.
  1477.  
  1478. (put 'flushright 'texinfo-format 'texinfo-format-flushright)
  1479. (defun texinfo-format-flushright ()
  1480.   (texinfo-push-stack 'flushright nil)
  1481.   (texinfo-discard-line))
  1482.  
  1483. (put 'flushright 'texinfo-end 'texinfo-end-flushright)
  1484. (defun texinfo-end-flushright ()
  1485.   (texinfo-discard-command)
  1486.  
  1487.   (let ((stacktop
  1488.          (texinfo-pop-stack 'flushright)))
  1489.  
  1490.     (texinfo-do-flushright (nth 1 stacktop))))
  1491.  
  1492. (defun texinfo-do-flushright (from)
  1493.   (save-excursion
  1494.    (while (progn (forward-line -1)
  1495.                  (>= (point) from))
  1496.  
  1497.      (beginning-of-line)
  1498.      (insert
  1499.       (make-string
  1500.        (- fill-column
  1501.           (save-excursion
  1502.             (end-of-line) 
  1503.             (skip-chars-backward " \t")
  1504.             (delete-region (point) (progn (end-of-line) (point)))
  1505.             (current-column)))  
  1506.        ? )))))
  1507.  
  1508.  
  1509. ;;; @ctrl, @TeX, @copyright, @minus, @dots
  1510.  
  1511. (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
  1512. (defun texinfo-format-ctrl ()
  1513.   (let ((str (texinfo-parse-arg-discard)))
  1514.     (insert (logand 31 (aref str 0)))))
  1515.  
  1516. (put 'TeX 'texinfo-format 'texinfo-format-TeX)
  1517. (defun texinfo-format-TeX ()
  1518.   (texinfo-parse-arg-discard)
  1519.   (insert "TeX"))
  1520.  
  1521. (put 'copyright 'texinfo-format 'texinfo-format-copyright)
  1522. (defun texinfo-format-copyright ()
  1523.   (texinfo-parse-arg-discard)
  1524.   (insert "(C)"))
  1525.  
  1526. (put 'minus 'texinfo-format 'texinfo-format-minus)
  1527. (defun texinfo-format-minus ()
  1528.   "Insert a minus sign.
  1529. If used within a line, follow `@minus' with braces."
  1530.   (texinfo-optional-braces-discard)
  1531.   (insert "-"))
  1532.  
  1533. (put 'dots 'texinfo-format 'texinfo-format-dots)
  1534. (defun texinfo-format-dots ()
  1535.   (texinfo-parse-arg-discard)
  1536.   (insert "..."))
  1537.  
  1538.  
  1539. ;;; Refilling and indenting:  @refill, @paragraphindent, @noindent
  1540.  
  1541. ;;; Indent only those paragraphs that are refilled as a result of an
  1542. ;;; @refill command.  
  1543.  
  1544. ;    * If the value is `asis', do not change the existing indentation at
  1545. ;      the starts of paragraphs.
  1546.  
  1547. ;    * If the value zero, delete any existing indentation.
  1548.  
  1549. ;    * If the value is greater than zero, indent each paragraph by that
  1550. ;      number of spaces.
  1551.  
  1552. ;;; But do not refill paragraphs with an @refill command that are
  1553. ;;; preceded by @noindent or are part of a table, list, or deffn.
  1554.  
  1555. (defvar texinfo-paragraph-indent "asis"
  1556.   "Number of spaces for @refill to indent a paragraph; else to leave as is.")
  1557.  
  1558. (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
  1559.  
  1560. (defun texinfo-paragraphindent ()
  1561.   "Specify the number of spaces for @refill to indent a paragraph.
  1562. Default is to leave the number of spaces as is."
  1563.   (let ((arg  (texinfo-parse-arg-discard)))
  1564.     (if (string= "asis" arg)
  1565.         (setq texinfo-paragraph-indent "asis")
  1566.       (setq texinfo-paragraph-indent (string-to-int arg)))))
  1567.  
  1568. (put 'refill 'texinfo-format 'texinfo-format-refill)
  1569. (defun texinfo-format-refill ()
  1570.   "Refill paragraph. Also, indent first line as set by @paragraphindent.
  1571. Default is to leave paragraph indentation as is."
  1572.   (texinfo-discard-command)
  1573.   (forward-paragraph -1)     
  1574.   (if (looking-at "[ \t\n]*$") (forward-line 1))
  1575.   ;; Do not indent if an entry in a list, table, or deffn,
  1576.   ;; or if paragraph is preceded by @noindent.
  1577.   ;; Otherwise, indent
  1578.   (cond 
  1579.    ;; delete a @noindent line and do not indent paragraph
  1580.    ((save-excursion (forward-line -1)
  1581.                     (looking-at "^@noindent")) 
  1582.     (forward-line -1)
  1583.     (delete-region (point) (progn (forward-line 1) (point))))
  1584.    ;; do nothing if "asis"
  1585.    ((equal texinfo-paragraph-indent "asis"))
  1586.    ;; do no indenting in list, etc.
  1587.    ((> texinfo-stack-depth 0))   
  1588.    ;; otherwise delete existing whitespace and indent
  1589.    (t 
  1590.     (delete-region (point) (progn (skip-chars-forward " \t") (point)))
  1591.     (insert (make-string texinfo-paragraph-indent ? ))))
  1592.   (forward-paragraph 1) 
  1593.   (forward-line -1)
  1594.   (end-of-line)
  1595.   (fill-paragraph nil))
  1596.  
  1597. (put 'noindent 'texinfo-format 'texinfo-noindent)
  1598. (defun texinfo-noindent ()  
  1599.   (save-excursion 
  1600.     (forward-paragraph 1)
  1601.     (if (search-backward "@refill"
  1602.                             (save-excursion (forward-line -1) (point)) t)
  1603.         () ; leave @noindent command so @refill command knows not to indent
  1604.       ;; else
  1605.       (texinfo-discard-line))))
  1606.  
  1607.  
  1608. ;;; Index generation
  1609.  
  1610. (put 'vindex 'texinfo-format 'texinfo-format-vindex)
  1611. (defun texinfo-format-vindex ()
  1612.   (texinfo-index 'texinfo-vindex))
  1613.  
  1614. (put 'cindex 'texinfo-format 'texinfo-format-cindex)
  1615. (defun texinfo-format-cindex ()
  1616.   (texinfo-index 'texinfo-cindex))
  1617.  
  1618. (put 'findex 'texinfo-format 'texinfo-format-findex)
  1619. (defun texinfo-format-findex ()
  1620.   (texinfo-index 'texinfo-findex))
  1621.  
  1622. (put 'pindex 'texinfo-format 'texinfo-format-pindex)
  1623. (defun texinfo-format-pindex ()
  1624.   (texinfo-index 'texinfo-pindex))
  1625.  
  1626. (put 'tindex 'texinfo-format 'texinfo-format-tindex)
  1627. (defun texinfo-format-tindex ()
  1628.   (texinfo-index 'texinfo-tindex))
  1629.  
  1630. (put 'kindex 'texinfo-format 'texinfo-format-kindex)
  1631. (defun texinfo-format-kindex ()
  1632.   (texinfo-index 'texinfo-kindex))
  1633.  
  1634. (defun texinfo-index (indexvar)
  1635.   (let ((arg (texinfo-parse-expanded-arg)))
  1636.     (texinfo-discard-command)
  1637.     (set indexvar
  1638.      (cons (list arg
  1639.                      texinfo-last-node
  1640.                      ;; Region formatting may not provide last node position.
  1641.              (if texinfo-last-node-pos
  1642.                          (1+ (count-lines texinfo-last-node-pos (point)))
  1643.                        1))
  1644.            (symbol-value indexvar)))))
  1645.  
  1646. (defconst texinfo-indexvar-alist
  1647.   '(("cp" . texinfo-cindex)
  1648.     ("fn" . texinfo-findex)
  1649.     ("vr" . texinfo-vindex)
  1650.     ("tp" . texinfo-tindex)
  1651.     ("pg" . texinfo-pindex)
  1652.     ("ky" . texinfo-kindex)))
  1653.  
  1654.  
  1655. ;;; @defindex   @defcodeindex
  1656. (put 'defindex 'texinfo-format 'texinfo-format-defindex)
  1657. (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
  1658.  
  1659. (defun texinfo-format-defindex ()
  1660.   (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
  1661.          (indexing-command (intern (concat index-name "index")))
  1662.          (index-formatting-command      ; eg: `texinfo-format-aaindex'
  1663.           (intern (concat "texinfo-format-" index-name "index")))
  1664.          (index-alist-name              ; eg: `texinfo-aaindex'
  1665.           (intern (concat "texinfo-" index-name "index"))))
  1666.  
  1667.     (set index-alist-name nil)
  1668.  
  1669.     (put indexing-command               ; eg, aaindex
  1670.          'texinfo-format
  1671.          index-formatting-command)      ; eg, texinfo-format-aaindex
  1672.  
  1673.     ;; eg: "aa" . texinfo-aaindex
  1674.     (or (assoc index-name texinfo-indexvar-alist)
  1675.         (setq texinfo-indexvar-alist
  1676.               (cons
  1677.                (cons index-name
  1678.                      index-alist-name)
  1679.                texinfo-indexvar-alist)))
  1680.  
  1681.     (fset index-formatting-command
  1682.           (list 'lambda 'nil
  1683.                 (list 'texinfo-index 
  1684.                       (list 'quote index-alist-name))))))
  1685.  
  1686.  
  1687. ;;; @synindex   @syncodeindex
  1688.  
  1689. (put 'synindex 'texinfo-format 'texinfo-format-synindex)
  1690. (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
  1691.  
  1692. (defun texinfo-format-synindex ()
  1693.   (let* ((args (texinfo-parse-arg-discard))
  1694.          (second (cdr (read-from-string args)))
  1695.          (joiner (symbol-name (car (read-from-string args))))
  1696.          (joined (symbol-name (car (read-from-string args second)))))
  1697.  
  1698.     (if (assoc joiner texinfo-short-index-cmds-alist)
  1699.         (put
  1700.           (cdr (assoc joiner texinfo-short-index-cmds-alist))
  1701.          'texinfo-format
  1702.          (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
  1703.              (intern (concat "texinfo-format-" joined "index"))))
  1704.       (put
  1705.        (intern (concat joiner "index"))
  1706.        'texinfo-format
  1707.        (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
  1708.            (intern (concat "texinfo-format-" joined "index")))))))
  1709.  
  1710. (defconst texinfo-short-index-cmds-alist
  1711.   '(("cp" . cindex)
  1712.     ("fn" . findex)
  1713.     ("vr" . vindex)
  1714.     ("tp" . tindex)
  1715.     ("pg" . pindex)
  1716.     ("ky" . kindex)))
  1717.  
  1718. (defconst texinfo-short-index-format-cmds-alist
  1719.   '(("cp" . texinfo-format-cindex)
  1720.     ("fn" . texinfo-format-findex)
  1721.     ("vr" . texinfo-format-vindex)
  1722.     ("tp" . texinfo-format-tindex)
  1723.     ("pg" . texinfo-format-pindex)
  1724.     ("ky" . texinfo-format-kindex)))
  1725.  
  1726.  
  1727. ;;; Sort and index (for VMS)
  1728.  
  1729. ;; Sort an index which is in the current buffer between START and END.
  1730. ;; Used on VMS, where the `sort' utility is not available.
  1731. (defun texinfo-sort-region (start end)
  1732.   (require 'sort)
  1733.   (save-restriction
  1734.     (narrow-to-region start end)
  1735.     (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
  1736.  
  1737. ;; Subroutine for sorting an index.
  1738. ;; At start of a line, return a string to sort the line under.
  1739. (defun texinfo-sort-startkeyfun ()
  1740.   (let ((line
  1741.      (buffer-substring (point) (save-excursion (end-of-line) (point)))))
  1742.     ;; Canonicalize whitespace and eliminate funny chars.
  1743.     (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
  1744.       (setq line (concat (substring line 0 (match-beginning 0))
  1745.              " "
  1746.              (substring line (match-end 0) (length line)))))
  1747.     line))
  1748.  
  1749.  
  1750. ;;; @printindex
  1751.  
  1752. (put 'printindex 'texinfo-format 'texinfo-format-printindex)
  1753.  
  1754. (defun texinfo-format-printindex ()
  1755.   (let ((indexelts (symbol-value
  1756.             (cdr (assoc (texinfo-parse-arg-discard)
  1757.                 texinfo-indexvar-alist))))
  1758.     opoint)
  1759.     (insert "\n* Menu:\n\n")
  1760.     (setq opoint (point))
  1761.     (texinfo-print-index nil indexelts)
  1762.  
  1763.     (if (eq system-type 'vax-vms)
  1764.         (texinfo-sort-region opoint (point))
  1765.       (shell-command-on-region opoint (point) "sort -fd" 1))))
  1766.  
  1767. (defun texinfo-print-index (file indexelts)
  1768.   (while indexelts
  1769.     (if (stringp (car (car indexelts)))
  1770.         (progn
  1771.           (insert "* " (car (car indexelts)) ": " )
  1772.           (indent-to 32)
  1773.           (insert
  1774.            (if file (concat "(" file ")") "")
  1775.            (nth 1 (car indexelts)) ".")
  1776.           (indent-to 54)
  1777.           (insert
  1778.            (if (nth 2 (car indexelts))
  1779.                (format "  %d." (nth 2 (car indexelts)))
  1780.              "")
  1781.            "\n"))
  1782.       ;; index entries from @include'd file
  1783.       (texinfo-print-index (nth 1 (car indexelts))
  1784.                (nth 2 (car indexelts))))
  1785.     (setq indexelts (cdr indexelts))))
  1786.  
  1787.  
  1788. ;;; Glyphs: @equiv, @error, etc
  1789.  
  1790. ;; @equiv           to show that two expressions are equivalent
  1791. ;; @error           to show an error message
  1792. ;; @expansion       to show what a macro expands to
  1793. ;; @point           to show the location of point in an example
  1794. ;; @print           to show what an evaluated expression prints
  1795. ;; @result          to indicate the value returned by an expression
  1796.  
  1797. (put 'equiv 'texinfo-format 'texinfo-format-equiv)
  1798. (defun texinfo-format-equiv ()
  1799.   (texinfo-parse-arg-discard)
  1800.   (insert "=="))
  1801.  
  1802. (put 'error 'texinfo-format 'texinfo-format-error)
  1803. (defun texinfo-format-error ()
  1804.   (texinfo-parse-arg-discard)
  1805.   (insert "error-->"))
  1806.  
  1807. (put 'expansion 'texinfo-format 'texinfo-format-expansion)
  1808. (defun texinfo-format-expansion ()
  1809.   (texinfo-parse-arg-discard)
  1810.   (insert "==>"))
  1811.  
  1812. (put 'point 'texinfo-format 'texinfo-format-point)
  1813. (defun texinfo-format-point ()
  1814.   (texinfo-parse-arg-discard)
  1815.   (insert "-!-"))
  1816.  
  1817. (put 'print 'texinfo-format 'texinfo-format-print)
  1818. (defun texinfo-format-print ()
  1819.   (texinfo-parse-arg-discard)
  1820.   (insert "-|"))
  1821.  
  1822. (put 'result 'texinfo-format 'texinfo-format-result)
  1823. (defun texinfo-format-result ()
  1824.   (texinfo-parse-arg-discard)
  1825.   (insert "=>"))
  1826.  
  1827.  
  1828. ;;; Definition formatting: @deffn, @defun, etc
  1829.  
  1830. ;; What definition formatting produces:
  1831. ;;
  1832. ;; @deffn category name args...
  1833. ;;     In Info, `Category: name ARGS'
  1834. ;;     In index: name:  node. line#.
  1835. ;;
  1836. ;; @defvr category name 
  1837. ;;     In Info, `Category: name'
  1838. ;;     In index: name:  node. line#.
  1839. ;;
  1840. ;; @deftp category name attributes...
  1841. ;; `category name attributes...'       Note: @deftp args in lower case.
  1842. ;;     In index: name:  node. line#.
  1843. ;;
  1844. ;; Specialized function-like or variable-like entity:
  1845. ;;
  1846. ;; @defun, @defmac, @defspec, @defvar, @defopt
  1847. ;;
  1848. ;; @defun name args           In Info, `Function: name ARGS'
  1849. ;; @defmac name args          In Info, `Macro: name ARGS'
  1850. ;; @defvar name               In Info, `Variable: name'
  1851. ;; etc.
  1852. ;;     In index: name:  node. line#.
  1853. ;;
  1854. ;; Generalized typed-function-like or typed-variable-like entity:
  1855. ;; @deftypefn category data-type name args...
  1856. ;;     In Info, `Category:  data-type name args...'
  1857. ;; @deftypevr category data-type name 
  1858. ;;     In Info, `Category:  data-type name'
  1859. ;;     In index: name:  node. line#.
  1860. ;;
  1861. ;; Specialized typed-function-like or typed-variable-like entity:
  1862. ;; @deftypefun data-type name args...
  1863. ;;     In Info, `Function:  data-type name ARGS'
  1864. ;;     In index: name:  node. line#.   
  1865. ;;
  1866. ;; @deftypevar data-type name 
  1867. ;;     In Info, `Variable:  data-type name'
  1868. ;;     In index: name:  node. line#.   but include args after name!?
  1869. ;;
  1870. ;; Generalized object oriented entity: 
  1871. ;; @defop category class name args...
  1872. ;;     In Info, `Category on class: name ARG'
  1873. ;;     In index: name on class: node. line#.
  1874. ;;
  1875. ;; @defcv category class name         
  1876. ;;     In Info, `Category of class: name'
  1877. ;;     In index: name of class: node. line#.
  1878. ;;
  1879. ;; Specialized object oriented entity:
  1880. ;; @defmethod class name args... 
  1881. ;;     In Info, `Method on class: name ARGS'
  1882. ;;     In index: name on class: node. line#.
  1883. ;;
  1884. ;; @defivar class name
  1885. ;;     In Info, `Instance variable of class: name'
  1886. ;;     In index: name of class: node. line#.
  1887.  
  1888.  
  1889. ;;; The definition formatting functions
  1890.  
  1891. (defun texinfo-format-defun ()
  1892.   (texinfo-push-stack 'defun nil)
  1893.   (setq fill-column (- fill-column 5))
  1894.   (texinfo-format-defun-1 t))
  1895.  
  1896. (defun texinfo-end-defun ()
  1897.   (setq fill-column (+ fill-column 5))
  1898.   (texinfo-discard-command)
  1899.   (let ((start (nth 1 (texinfo-pop-stack 'defun))))
  1900.     (texinfo-do-itemize start)
  1901.     ;; Delete extra newline inserted after header.
  1902.     (save-excursion
  1903.       (goto-char start)
  1904.       (delete-char -1))))
  1905.  
  1906. (defun texinfo-format-defunx ()
  1907.   (texinfo-format-defun-1 nil))
  1908.  
  1909. (defun texinfo-format-defun-1 (first-p)
  1910.   (let ((parse-args (texinfo-format-parse-defun-args))
  1911.     (command-type (get texinfo-command-name 'texinfo-defun-type)))
  1912.     (texinfo-discard-command)
  1913.     ;; Delete extra newline inserted after previous header line.
  1914.     (if (not first-p)
  1915.     (delete-char -1))
  1916.     (funcall
  1917.      (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
  1918.     ;; Insert extra newline so that paragraph filling does not mess
  1919.     ;; with header line.
  1920.     (insert "\n\n")
  1921.     (rplaca (cdr (cdr (car texinfo-stack))) (point))
  1922.     (funcall
  1923.      (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
  1924.  
  1925. ;;; Formatting the first line of a definition
  1926.  
  1927. ;; @deffn, @defvr, @deftp
  1928. (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1929. (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1930. (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1931. (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1932. (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1933. (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1934. (defun texinfo-format-deffn (parsed-args)
  1935.   ;; Generalized function-like, variable-like, or generic data-type entity:
  1936.   ;; @deffn category name args...
  1937.   ;;     In Info, `Category: name ARGS'
  1938.   ;; @deftp category name attributes...
  1939.   ;; `category name attributes...'       Note: @deftp args in lower case.
  1940.   (let ((category (car parsed-args))
  1941.         (name (car (cdr parsed-args)))
  1942.         (args (cdr (cdr parsed-args))))
  1943.     (insert " -- " category ": " name)
  1944.     (while args
  1945.       (insert " "
  1946.               (if (or (= ?& (aref (car args) 0))
  1947.                       (eq (eval (car command-type)) 'deftp-type))
  1948.                   (car args)
  1949.                 (upcase (car args))))
  1950.       (setq args (cdr args)))))
  1951.  
  1952. ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
  1953. (put 'defun 'texinfo-deffn-formatting-property
  1954.      'texinfo-format-specialized-defun)
  1955. (put 'defunx 'texinfo-deffn-formatting-property
  1956.      'texinfo-format-specialized-defun)
  1957. (put 'defmac 'texinfo-deffn-formatting-property
  1958.      'texinfo-format-specialized-defun)
  1959. (put 'defmacx 'texinfo-deffn-formatting-property
  1960.      'texinfo-format-specialized-defun)
  1961. (put 'defspec 'texinfo-deffn-formatting-property
  1962.      'texinfo-format-specialized-defun)
  1963. (put 'defspecx 'texinfo-deffn-formatting-property
  1964.      'texinfo-format-specialized-defun)
  1965. (put 'defvar 'texinfo-deffn-formatting-property
  1966.      'texinfo-format-specialized-defun)
  1967. (put 'defvarx 'texinfo-deffn-formatting-property
  1968.      'texinfo-format-specialized-defun)
  1969. (put 'defopt 'texinfo-deffn-formatting-property
  1970.      'texinfo-format-specialized-defun)
  1971. (put 'defoptx 'texinfo-deffn-formatting-property
  1972.      'texinfo-format-specialized-defun)
  1973. (defun texinfo-format-specialized-defun (parsed-args)
  1974.   ;; Specialized function-like or variable-like entity:
  1975.   ;; @defun name args           In Info, `Function: Name ARGS'
  1976.   ;; @defmac name args          In Info, `Macro: Name ARGS'
  1977.   ;; @defvar name               In Info, `Variable: Name'
  1978.   ;; Use cdr of command-type to determine category:
  1979.   (let ((category (car (cdr command-type)))
  1980.         (name (car parsed-args))
  1981.         (args (cdr parsed-args)))
  1982.     (insert " -- " category ": " name)
  1983.     (while args
  1984.       (insert " "
  1985.               (if (= ?& (aref (car args) 0))
  1986.                   (car args)
  1987.                 (upcase (car args))))
  1988.       (setq args (cdr args)))))
  1989.  
  1990. ;; @deftypefn, @deftypevr: Generalized typed
  1991. (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  1992. (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  1993. (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  1994. (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  1995. (defun texinfo-format-deftypefn (parsed-args)
  1996.   ;; Generalized typed-function-like or typed-variable-like entity:
  1997.   ;; @deftypefn category data-type name args...
  1998.   ;;     In Info, `Category:  data-type name args...'
  1999.   ;; @deftypevr category data-type name 
  2000.   ;;     In Info, `Category:  data-type name'
  2001.   ;; Note: args in lower case, unless modified in command line.
  2002.   (let ((category (car parsed-args))
  2003.         (data-type (car (cdr parsed-args)))
  2004.         (name (car (cdr (cdr parsed-args))))
  2005.         (args (cdr (cdr (cdr parsed-args)))))
  2006.     (insert " -- " category ": " data-type " " name)
  2007.     (while args
  2008.       (insert " " (car args))
  2009.       (setq args (cdr args)))))
  2010.  
  2011. ;; @deftypefun, @deftypevar: Specialized typed
  2012. (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2013. (put 'deftypefunx 'texinfo-deffn-formatting-property
  2014.      'texinfo-format-deftypefun)
  2015. (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2016. (put 'deftypevarx 'texinfo-deffn-formatting-property
  2017.      'texinfo-format-deftypefun)
  2018. (defun texinfo-format-deftypefun (parsed-args)
  2019.   ;; Specialized typed-function-like or typed-variable-like entity:
  2020.   ;; @deftypefun data-type name args...
  2021.   ;;     In Info, `Function:  data-type name ARGS'
  2022.   ;; @deftypevar data-type name 
  2023.   ;;     In Info, `Variable:  data-type name'
  2024.   ;; Note: args in lower case, unless modified in command line.
  2025.   ;; Use cdr of command-type to determine category:
  2026.   (let ((category (car (cdr command-type)))
  2027.         (data-type (car parsed-args))
  2028.         (name (car (cdr  parsed-args)))
  2029.         (args (cdr (cdr parsed-args))))
  2030.     (insert " -- " category ": " data-type " " name)
  2031.     (while args
  2032.       (insert " " (car args))
  2033.       (setq args (cdr args)))))
  2034.  
  2035. ;; @defop: Generalized object-oriented
  2036. (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2037. (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2038. (defun texinfo-format-defop (parsed-args)
  2039.   ;; Generalized object oriented entity: 
  2040.   ;; @defop category class name args...
  2041.   ;;     In Info, `Category on class: name ARG'
  2042.   ;; Note: args in upper case; use of `on'
  2043.   (let ((category (car parsed-args))
  2044.         (class (car (cdr parsed-args)))
  2045.         (name (car (cdr (cdr parsed-args))))
  2046.         (args (cdr (cdr (cdr parsed-args)))))
  2047.     (insert " -- " category " on " class ": " name)
  2048.     (while args
  2049.       (insert " " (upcase (car args)))
  2050.       (setq args (cdr args)))))
  2051.  
  2052. ;; @defcv: Generalized object-oriented
  2053. (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2054. (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2055. (defun texinfo-format-defcv (parsed-args)
  2056.   ;; Generalized object oriented entity: 
  2057.   ;; @defcv category class name         
  2058.   ;;     In Info, `Category of class: name'
  2059.   ;; Note: args in upper case; use of `of'
  2060.   (let ((category (car parsed-args))
  2061.         (class (car (cdr parsed-args)))
  2062.         (name (car (cdr (cdr parsed-args))))
  2063.         (args (cdr (cdr (cdr parsed-args)))))
  2064.     (insert " -- " category " of " class ": " name)
  2065.     (while args
  2066.       (insert " " (upcase (car args)))
  2067.       (setq args (cdr args)))))
  2068.  
  2069. ;; @defmethod: Specialized object-oriented
  2070. (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2071. (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2072. (defun texinfo-format-defmethod (parsed-args)
  2073.   ;; Specialized object oriented entity:
  2074.   ;; @defmethod class name args... 
  2075.   ;;     In Info, `Method on class: name ARGS'
  2076.   ;; Note: args in upper case; use of `on'
  2077.   ;; Use cdr of command-type to determine category:
  2078.   (let ((category (car (cdr command-type)))
  2079.         (class (car parsed-args))
  2080.         (name (car (cdr  parsed-args)))
  2081.         (args (cdr  (cdr parsed-args))))
  2082.     (insert " -- " category " on " class ": " name)
  2083.     (while args
  2084.       (insert " " (upcase (car args)))
  2085.       (setq args (cdr args)))))
  2086.  
  2087. ;; @defivar: Specialized object-oriented
  2088. (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2089. (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2090. (defun texinfo-format-defivar (parsed-args)
  2091.   ;; Specialized object oriented entity:
  2092.   ;; @defivar class name
  2093.   ;;     In Info, `Instance variable of class: name'
  2094.   ;; Note: args in upper case; use of `of'
  2095.   ;; Use cdr of command-type to determine category:
  2096.   (let ((category (car (cdr command-type)))
  2097.         (class (car parsed-args))
  2098.         (name (car (cdr  parsed-args)))
  2099.         (args (cdr  (cdr parsed-args))))
  2100.     (insert " -- " category " of " class ": " name)
  2101.     (while args
  2102.       (insert " " (upcase (car args)))
  2103.       (setq args (cdr args)))))
  2104.  
  2105.  
  2106. ;;; Indexing for definitions
  2107.  
  2108. ;; An index entry has three parts: the `entry proper', the node name, and the
  2109. ;; line number.  Depending on the which command is used, the entry is
  2110. ;; formatted differently:
  2111. ;;
  2112. ;; @defun, 
  2113. ;; @defmac, 
  2114. ;; @defspec, 
  2115. ;; @defvar, 
  2116. ;; @defopt          all use their 1st argument as the entry-proper 
  2117. ;;
  2118. ;; @deffn, 
  2119. ;; @defvr, 
  2120. ;; @deftp 
  2121. ;; @deftypefun
  2122. ;; @deftypevar      all use their 2nd argument as the entry-proper
  2123. ;;
  2124. ;; @deftypefn, 
  2125. ;; @deftypevr       both use their 3rd argument as the entry-proper  
  2126. ;;
  2127. ;; @defmethod       uses its 2nd and 1st arguments as an entry-proper 
  2128. ;;                    formatted: NAME on CLASS
  2129.  
  2130. ;; @defop           uses its 3rd and 2nd arguments as an entry-proper 
  2131. ;;                    formatted: NAME on CLASS
  2132. ;;        
  2133. ;; @defivar         uses its 2nd and 1st arguments as an entry-proper
  2134. ;;                    formatted: NAME of CLASS
  2135. ;;
  2136. ;; @defcv           uses its 3rd and 2nd argument as an entry-proper
  2137. ;;                    formatted: NAME of CLASS
  2138.  
  2139. (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2140. (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2141. (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2142. (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2143. (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2144. (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2145. (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2146. (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2147. (put 'defopt  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2148. (put 'defoptx  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2149. (defun texinfo-index-defun (parsed-args)
  2150.   ;; use 1st parsed-arg  as entry-proper
  2151.   ;; `index-list' will be texinfo-findex or the like
  2152.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2153.     (set index-list
  2154.          (cons 
  2155.           ;; Three elements: entry-proper, node-name, line-number
  2156.           (list
  2157.            (car parsed-args)
  2158.            texinfo-last-node
  2159.            ;; Region formatting may not provide last node position.
  2160.            (if texinfo-last-node-pos
  2161.                (1+ (count-lines texinfo-last-node-pos (point)))
  2162.              1))
  2163.           (symbol-value index-list)))))
  2164.  
  2165. (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2166. (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2167. (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2168. (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2169. (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2170. (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2171. (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2172. (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2173. (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2174. (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2175. (defun texinfo-index-deffn (parsed-args) 
  2176.  ;; use 2nd parsed-arg  as entry-proper
  2177.   ;; `index-list' will be texinfo-findex or the like
  2178.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2179.     (set index-list
  2180.          (cons 
  2181.           ;; Three elements: entry-proper, node-name, line-number
  2182.           (list
  2183.            (car (cdr parsed-args))
  2184.            texinfo-last-node
  2185.            ;; Region formatting may not provide last node position.
  2186.            (if texinfo-last-node-pos
  2187.                (1+ (count-lines texinfo-last-node-pos (point)))
  2188.              1))
  2189.           (symbol-value index-list)))))
  2190.  
  2191. (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2192. (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2193. (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2194. (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2195. (defun texinfo-index-deftypefn (parsed-args)
  2196.   ;; use 3rd parsed-arg  as entry-proper
  2197.   ;; `index-list' will be texinfo-findex or the like
  2198.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2199.     (set index-list
  2200.          (cons 
  2201.           ;; Three elements: entry-proper, node-name, line-number
  2202.           (list
  2203.            (car (cdr (cdr parsed-args)))
  2204.            texinfo-last-node
  2205.            ;; Region formatting may not provide last node position.
  2206.            (if texinfo-last-node-pos
  2207.                (1+ (count-lines texinfo-last-node-pos (point)))
  2208.              1))
  2209.           (symbol-value index-list)))))
  2210.  
  2211. (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2212. (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2213. (defun texinfo-index-defmethod (parsed-args)
  2214.   ;; use 2nd on 1st parsed-arg  as entry-proper
  2215.   ;; `index-list' will be texinfo-findex or the like
  2216.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2217.     (set index-list
  2218.          (cons 
  2219.           ;; Three elements: entry-proper, node-name, line-number
  2220.           (list
  2221.            (format "%s on %s"            
  2222.                    (car (cdr parsed-args))
  2223.                    (car parsed-args))
  2224.            texinfo-last-node
  2225.            ;; Region formatting may not provide last node position.
  2226.            (if texinfo-last-node-pos
  2227.                (1+ (count-lines texinfo-last-node-pos (point)))
  2228.              1))
  2229.           (symbol-value index-list)))))
  2230.  
  2231. (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2232. (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2233. (defun texinfo-index-defop (parsed-args)
  2234.   ;; use 3rd on 2nd parsed-arg  as entry-proper
  2235.   ;; `index-list' will be texinfo-findex or the like
  2236.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2237.     (set index-list
  2238.          (cons 
  2239.           ;; Three elements: entry-proper, node-name, line-number
  2240.           (list
  2241.            (format "%s on %s"            
  2242.                    (car (cdr (cdr parsed-args)))
  2243.                    (car (cdr parsed-args)))
  2244.            texinfo-last-node
  2245.            ;; Region formatting may not provide last node position.
  2246.            (if texinfo-last-node-pos
  2247.                (1+ (count-lines texinfo-last-node-pos (point)))
  2248.              1))
  2249.           (symbol-value index-list)))))
  2250.  
  2251. (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2252. (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2253. (defun texinfo-index-defivar (parsed-args)
  2254.   ;; use 2nd of 1st parsed-arg  as entry-proper
  2255.   ;; `index-list' will be texinfo-findex or the like
  2256.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2257.     (set index-list
  2258.          (cons 
  2259.           ;; Three elements: entry-proper, node-name, line-number
  2260.           (list
  2261.            (format "%s of %s"            
  2262.                    (car (cdr parsed-args))
  2263.                    (car parsed-args))
  2264.            texinfo-last-node
  2265.            ;; Region formatting may not provide last node position.
  2266.            (if texinfo-last-node-pos
  2267.                (1+ (count-lines texinfo-last-node-pos (point)))
  2268.              1))
  2269.           (symbol-value index-list)))))
  2270.  
  2271. (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2272. (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2273. (defun texinfo-index-defcv (parsed-args)
  2274.   ;; use 3rd of 2nd parsed-arg  as entry-proper
  2275.   ;; `index-list' will be texinfo-findex or the like
  2276.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2277.     (set index-list
  2278.          (cons 
  2279.           ;; Three elements: entry-proper, node-name, line-number
  2280.           (list
  2281.            (format "%s of %s"            
  2282.                    (car (cdr (cdr parsed-args)))
  2283.                    (car (cdr parsed-args)))
  2284.            texinfo-last-node
  2285.            ;; Region formatting may not provide last node position.
  2286.            (if texinfo-last-node-pos
  2287.                (1+ (count-lines texinfo-last-node-pos (point)))
  2288.              1))
  2289.           (symbol-value index-list)))))
  2290.  
  2291.  
  2292. ;;; Properties for definitions
  2293.  
  2294. ;; Each definition command has six properties:
  2295. ;;
  2296. ;; 1. texinfo-deffn-formatting-property      to format definition line
  2297. ;; 2. texinfo-defun-indexing-property        to create index entry
  2298. ;; 3. texinfo-format                         formatting command
  2299. ;; 4. texinfo-end                            end formatting command
  2300. ;; 5. texinfo-defun-type                     type of deffn to format
  2301. ;; 6. texinfo-defun-index                    type of index to use
  2302. ;;
  2303. ;; The `x' forms of each definition command are used for the second
  2304. ;; and subsequent header lines.
  2305.  
  2306. ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
  2307. ;; are listed just before the appropriate formatting and indexing commands.
  2308.  
  2309. (put 'deffn 'texinfo-format 'texinfo-format-defun)
  2310. (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
  2311. (put 'deffn 'texinfo-end 'texinfo-end-defun)
  2312. (put 'deffn 'texinfo-defun-type '('deffn-type nil))
  2313. (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
  2314. (put 'deffn 'texinfo-defun-index 'texinfo-findex)
  2315. (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
  2316.  
  2317. (put 'defun 'texinfo-format 'texinfo-format-defun)
  2318. (put 'defunx 'texinfo-format 'texinfo-format-defunx)
  2319. (put 'defun 'texinfo-end 'texinfo-end-defun)
  2320. (put 'defun 'texinfo-defun-type '('defun-type "Function"))
  2321. (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
  2322. (put 'defun 'texinfo-defun-index 'texinfo-findex)
  2323. (put 'defunx 'texinfo-defun-index 'texinfo-findex)
  2324.  
  2325. (put 'defmac 'texinfo-format 'texinfo-format-defun)
  2326. (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
  2327. (put 'defmac 'texinfo-end 'texinfo-end-defun)
  2328. (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
  2329. (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
  2330. (put 'defmac 'texinfo-defun-index 'texinfo-findex)
  2331. (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
  2332.  
  2333. (put 'defspec 'texinfo-format 'texinfo-format-defun)
  2334. (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
  2335. (put 'defspec 'texinfo-end 'texinfo-end-defun)
  2336. (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
  2337. (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
  2338. (put 'defspec 'texinfo-defun-index 'texinfo-findex)
  2339. (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
  2340.  
  2341. (put 'defvr 'texinfo-format 'texinfo-format-defun)
  2342. (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
  2343. (put 'defvr 'texinfo-end 'texinfo-end-defun)
  2344. (put 'defvr 'texinfo-defun-type '('deffn-type nil))
  2345. (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
  2346. (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
  2347. (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
  2348.  
  2349. (put 'defvar 'texinfo-format 'texinfo-format-defun)
  2350. (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
  2351. (put 'defvar 'texinfo-end 'texinfo-end-defun)
  2352. (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
  2353. (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
  2354. (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
  2355. (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
  2356.  
  2357. (put 'defconst 'texinfo-format 'texinfo-format-defun)
  2358. (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
  2359. (put 'defconst 'texinfo-end 'texinfo-end-defun)
  2360. (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
  2361. (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
  2362. (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
  2363. (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
  2364.  
  2365. (put 'defcmd 'texinfo-format 'texinfo-format-defun)
  2366. (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
  2367. (put 'defcmd 'texinfo-end 'texinfo-end-defun)
  2368. (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
  2369. (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
  2370. (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
  2371. (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
  2372.  
  2373. (put 'defopt 'texinfo-format 'texinfo-format-defun)
  2374. (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
  2375. (put 'defopt 'texinfo-end 'texinfo-end-defun)
  2376. (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
  2377. (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
  2378. (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
  2379. (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
  2380.  
  2381. (put 'deftp 'texinfo-format 'texinfo-format-defun)
  2382. (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
  2383. (put 'deftp 'texinfo-end 'texinfo-end-defun)
  2384. (put 'deftp 'texinfo-defun-type '('deftp-type nil))
  2385. (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
  2386. (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
  2387. (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
  2388.  
  2389. ;;; Object-oriented stuff is a little hairier.
  2390.  
  2391. (put 'defop 'texinfo-format 'texinfo-format-defun)
  2392. (put 'defopx 'texinfo-format 'texinfo-format-defunx)
  2393. (put 'defop 'texinfo-end 'texinfo-end-defun)
  2394. (put 'defop 'texinfo-defun-type '('defop-type nil))
  2395. (put 'defopx 'texinfo-defun-type '('defop-type nil))
  2396. (put 'defop 'texinfo-defun-index 'texinfo-findex)
  2397. (put 'defopx 'texinfo-defun-index 'texinfo-findex)
  2398.  
  2399. (put 'defmethod 'texinfo-format 'texinfo-format-defun)
  2400. (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
  2401. (put 'defmethod 'texinfo-end 'texinfo-end-defun)
  2402. (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
  2403. (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
  2404. (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
  2405. (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
  2406.  
  2407. (put 'defcv 'texinfo-format 'texinfo-format-defun)
  2408. (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
  2409. (put 'defcv 'texinfo-end 'texinfo-end-defun)
  2410. (put 'defcv 'texinfo-defun-type '('defop-type nil))
  2411. (put 'defcvx 'texinfo-defun-type '('defop-type nil))
  2412. (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
  2413. (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
  2414.  
  2415. (put 'defivar 'texinfo-format 'texinfo-format-defun)
  2416. (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
  2417. (put 'defivar 'texinfo-end 'texinfo-end-defun)
  2418. (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2419. (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2420. (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
  2421. (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
  2422.  
  2423. ;;; Typed functions and variables
  2424.  
  2425. (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
  2426. (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
  2427. (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
  2428. (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
  2429. (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
  2430. (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
  2431. (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
  2432.  
  2433. (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
  2434. (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
  2435. (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
  2436. (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
  2437. (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
  2438. (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
  2439. (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
  2440.  
  2441. (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
  2442. (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
  2443. (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
  2444. (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
  2445. (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
  2446. (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
  2447. (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
  2448.  
  2449. (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
  2450. (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
  2451. (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
  2452. (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
  2453. (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
  2454. (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
  2455. (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
  2456.  
  2457.  
  2458. ;;; @set, @clear, @ifset, @ifclear
  2459.  
  2460. ;; If a flag is set with @set FLAG, then text between @ifset and @end
  2461. ;; ifset is formatted normally, but if the flag is is cleared with
  2462. ;; @clear FLAG, then the text is not formatted; it is ignored.
  2463.  
  2464. ;; If a flag is cleared with @clear FLAG, then text between @ifclear
  2465. ;; and @end ifclear is formatted normally, but if the flag is is set with
  2466. ;; @set FLAG, then the text is not formatted; it is ignored.  @ifclear
  2467. ;; is the opposite of @ifset.
  2468.  
  2469. (put 'clear 'texinfo-format 'texinfo-clear)
  2470. (defun texinfo-clear ()
  2471.   "Clear the value of the flag."
  2472.   (let ((arg (texinfo-parse-arg-discard)))
  2473.     (make-local-variable (intern arg))
  2474.     (set (intern arg) nil)))
  2475.  
  2476. (put 'set 'texinfo-format 'texinfo-set)
  2477. (defun texinfo-set ()
  2478.   "Set the value of the flag."
  2479.   (let ((arg (texinfo-parse-arg-discard)))
  2480.     (make-local-variable (intern arg))
  2481.     (set (intern arg) t)))
  2482.  
  2483. (put 'ifset 'texinfo-end 'texinfo-discard-command)
  2484. (put 'ifset 'texinfo-format 'texinfo-if-set)
  2485. (defun texinfo-if-set ()
  2486.   "If set, continue formatting; else do not format region up to @end ifset"
  2487.   (let ((arg (texinfo-parse-line-arg)))
  2488.     (if (not (boundp (intern arg)))
  2489.       (error  "@ifset flag `%s' is not defined by @set." arg))
  2490.     (texinfo-discard-command)
  2491.     (if  (symbol-value (intern arg))
  2492.         ;; (message  "%s is true." arg)
  2493.         () 
  2494.       ;; (message  "%s is false." arg)
  2495.       (delete-region texinfo-command-start
  2496.                      (progn (re-search-forward "@end ifset[ \t]*\n")
  2497.                             (point))))))
  2498.  
  2499. (put 'ifclear 'texinfo-end 'texinfo-discard-command)
  2500. (put 'ifclear 'texinfo-format 'texinfo-if-clear)
  2501. (defun texinfo-if-clear ()
  2502.   "If clear, do not format up to @end ifclear; else continue formatting."
  2503.   (let ((arg (texinfo-parse-line-arg)))
  2504.     (if (not (boundp (intern arg)))
  2505.       (error  "@ifclear flag `%s' is not defined by @clear or @set." arg))
  2506.     (texinfo-discard-command)
  2507.     (if  (symbol-value (intern arg))
  2508.       (delete-region texinfo-command-start
  2509.                      (progn (re-search-forward "@end ifclear[ \t]*\n")
  2510.                             (point))))))
  2511.  
  2512.  
  2513. ;;; Process included files:  `@include' command
  2514.  
  2515. ;; Updated 19 October 1990
  2516. ;; In the original version, include files were ignored by Info but
  2517. ;; incorporated in to the printed manual.  To make references to the
  2518. ;; included file, the Texinfo source file has to refer to the included
  2519. ;; files using the `(filename)nodename' format for refering to other
  2520. ;; Info files.  Also, the included files had to be formatted on their
  2521. ;; own.  It was just like they were another file.
  2522.  
  2523. ;; Currently, include files are inserted into the buffer that is
  2524. ;; formatted for Info.  If large, the resulting info file is split and
  2525. ;; tagified.  For current include files to work, the master menu must
  2526. ;; refer to all the nodes, and the highest level nodes in the include
  2527. ;; files must have the correct next, prev, and up pointers.
  2528.  
  2529. ;; The included file may have an @setfilename and even an @settitle,
  2530. ;; but not an /input texinfo
  2531.  
  2532. ; Original definition:
  2533. ; (defun texinfo-format-include ()
  2534. ;   (let ((filename (texinfo-parse-arg-discard))
  2535. ;     (default-directory input-directory)
  2536. ;     subindex)
  2537. ;     (setq subindex
  2538. ;       (save-excursion
  2539. ;         (progn (find-file
  2540. ;             (cond ((file-readable-p (concat filename ".texinfo"))
  2541. ;                (concat filename ".texinfo"))
  2542. ;               ((file-readable-p (concat filename ".texi"))
  2543. ;                (concat filename ".texi"))
  2544. ;               ((file-readable-p (concat filename ".tex"))
  2545. ;                (concat filename ".tex"))
  2546. ;               ((file-readable-p filename)
  2547. ;                filename)
  2548. ;               (t (error "@include'd file %s not found"
  2549. ;                     filename))))
  2550. ;            (texinfo-format-buffer-1))))
  2551. ;     (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
  2552. ;     (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
  2553. ;     (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
  2554. ;     (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
  2555. ;     (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
  2556. ;     (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
  2557.  
  2558. (defun texinfo-subindex (indexvar file content)
  2559.   (set indexvar (cons (list 'recurse file content)
  2560.               (symbol-value indexvar))))
  2561.  
  2562. (put 'include 'texinfo-format 'texinfo-format-include)
  2563. (defun texinfo-format-include ()
  2564.   (let ((filename (concat input-directory
  2565.               (texinfo-parse-arg-discard)))
  2566.     (default-directory input-directory))
  2567.     (message "Reading: %s" filename)
  2568.     (save-excursion
  2569.       (save-restriction
  2570.         (narrow-to-region
  2571.          (point)
  2572.          (+ (point) (car (cdr (insert-file-contents filename)))))
  2573.         (goto-char (point-min))
  2574.         (texinfo-append-refill)
  2575.         (texinfo-format-convert (point-min) (point-max))))
  2576.     (setq last-input-buffer input-buffer)  ; to bypass setfilename
  2577.     ))
  2578.  
  2579.  
  2580. ;;; Numerous commands do nothing in Texinfo
  2581.  
  2582. ;; These commands are defined in texinfo.tex for printed output.
  2583.  
  2584. (put 'bye 'texinfo-format 'texinfo-discard-line)
  2585. (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
  2586. (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
  2587. (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
  2588. (put 'finalout 'texinfo-format 'texinfo-discard-line)
  2589. (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
  2590. (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
  2591. (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
  2592. (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
  2593. (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
  2594. (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
  2595. (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
  2596. (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
  2597. (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
  2598. (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
  2599. (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
  2600. (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
  2601. (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
  2602. (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
  2603. (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
  2604. (put 'smallbook 'texinfo-format 'texinfo-discard-line)
  2605. (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
  2606.  
  2607.  
  2608. ;;; Some commands cannot be handled
  2609.  
  2610. (defun texinfo-unsupported ()
  2611.   (error "%s is not handled by texinfo"
  2612.      (buffer-substring texinfo-command-start texinfo-command-end)))
  2613.  
  2614. ;;; Batch formatting
  2615.  
  2616. (defun batch-texinfo-format ()
  2617.   "Runs  texinfo-format-buffer  on the files remaining on the command line.
  2618. Must be used only with -batch, and kills emacs on completion.
  2619. Each file will be processed even if an error occurred previously.
  2620. For example, invoke
  2621.   \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
  2622.   (if (not noninteractive)
  2623.       (error "batch-texinfo-format may only be used -batch."))
  2624.   (let ((version-control t)
  2625.     (auto-save-default nil)
  2626.     (find-file-run-dired nil)
  2627.     (kept-old-versions 259259)
  2628.     (kept-new-versions 259259))
  2629.     (let ((error 0)
  2630.       file
  2631.       (files ()))
  2632.       (while command-line-args-left
  2633.     (setq file (expand-file-name (car command-line-args-left)))
  2634.     (cond ((not (file-exists-p file))
  2635.            (message ">> %s does not exist!" file)
  2636.            (setq error 1
  2637.              command-line-args-left (cdr command-line-args-left)))
  2638.           ((file-directory-p file)
  2639.            (setq command-line-args-left
  2640.              (nconc (directory-files file)
  2641.                 (cdr command-line-args-left))))
  2642.           (t
  2643.            (setq files (cons file files)
  2644.              command-line-args-left (cdr command-line-args-left)))))
  2645.       (while files
  2646.     (setq file (car files)
  2647.           files (cdr files))
  2648.     (condition-case err
  2649.         (progn
  2650.           (if buffer-file-name (kill-buffer (current-buffer)))
  2651.           (find-file file)
  2652.           (buffer-flush-undo (current-buffer))
  2653.           (set-buffer-modified-p nil)
  2654.           (texinfo-mode)
  2655.           (message "texinfo formatting %s..." file)
  2656.           (texinfo-format-buffer nil)
  2657.           (if (buffer-modified-p)
  2658.           (progn (message "Saving modified %s" (buffer-file-name))
  2659.              (save-buffer))))
  2660.       (error
  2661.        (message ">> Error: %s" (prin1-to-string err))
  2662.        (message ">>  point at")
  2663.        (let ((s (buffer-substring (point)
  2664.                       (min (+ (point) 100)
  2665.                        (point-max))))
  2666.          (tem 0))
  2667.          (while (setq tem (string-match "\n+" s tem))
  2668.            (setq s (concat (substring s 0 (match-beginning 0))
  2669.                    "\n>>  "
  2670.                    (substring s (match-end 0)))
  2671.              tem (1+ tem)))
  2672.          (message ">>  %s" s))
  2673.        (setq error 1))))
  2674.       (kill-emacs error))))
  2675.  
  2676.  
  2677. ;;; Place `provide' at end of file.
  2678. (provide 'texinfmt)
  2679. ;;;;;;;;;;;;;;;; end texinfmt.el ;;;;;;;;;;;;;;;;
  2680.