home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / texinfmt.el < prev    next >
Encoding:
Text File  |  1995-08-08  |  113.0 KB  |  3,069 lines

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