home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / texinfo-3.1-src.lha / src / amiga / texinfo-3.1 / emacs / texinfmt.el < prev    next >
Lisp/Scheme  |  1993-05-19  |  114KB  |  3,012 lines

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