home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / texinfmt.el < prev    next >
Encoding:
Text File  |  1992-06-29  |  55.6 KB  |  1,629 lines

  1. ;; Convert texinfo files to info files.
  2. ;; Copyright (C) 1985, 1986, 1988, 1990 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; Updated May 1990 to correspond, more or less, to version 2.8 of
  21. ;; texinfo.tex.  NOTE: texinfmt.el is being phased out; it is being
  22. ;; replaced by makeinfo.c, which is faster and provides better error
  23. ;; checking.  
  24. ;; Robert J. Chassell, bob@ai.mit.edu
  25.  
  26. (defvar texinfo-format-syntax-table nil)
  27.  
  28. (defvar texinfo-vindex)
  29. (defvar texinfo-findex)
  30. (defvar texinfo-cindex)
  31. (defvar texinfo-pindex)
  32. (defvar texinfo-tindex)
  33. (defvar texinfo-kindex)
  34. (defvar texinfo-last-node)
  35. (defvar texinfo-node-names)
  36.  
  37. (if texinfo-format-syntax-table
  38.     nil
  39.   (setq texinfo-format-syntax-table (make-syntax-table))
  40.   (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
  41.   (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
  42.   (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
  43.   (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
  44.   (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
  45.   (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
  46.   (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
  47.   (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
  48.   (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
  49.   (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
  50.   (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
  51.  
  52. (defun texinfo-format-buffer (&optional notagify)
  53.   "Process the current buffer as texinfo code, into an Info file.
  54. The Info file output is generated in a buffer visiting the Info file
  55. names specified in the @setfilename command.
  56.  
  57. Non-nil argument (prefix, if interactive) means don't make tag table
  58. and don't split the file if large.  You can use Info-tagify and
  59. Info-split to do these manually."
  60.   (interactive "P")
  61.   (let ((lastmessage "Formatting Info file..."))
  62.     (message lastmessage)
  63.     (texinfo-format-buffer-1)
  64.     (if notagify
  65.     nil
  66.       (if (> (buffer-size) 30000)
  67.       (progn
  68.         (message (setq lastmessage "Making tags table for Info file..."))
  69.         (Info-tagify)))
  70.       (if (> (buffer-size) 100000)
  71.       (progn
  72.         (message (setq lastmessage "Splitting Info file..."))
  73.         (Info-split))))
  74.     (message (concat lastmessage
  75.              (if (interactive-p) "done.  Now save it." "done.")))))
  76.  
  77.  
  78. (defun texinfo-format-buffer-1 ()
  79.   (let (texinfo-format-filename
  80.     texinfo-example-start
  81.     texinfo-command-start
  82.     texinfo-command-end
  83.     texinfo-command-name
  84.     texinfo-last-node
  85.     texinfo-vindex
  86.     texinfo-findex
  87.     texinfo-cindex
  88.     texinfo-pindex
  89.     texinfo-tindex
  90.     texinfo-kindex
  91.     texinfo-stack
  92.     texinfo-node-names
  93.     outfile
  94.     (fill-column fill-column)
  95.     (input-buffer (current-buffer))
  96.     (input-directory default-directory))
  97.     (save-excursion
  98.       (goto-char (point-min))
  99.       (search-forward "@setfilename")
  100.       (setq texinfo-command-end (point))
  101.       (setq outfile (texinfo-parse-line-arg)))
  102.     (find-file outfile)
  103.     (texinfo-mode)
  104.     (set-syntax-table texinfo-format-syntax-table)
  105.     (erase-buffer)
  106.     (insert-buffer-substring input-buffer)
  107.     (goto-char (point-min))
  108.     (search-forward "@setfilename")
  109.     (beginning-of-line)
  110.     (delete-region (point-min) (point))
  111.     ;; Remove @bye at end of file, if it is there.
  112.     (goto-char (point-max))
  113.     (if (search-backward "@bye" nil t)
  114.     (delete-region (point) (point-max)))
  115.     ;; Make sure buffer ends in a newline.
  116.     (or (= (preceding-char) ?\n)
  117.     (insert "\n"))
  118.     ;; Scan the whole buffer, converting to Info format.
  119.     (texinfo-format-scan)
  120.     ;; Return data for indices.
  121.     (goto-char (point-min))
  122.     (list outfile
  123.       texinfo-vindex texinfo-findex texinfo-cindex
  124.       texinfo-pindex texinfo-tindex texinfo-kindex)))
  125.  
  126. (defvar texinfo-region-buffer-name "*Info Region*"
  127.   "*Name of the temporary buffer used by \\[texinfo-format-region].")
  128.  
  129. (defun texinfo-format-region (region-beginning region-ending)
  130.   "Convert the current region of the Texinfo file to Info format.
  131. This lets you see what that part of the file will look like in Info.
  132. The command is bound to \\[texinfo-format-region].  The text that is
  133. converted to Info is stored in a temporary buffer."
  134.   (interactive "r")
  135.   (message "Converting region to Info format...")
  136.   (let (texinfo-command-start
  137.     texinfo-command-end
  138.     texinfo-command-name
  139.     texinfo-vindex
  140.     texinfo-findex
  141.     texinfo-cindex
  142.     texinfo-pindex
  143.     texinfo-tindex
  144.     texinfo-kindex
  145.     texinfo-stack
  146.     texinfo-format-filename
  147.     texinfo-example-start
  148.     texinfo-last-node
  149.     texinfo-node-names
  150.     (fill-column fill-column)
  151.     (input-buffer (current-buffer))
  152.     (input-directory default-directory)
  153.     filename-beginning
  154.     filename-ending)
  155.  
  156. ;;; Find a buffer to use.
  157.  
  158.     (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
  159.  
  160.     ;; Insert the region into the buffer.
  161.     (erase-buffer)
  162.  
  163.     (save-excursion
  164.       (set-buffer input-buffer)
  165.       (save-excursion
  166.     (save-restriction
  167.       (widen)
  168.       (goto-char (point-min))
  169.       ;; Initialize the buffer with the filename
  170.       ;; or else explain that a filename is needed.
  171.       (or (search-forward "@setfilename"
  172.                   (save-excursion (forward-line 100) (point)) t)
  173.           (error "The texinfo file needs a line saying: @setfilename <name>"))
  174.       (beginning-of-line)
  175.       (setq filename-beginning (point))
  176.       (forward-line 1)
  177.       (setq filename-ending (point)))))
  178.  
  179.     ;; Insert the @setfilename line into the buffer.
  180.     (insert-buffer-substring input-buffer
  181.                  (min filename-beginning region-beginning)  
  182.                  filename-ending)
  183.     
  184.     ;; Insert the region into the buffer.
  185.     (insert-buffer-substring input-buffer
  186.                  (max region-beginning filename-ending)
  187.                  region-ending)
  188.  
  189.     (texinfo-mode)
  190.  
  191.     ;; Install a syntax table useful for scanning command operands.
  192.     (set-syntax-table texinfo-format-syntax-table)
  193.     
  194.     ;; If the region includes the effective end of the data,
  195.     ;; discard everything after that.
  196.     (goto-char (point-max))
  197.     (if (re-search-backward "^@bye" nil t)
  198.     (delete-region (point) (point-max)))
  199.     ;; Make sure buffer ends in a newline.
  200.     (or (= (preceding-char) ?\n)
  201.     (insert "\n"))
  202.  
  203.     ;; Now convert for real.
  204.     (goto-char (point-min))
  205.     (texinfo-format-scan)
  206.     (goto-char (point-min)))
  207.  
  208.   (message "Done."))
  209.  
  210.  
  211. ;; Perform those texinfo-to-info conversions that apply to the whole input
  212. ;; uniformly.
  213. (defun texinfo-format-scan ()
  214.     ;; Convert left and right quotes to typewriter font quotes.
  215.     (goto-char (point-min))
  216.     (while (search-forward "``" nil t)
  217.       (replace-match "\""))
  218.     (goto-char (point-min))
  219.     (while (search-forward "''" nil t)
  220.       (replace-match "\""))
  221.     ;; Scan for @-commands.
  222.     (goto-char (point-min))
  223.     (while (search-forward "@" nil t)
  224.       (if (looking-at "[@{}'` *]")
  225.           ;; Handle a few special @-followed-by-one-char commands.
  226.           (if (= (following-char) ?*)
  227.               (progn
  228.                 ;; remove command
  229.                 (delete-region (1- (point)) (1+ (point)))
  230.                 ;; insert return if not at end of line;
  231.                 ;; else line is already broken.
  232.                 (if (not (= (following-char) ?\n))
  233.                     (insert ?\n)))      
  234.             ;; The other characters are simply quoted.  Delete the @.
  235.             (delete-char -1)
  236.             (forward-char 1))
  237.         ;; @ is followed by a command-word; find the end of the word.
  238.         (setq texinfo-command-start (1- (point)))
  239.         (if (= (char-syntax (following-char)) ?w)
  240.             (forward-word 1)
  241.           (forward-char 1))
  242.         (setq texinfo-command-end (point))
  243.         ;; Call the handler for this command.
  244.         (setq texinfo-command-name
  245.               (intern (buffer-substring (1+ texinfo-command-start)
  246.                                         texinfo-command-end)))
  247.         (let ((cmd (get texinfo-command-name 'texinfo-format)))
  248.           (if cmd (funcall cmd)
  249.             (texinfo-unsupported)))))
  250.     (cond (texinfo-stack
  251.            (goto-char (nth 2 (car texinfo-stack)))
  252.            (error "Unterminated @%s" (car (car texinfo-stack))))))
  253.  
  254. (put 'begin 'texinfo-format 'texinfo-format-begin)
  255. (defun texinfo-format-begin ()
  256.   (texinfo-format-begin-end 'texinfo-format))
  257.  
  258. (put 'end 'texinfo-format 'texinfo-format-end)
  259. (defun texinfo-format-end ()
  260.   (texinfo-format-begin-end 'texinfo-end))
  261.  
  262. (defun texinfo-format-begin-end (prop)
  263.   (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
  264.   (setq cmd (get texinfo-command-name prop))
  265.   (if cmd (funcall cmd)
  266.     (texinfo-unsupported)))
  267.  
  268. (defun texinfo-parse-line-arg ()
  269.   (goto-char texinfo-command-end)
  270.   (let ((start (point)))
  271.     (cond ((looking-at " ")
  272.        (skip-chars-forward " ")
  273.        (setq start (point))
  274.        (end-of-line)
  275.        (setq texinfo-command-end (1+ (point))))
  276.       ((looking-at "{")
  277.        (setq start (1+ (point)))
  278.        (forward-list 1)
  279.        (setq texinfo-command-end (point))
  280.        (forward-char -1))
  281.       (t
  282.        (error "Invalid texinfo command arg format")))
  283.     (prog1 (buffer-substring start (point))
  284.        (if (eolp) (forward-char 1)))))
  285.  
  286. (defun texinfo-parse-expanded-arg ()
  287.   (goto-char texinfo-command-end)
  288.   (let ((start (point))
  289.     marker)
  290.     (cond ((looking-at " ")
  291.        (skip-chars-forward " ")
  292.        (setq start (point))
  293.        (end-of-line)
  294.        (setq texinfo-command-end (1+ (point))))
  295.       ((looking-at "{")
  296.        (setq start (1+ (point)))
  297.        (forward-list 1)
  298.        (setq texinfo-command-end (point))
  299.        (forward-char -1))
  300.       (t
  301.        (error "Invalid texinfo command arg format")))
  302.     (setq marker (move-marker (make-marker) texinfo-command-end))
  303.     (texinfo-format-expand-region start (point))
  304.     (setq texinfo-command-end (marker-position marker))
  305.     (move-marker marker nil)
  306.     (prog1 (buffer-substring start (point))
  307.        (if (eolp) (forward-char 1)))))
  308.  
  309. (defun texinfo-format-expand-region (start end)
  310.   (save-restriction
  311.     (narrow-to-region start end)
  312.     (let (texinfo-command-start
  313.       texinfo-command-end
  314.       texinfo-command-name
  315.       texinfo-stack)
  316.       (texinfo-format-scan))
  317.     (goto-char (point-max))))
  318.  
  319. (defun texinfo-parse-arg-discard ()
  320.   (prog1 (texinfo-parse-line-arg)
  321.      (texinfo-discard-command)))
  322.  
  323. (defun texinfo-discard-command ()
  324.   (delete-region texinfo-command-start texinfo-command-end))
  325.  
  326. (defun texinfo-format-parse-line-args ()
  327.   (let ((start (1- (point)))
  328.     next beg end
  329.     args)
  330.     (skip-chars-forward " ")
  331.     (while (not (eolp))
  332.       (setq beg (point))
  333.       (re-search-forward "[\n,]")
  334.       (setq next (point))
  335.       (if (bolp) (setq next (1- next)))
  336.       (forward-char -1)
  337.       (skip-chars-backward " ")
  338.       (setq end (point))
  339.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  340.                args))
  341.       (goto-char next)
  342.       (skip-chars-forward " "))
  343.     (if (eolp) (forward-char 1))
  344.     (setq texinfo-command-end (point))
  345.     (nreverse args)))
  346.  
  347. (defun texinfo-format-parse-args ()
  348.   (let ((start (1- (point)))
  349.     next beg end
  350.     args)
  351.     (search-forward "{")
  352.     (save-excursion
  353.       (texinfo-format-expand-region 
  354.        (point)
  355.        (save-excursion (up-list 1) (1- (point)))))
  356.     (while (/= (preceding-char) ?\})
  357.       (skip-chars-forward " \t\n")
  358.       (setq beg (point))
  359.       (re-search-forward "[},]")
  360.       (setq next (point))
  361.       (forward-char -1)
  362.       (skip-chars-backward " \t\n")
  363.       (setq end (point))
  364.       (cond ((< beg end)
  365.          (goto-char beg)
  366.          (while (search-forward "\n" end t)
  367.            (replace-match " "))))
  368.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  369.                args))
  370.       (goto-char next))
  371.     (if (eolp) (forward-char 1))
  372.     (setq texinfo-command-end (point))
  373.     (nreverse args)))
  374.  
  375. (defun texinfo-format-parse-defun-args ()
  376.   (goto-char texinfo-command-end)
  377.   (let ((start (point)))
  378.     (end-of-line)
  379.     (setq texinfo-command-end (1+ (point)))
  380.     (let ((marker (move-marker (make-marker) texinfo-command-end)))
  381.       (texinfo-format-expand-region start (point))
  382.       (setq texinfo-command-end (marker-position marker))
  383.       (move-marker marker nil))
  384.     (goto-char start)
  385.     (let ((args '())
  386.       beg end)
  387.       (skip-chars-forward " ")
  388.       (while (not (eolp))
  389.     (cond ((looking-at "{")
  390.            (setq beg (1+ (point)))
  391.            (forward-list 1)
  392.            (setq end (1- (point))))
  393.           (t
  394.            (setq beg (point))
  395.            (re-search-forward "[\n ]")
  396.            (forward-char -1)
  397.            (setq end (point))))
  398.     (setq args (cons (buffer-substring beg end) args))
  399.     (skip-chars-forward " "))
  400.       (forward-char 1)
  401.       (nreverse args))))
  402.  
  403. (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
  404. (defun texinfo-format-setfilename ()
  405.   (let ((arg (texinfo-parse-arg-discard)))
  406.     (setq texinfo-format-filename
  407.       (file-name-nondirectory (expand-file-name arg)))
  408.     (insert "Info file: "
  409.         texinfo-format-filename ",    -*-Text-*-\n"
  410.         "produced by texinfo-format-buffer\nfrom "
  411.         (if (buffer-file-name input-buffer)
  412.         (concat "file: "
  413.             (file-name-sans-versions
  414.              (file-name-nondirectory
  415.               (buffer-file-name input-buffer))))
  416.           (concat "buffer " (buffer-name input-buffer)))
  417.         "\n\n")))
  418.  
  419. (put 'node 'texinfo-format 'texinfo-format-node)
  420. (defun texinfo-format-node ()
  421.   (let* ((args (texinfo-format-parse-line-args))
  422.      (name (nth 0 args))
  423.      (next (nth 1 args))
  424.      (prev (nth 2 args))
  425.      (up (nth 3 args)))
  426.     (texinfo-discard-command)
  427.     (setq texinfo-last-node name)
  428.     (let ((tem (downcase name)))
  429.       (if (assoc tem texinfo-node-names)
  430.       (error "Duplicate node name: %s" name)
  431.     (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
  432.     (or (bolp)
  433.     (insert ?\n))
  434.     (insert "\^_\nFile: " texinfo-format-filename
  435.         "  Node: " name)
  436.     (if prev
  437.     (insert ", Prev: " prev))
  438.     (if up
  439.     (insert ", Up: " up))
  440.     (if next
  441.     (insert ", Next: " next))
  442.     (insert ?\n)))
  443.  
  444. (put 'menu 'texinfo-format 'texinfo-format-menu)
  445. (defun texinfo-format-menu ()
  446.   (texinfo-discard-line)
  447.   (insert "* Menu:\n\n"))
  448.  
  449. (put 'menu 'texinfo-end 'texinfo-discard-command)
  450. (defun texinfo-discard-line ()
  451.   (goto-char texinfo-command-end)
  452.   (skip-chars-forward " \t")
  453.   (or (eolp)
  454.       (error "Extraneous text at end of command line."))
  455.   (goto-char texinfo-command-start)
  456.   (or (bolp)
  457.       (error "Extraneous text at beginning of command line."))
  458.   (delete-region (point) (progn (forward-line 1) (point))))
  459.  
  460. ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
  461. ; -> *Note FNAME: (FILE)NODE
  462. ;   If FILE is missing,
  463. ;    *Note FNAME: NODE
  464. ;   If FNAME is empty and NAME is present
  465. ;    *Note NAME: Node
  466. ;   If both NAME and FNAME are missing
  467. ;    *Note NODE::
  468. ;   texinfo ignores the DOCUMENT argument.
  469. ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  470. ;   If FILE is specified, (FILE)NODE is used for xrefs.
  471. ;   If fifth argument DOCUMENT is specified, produces
  472. ;    See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  473. ;    of DOCUMENT
  474.  
  475. ; @ref             a reference that does not put `See' or `see' in
  476. ;                  the hardcopy and is the same as @xref in Info
  477. (put 'ref 'texinfo-format 'texinfo-format-xref)
  478.  
  479. (put 'xref 'texinfo-format 'texinfo-format-xref)
  480. (defun texinfo-format-xref ()
  481.   (let ((args (texinfo-format-parse-args)))
  482.     (texinfo-discard-command)
  483.     (insert "*Note ")
  484.     (let ((fname (or (nth 1 args) (nth 2 args))))
  485.       (if (null (or fname (nth 3 args)))
  486.       (insert (car args) "::")
  487.     (insert (or fname (car args)) ": ")
  488.     (if (nth 3 args)
  489.         (insert "(" (nth 3 args) ")"))
  490.     (insert (car args))))))
  491.  
  492. (put 'pxref 'texinfo-format 'texinfo-format-pxref)
  493. (defun texinfo-format-pxref ()
  494.   (texinfo-format-xref)
  495.   (or (save-excursion
  496.     (forward-char -2)
  497.     (looking-at "::"))
  498.       (insert ".")))
  499.  
  500. ;@inforef{NODE, FNAME, FILE}
  501. ;Like @xref{NODE, FNAME,,FILE} in texinfo.
  502. ;In Tex, generates "See Info file FILE, node NODE"
  503. (put 'inforef 'texinfo-format 'texinfo-format-inforef)
  504. (defun texinfo-format-inforef ()
  505.   (let ((args (texinfo-format-parse-args)))
  506.     (texinfo-discard-command)
  507.     (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))))
  508.  
  509. (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
  510. (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
  511. (put 'chapter 'texinfo-format 'texinfo-format-chapter)
  512. (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
  513. (put 'appendix 'texinfo-format 'texinfo-format-chapter)
  514. (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
  515. (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
  516. (defun texinfo-format-chapter ()
  517.   (texinfo-format-chapter-1 ?*))
  518.  
  519. (put 'heading 'texinfo-format 'texinfo-format-section)
  520. (put 'isection 'texinfo-format 'texinfo-format-section)
  521. (put 'section 'texinfo-format 'texinfo-format-section)
  522. (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
  523. (put 'appendixsection 'texinfo-format 'texinfo-format-section)
  524. (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
  525. (put 'appendixsec 'texinfo-format 'texinfo-format-section)
  526. (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
  527. (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
  528. (defun texinfo-format-section ()
  529.   (texinfo-format-chapter-1 ?=))
  530.  
  531. (put 'subheading 'texinfo-format 'texinfo-format-subsection)
  532. (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
  533. (put 'subsection 'texinfo-format 'texinfo-format-subsection)
  534. (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
  535. (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
  536. (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  537. (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  538. (defun texinfo-format-subsection ()
  539.   (texinfo-format-chapter-1 ?-))
  540.  
  541. (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
  542. (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
  543. (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
  544. (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  545. (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  546. (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  547. (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  548. (defun texinfo-format-subsubsection ()
  549.   (texinfo-format-chapter-1 ?.))
  550.  
  551. (defun texinfo-format-chapter-1 (belowchar)
  552.   (let ((arg (texinfo-parse-arg-discard)))
  553.     (message "Formatting: %s ... " arg)   ; So we can see where we are.
  554.     (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
  555.     (forward-line -2)))
  556.  
  557. (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
  558. (defun texinfo-format-sectionpad ()
  559.   (let ((str (texinfo-parse-arg-discard)))
  560.     (forward-char -1)
  561.     (let ((column (current-column)))
  562.       (forward-char 1)
  563.       (while (> column 0)
  564.     (insert str)
  565.     (setq column (1- column))))
  566.     (insert ?\n)))
  567.  
  568. (put '\. 'texinfo-format 'texinfo-format-\.)
  569. (defun texinfo-format-\. ()
  570.   (texinfo-discard-command)
  571.   (insert "."))
  572.  
  573. (put '\: 'texinfo-format 'texinfo-format-\:)
  574. (defun texinfo-format-\: ()
  575.   (texinfo-discard-command))
  576.  
  577. (put 'center 'texinfo-format 'texinfo-format-center)
  578. (defun texinfo-format-center ()
  579.   (texinfo-discard-command)
  580.   (let ((indent-tabs-mode nil))
  581.     (center-line)))
  582.  
  583. (put 'sp 'texinfo-format 'texinfo-format-sp)
  584. (defun texinfo-format-sp ()
  585.   (let* ((arg (texinfo-parse-arg-discard))
  586.      (num (read arg)))
  587.     (insert-char ?\n num)))
  588.  
  589. (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
  590. (defun texinfo-format-paragraph-break ()
  591.   (texinfo-parse-arg-discard)
  592.   ;; insert one return if at end of line;
  593.   ;; else insert two returns, to generate a blank line.
  594.   (if (= (following-char) ?\n)
  595.       (insert ?\n)
  596.     (insert-char ?\n 2)))
  597.  
  598.  
  599. ;;; @footnote
  600.  
  601. ; In Texinfo, footnotes are created with the `@footnote' command.
  602. ; This command is followed immediately by a left brace, then by the text of
  603. ; the footnote, and then by a terminating right brace.  The
  604. ; template for a footnote is:
  605. ;      @footnote{TEXT}
  606. ;
  607. ; Info has two footnote styles:
  608. ; `End Node'
  609. ;      In the "End Node" style, all the footnotes for a single node
  610. ;      are placed at the end of that node.  The footnotes are
  611. ;      separated from the rest of the node by a line of dashes with
  612. ;      the word `Footnotes' within it.
  613. ; `Make Node'
  614. ;      In the "Make Node" style, all the footnotes for a single node are
  615. ;      placed in an automatically constructed node of their own.  
  616.  
  617. (put 'footnote 'texinfo-format 'texinfo-format-footnote)
  618.  
  619. (defvar texinfo-footnote-style 'MN "\
  620. *Footnote style, either EN for end node or MN for make node.")
  621.  
  622. (defun texinfo-format-footnote ()
  623.   "Format a footnote in either `end node' or `make node' style.
  624. The   texinfo-footnote-style  variable controls which style is used."
  625.   (cond ((eq texinfo-footnote-style 'EN) (texinfo-format-end-node))
  626.         ((eq texinfo-footnote-style 'MN) (texinfo-format-make-node))))
  627.  
  628. (defun texinfo-format-make-node ()
  629.   "Format footnote in `MN', Make Node, style with notes in own node.
  630. The node is constructed automatically."
  631.   (let* (start
  632.          (arg (texinfo-parse-expanded-arg))
  633.          (node-name-beginning
  634.           (save-excursion
  635.             (re-search-backward
  636.              "^File: \\w+\\(\\w\\|\\s_\\)*[ \t]+Node:")
  637.             (match-end 0)))
  638.          (node-name
  639.           (save-excursion
  640.             (buffer-substring
  641.              (progn (goto-char node-name-beginning) ; skip over node command
  642.                     (skip-chars-forward " \t")  ; and over spaces
  643.                     (point))
  644.              (if (search-forward
  645.                   ","
  646.                   (save-excursion (end-of-line) (point)) t) ; bound search
  647.                  (1- (point))
  648.                (end-of-line) (point))))))
  649.     (texinfo-discard-command)
  650.     (insert (format "() (*note %s-Footnotes::)" node-name))
  651.     (fill-paragraph nil)
  652.     (save-excursion
  653.     (if (re-search-forward "^@node" nil 'move)
  654.         (forward-line -1))
  655.  
  656.     ;; two cases: for the first footnote, we must insert a node header;
  657.     ;; for the second and subsequent footnotes, we need only insert 
  658.     ;; the text of the  footnote.
  659.  
  660.     (if (save-excursion
  661.          (re-search-backward
  662.           (concat node-name "-Footnotes, Up: ")
  663.           node-name-beginning
  664.           t))
  665.         (progn   ; already at least one footnote
  666.           (setq start (point))
  667.           (insert (format "\n()  %s\n" arg))
  668.           (fill-region start (point)))
  669.       ;; else not yet a footnote
  670.       (insert "\n\^_\nFile: "  texinfo-format-filename
  671.               "  Node: " node-name "-Footnotes, Up: " node-name "\n")
  672.       (setq start (point))
  673.       (insert (format "\n()  %s\n" arg))
  674.       (fill-region start (point))))))
  675.  
  676. (defun texinfo-format-end-node ()
  677.   "Format footnote in `EN', End Node, style with notes at end of node."
  678.   (let (start
  679.         (arg (texinfo-parse-expanded-arg)))
  680.     (texinfo-discard-command)
  681.     (insert "() ")
  682.     (fill-paragraph nil)
  683.     (save-excursion
  684.       (if (search-forward "\n--------- Footnotes ---------\n" nil t)
  685.           (progn ; already have footnote, put new one before end of node
  686.             (if (re-search-forward "^@node" nil 'move)
  687.                 (forward-line -1))
  688.             (setq start (point))
  689.             (insert (format "\n()  %s\n" arg))
  690.             (fill-region start (point)))
  691.         ;; else no prior footnote
  692.         (if (re-search-forward "^@node" nil 'move)
  693.             (forward-line -1))
  694.         (insert "\n--------- Footnotes ---------\n")
  695.         (setq start (point))
  696.         (insert (format "\n()  %s\n" arg))
  697.         (fill-region start (point))))))
  698.  
  699.  
  700. ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
  701. ;; @enumerate pushes (enumerate 0 STARTPOS).
  702. ;; @item dispatches to the texinfo-item prop of the first elt of the list.
  703. ;; For itemize, this puts in and rescans the COMMANDS.
  704. ;; For enumerate, this increments the number and puts it in.
  705. ;; In either case, it puts a Backspace at the front of the line
  706. ;; which marks it not to be indented later.
  707. ;; All other lines get indented by 5 when the @end is reached.
  708.  
  709. (defun texinfo-push-stack (check arg)
  710.   (setq texinfo-stack
  711.     (cons (list check arg texinfo-command-start)
  712.           texinfo-stack)))
  713.  
  714. (defun texinfo-pop-stack (check)
  715.   (if (null texinfo-stack)
  716.       (error "Unmatched @end %s" check))
  717.   (if (not (eq (car (car texinfo-stack)) check))
  718.       (error "@end %s matches @%s"
  719.          check (car (car texinfo-stack))))
  720.   (prog1 (cdr (car texinfo-stack))
  721.      (setq texinfo-stack (cdr texinfo-stack))))
  722.  
  723. (put 'itemize 'texinfo-format 'texinfo-itemize)
  724. (defun texinfo-itemize ()
  725.   (texinfo-push-stack 'itemize (texinfo-parse-arg-discard))
  726.   (setq fill-column (- fill-column 5)))
  727.  
  728. (put 'itemize 'texinfo-end 'texinfo-end-itemize)
  729. (defun texinfo-end-itemize ()
  730.   (setq fill-column (+ fill-column 5))
  731.   (texinfo-discard-command)
  732.   (let ((stacktop
  733.      (texinfo-pop-stack 'itemize)))
  734.     (texinfo-do-itemize (nth 1 stacktop))))
  735.  
  736. (put 'enumerate 'texinfo-format 'texinfo-enumerate)
  737. (defun texinfo-enumerate ()
  738.   (texinfo-push-stack 'enumerate 0)
  739.   (setq fill-column (- fill-column 5))
  740.   (texinfo-discard-line))
  741.  
  742. (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
  743. (defun texinfo-end-enumerate ()
  744.   (setq fill-column (+ fill-column 5))
  745.   (texinfo-discard-command)
  746.   (let ((stacktop
  747.      (texinfo-pop-stack 'enumerate)))
  748.     (texinfo-do-itemize (nth 1 stacktop))))
  749.  
  750. (put 'table 'texinfo-format 'texinfo-table)
  751. (defun texinfo-table ()
  752.   (texinfo-push-stack 'table (texinfo-parse-arg-discard))
  753.   (setq fill-column (- fill-column 5)))
  754.  
  755. (put 'ftable 'texinfo-format 'texinfo-ftable)
  756. (defun texinfo-ftable ()
  757.   (texinfo-push-stack 'table "@code")
  758.   (setq fill-column (- fill-column 5))
  759.   (texinfo-discard-line))
  760.  
  761. (put 'description 'texinfo-format 'texinfo-description)
  762. (defun texinfo-description ()
  763.   (texinfo-push-stack 'table "@asis")
  764.   (setq fill-column (- fill-column 5))
  765.   (texinfo-discard-line))
  766.  
  767. (put 'table 'texinfo-end 'texinfo-end-table)
  768. (put 'ftable 'texinfo-end 'texinfo-end-table)
  769. (put 'description 'texinfo-end 'texinfo-end-table)
  770. (defun texinfo-end-table ()
  771.   (setq fill-column (+ fill-column 5))
  772.   (texinfo-discard-command)
  773.   (let ((stacktop
  774.      (texinfo-pop-stack 'table)))
  775.     (texinfo-do-itemize (nth 1 stacktop))))
  776.  
  777. ;; At the @end, indent all the lines within the construct
  778. ;; except those marked with backspace.  FROM says where
  779. ;; construct started.
  780. (defun texinfo-do-itemize (from)
  781.   (save-excursion
  782.    (while (progn (forward-line -1)
  783.          (>= (point) from))
  784.      (if (= (following-char) ?\b)
  785.      (save-excursion
  786.        (delete-char 1)
  787.        (end-of-line)
  788.        (delete-char 6))
  789.        (if (not (looking-at "[ \t]*$"))
  790.        (save-excursion (insert "     ")))))))
  791.  
  792. (put 'item 'texinfo-format 'texinfo-item)
  793. (put 'itemx 'texinfo-format 'texinfo-item)
  794. (defun texinfo-item ()
  795.   (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
  796.  
  797. (put 'itemize 'texinfo-item 'texinfo-itemize-item)
  798. (defun texinfo-itemize-item ()
  799.   (texinfo-discard-line)
  800.   (insert "\b   " (nth 1 (car texinfo-stack)) " \n")
  801.   (forward-line -1))
  802.  
  803. (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
  804. (defun texinfo-enumerate-item ()
  805.   (texinfo-discard-line)
  806.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  807.     (setcar (cdr (car texinfo-stack)) next)
  808.     (insert ?\b (format "%3d. " next) ?\n))
  809.   (forward-line -1))
  810.  
  811. (put 'table 'texinfo-item 'texinfo-table-item)
  812. (defun texinfo-table-item ()
  813.   (let ((arg (texinfo-parse-arg-discard))
  814.     (itemfont (car (cdr (car texinfo-stack)))))
  815.     (insert ?\b itemfont ?\{ arg "}\n     \n"))
  816.   (forward-line -2))
  817.  
  818.  
  819. ; @ftable
  820.  
  821. ; The `@ftable' command is like the `@table' command but it also
  822. ; inserts each item in the first column into the function index.
  823.  
  824. (put 'ftable 'texinfo-format 'texinfo-ftable)
  825.  
  826. ; The following function presumes that the first column of the table
  827. ; should be in `@code' font; but the texinfo.tex source does not
  828. ; presume this.  
  829. ; (defun texinfo-ftable ()
  830. ;   (texinfo-push-stack 'ftable "@code")
  831. ;   (setq fill-column (- fill-column 5))
  832. ;   (texinfo-discard-line))
  833.  
  834. (defun texinfo-ftable ()
  835.   (texinfo-push-stack 'ftable (texinfo-parse-arg-discard))
  836.   (setq fill-column (- fill-column 5)))
  837.  
  838. (put 'ftable 'texinfo-item 'texinfo-ftable-item)
  839. (defun texinfo-ftable-item ()
  840.   (let ((item (texinfo-parse-arg-discard))
  841.         (itemfont (car (cdr (car texinfo-stack))))
  842.         (indexvar 'texinfo-findex))
  843.     (insert ?\b itemfont ?\{ item "}\n     \n")
  844.     (set indexvar
  845.          (cons
  846.           (list item texinfo-last-node)
  847.           (symbol-value indexvar)))
  848.     (forward-line -2)))
  849.  
  850. (put 'ftable 'texinfo-end 'texinfo-end-ftable)
  851. (defun texinfo-end-ftable ()
  852.   (setq fill-column (+ fill-column 5))
  853.   (texinfo-discard-command)
  854.   (let ((stacktop
  855.          (texinfo-pop-stack 'ftable)))
  856.     (texinfo-do-itemize (nth 1 stacktop))))
  857.  
  858.  
  859. (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
  860. (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
  861.  
  862. (put 'iftex 'texinfo-format 'texinfo-format-iftex)
  863. (defun texinfo-format-iftex ()
  864.   (delete-region texinfo-command-start
  865.          (progn (re-search-forward "@end iftex\n")
  866.             (point))))
  867.  
  868. (put 'tex 'texinfo-format 'texinfo-format-tex)
  869. (defun texinfo-format-tex ()
  870.   (delete-region texinfo-command-start
  871.          (progn (re-search-forward "@end tex\n")
  872.             (point))))
  873.  
  874. (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
  875. (defun texinfo-format-titlepage ()
  876.   (delete-region texinfo-command-start
  877.          (progn (search-forward "@end titlepage\n")
  878.             (point))))
  879.  
  880. (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
  881.  
  882. ; @titlespec         an alternative titling command; ignored by Info
  883.  
  884. (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
  885. (defun texinfo-format-titlespec ()
  886.   (delete-region texinfo-command-start
  887.                  (progn (search-forward "@end titlespec\n")
  888.                         (point))))
  889.  
  890. (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
  891.  
  892. ; @today{}
  893.  
  894. (put 'today 'texinfo-format 'texinfo-format-today)
  895.  
  896. ; Produces Day Month Year style of output.  eg `1 Jan 1900'
  897. ; The `@today{}' command requires a pair of braces, like `@dots{}'.
  898. (defun texinfo-format-today ()
  899.   (texinfo-parse-arg-discard)
  900.   (insert (format "%s %s %s"
  901.           (substring (current-time-string) 8 10)
  902.           (substring (current-time-string) 4 7)
  903.           (substring (current-time-string) -4))))
  904.  
  905.  
  906. (put 'ignore 'texinfo-format 'texinfo-format-ignore)
  907. (defun texinfo-format-ignore ()
  908.   (delete-region texinfo-command-start
  909.          (progn (search-forward "@end ignore\n")
  910.             (point))))
  911.  
  912. (put 'endignore 'texinfo-format 'texinfo-discard-line)
  913.  
  914. (put 'var 'texinfo-format 'texinfo-format-var)
  915. ;  @sc  a small caps font for TeX; formatted as `var' in Info
  916. (put 'sc 'texinfo-format 'texinfo-format-var)
  917. (defun texinfo-format-var ()
  918.   (insert (upcase (texinfo-parse-arg-discard)))
  919.   (goto-char texinfo-command-start))
  920.  
  921. ; various noops
  922.  
  923. (put 'asis 'texinfo-format 'texinfo-format-noop)
  924. (put 'b 'texinfo-format 'texinfo-format-noop)
  925. (put 't 'texinfo-format 'texinfo-format-noop)
  926. (put 'i 'texinfo-format 'texinfo-format-noop)
  927. (put 'r 'texinfo-format 'texinfo-format-noop)
  928. (put 'titlefont 'texinfo-format 'texinfo-format-noop)
  929. (put 'key 'texinfo-format 'texinfo-format-noop)
  930. (put 'w 'texinfo-format 'texinfo-format-noop)
  931. (defun texinfo-format-noop ()
  932.   (insert (texinfo-parse-arg-discard))
  933.   (goto-char texinfo-command-start))
  934.  
  935. (put 'code 'texinfo-format 'texinfo-format-code)
  936. (put 'samp 'texinfo-format 'texinfo-format-code)
  937. (put 'file 'texinfo-format 'texinfo-format-code)
  938. (put 'kbd 'texinfo-format 'texinfo-format-code)
  939. (put 'cite 'texinfo-format 'texinfo-format-code)
  940. (defun texinfo-format-code ()
  941.   (insert "`" (texinfo-parse-arg-discard) "'")
  942.   (goto-char texinfo-command-start))
  943.  
  944. (put 'emph 'texinfo-format 'texinfo-format-emph)
  945. (put 'strong 'texinfo-format 'texinfo-format-emph)
  946. (defun texinfo-format-emph ()
  947.   (insert "*" (texinfo-parse-arg-discard) "*")
  948.   (goto-char texinfo-command-start))
  949.  
  950. (put 'defn 'texinfo-format 'texinfo-format-defn)
  951. (put 'dfn 'texinfo-format 'texinfo-format-defn)
  952. (defun texinfo-format-defn ()
  953.   (insert "\"" (texinfo-parse-arg-discard) "\"")
  954.   (goto-char texinfo-command-start))
  955.  
  956. (put 'bullet 'texinfo-format 'texinfo-format-bullet)
  957. (defun texinfo-format-bullet ()
  958.   (texinfo-discard-command)
  959.   (insert "*"))
  960.  
  961. (put 'smallexample 'texinfo-format 'texinfo-format-example)
  962. (put 'smalllisp 'texinfo-format 'texinfo-format-example)
  963. (put 'example 'texinfo-format 'texinfo-format-example)
  964. (put 'quotation 'texinfo-format 'texinfo-format-example)
  965. (put 'lisp 'texinfo-format 'texinfo-format-example)
  966. (put 'display 'texinfo-format 'texinfo-format-example)
  967. (put 'format 'texinfo-format 'texinfo-format-example)
  968. (put 'flushleft 'texinfo-format 'texinfo-format-example)
  969. (defun texinfo-format-example ()
  970.   (texinfo-push-stack 'example nil)
  971.   (setq fill-column (- fill-column 5))
  972.   (texinfo-discard-line))
  973.  
  974. (put 'smallexample 'texinfo-end 'texinfo-end-example)
  975. (put 'example 'texinfo-end 'texinfo-end-example)
  976. (put 'quotation 'texinfo-end 'texinfo-end-example)
  977. (put 'lisp 'texinfo-end 'texinfo-end-example)
  978. (put 'display 'texinfo-end 'texinfo-end-example)
  979. (put 'format 'texinfo-end 'texinfo-end-example)
  980. (put 'flushleft 'texinfo-end 'texinfo-end-example)
  981. (defun texinfo-end-example ()
  982.   (setq fill-column (+ fill-column 5))
  983.   (texinfo-discard-command)
  984.   (let ((stacktop
  985.      (texinfo-pop-stack 'example)))
  986.     (texinfo-do-itemize (nth 1 stacktop))))
  987.  
  988. (put 'exdent 'texinfo-format 'texinfo-format-exdent)
  989. (defun texinfo-format-exdent ()
  990.   (texinfo-discard-command)
  991.   (delete-region (point)
  992.          (progn
  993.           (skip-chars-forward " ")
  994.           (point)))
  995.   (insert ?\b)
  996.   ;; Cancel out the deletion that texinfo-do-itemize
  997.   ;; is going to do at the end of this line.
  998.   (save-excursion
  999.     (end-of-line)
  1000.     (insert "\n     ")))
  1001.  
  1002.  
  1003. ;; @flushright  ...   @end flushright
  1004.  
  1005. ; The @flushright command right justifies every line but leaves the
  1006. ; left end ragged.
  1007.  
  1008. (put 'flushright 'texinfo-format 'texinfo-format-flushright)
  1009. (defun texinfo-format-flushright ()
  1010.   (texinfo-push-stack 'flushright nil)
  1011.   (texinfo-discard-line))
  1012.  
  1013. (put 'flushright 'texinfo-end 'texinfo-end-flushright)
  1014. (defun texinfo-end-flushright ()
  1015.   (texinfo-discard-command)
  1016.  
  1017.   (let ((stacktop
  1018.          (texinfo-pop-stack 'flushright)))
  1019.  
  1020.     (texinfo-do-flushright (nth 1 stacktop))))
  1021.  
  1022. (defun texinfo-do-flushright (from)
  1023.   (save-excursion
  1024.    (while (progn (forward-line -1)
  1025.                  (>= (point) from))
  1026.  
  1027.      (beginning-of-line)
  1028.      (insert
  1029.       (make-string
  1030.        (- fill-column
  1031.           (save-excursion
  1032.             (end-of-line)
  1033.             (current-column)))  
  1034.        ? )))))
  1035.  
  1036.  
  1037. (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
  1038. (defun texinfo-format-ctrl ()
  1039.   (let ((str (texinfo-parse-arg-discard)))
  1040.     (insert (logand 31 (aref str 0)))))
  1041.  
  1042. (put 'TeX 'texinfo-format 'texinfo-format-TeX)
  1043. (defun texinfo-format-TeX ()
  1044.   (texinfo-parse-arg-discard)
  1045.   (insert "TeX"))
  1046.  
  1047. (put 'copyright 'texinfo-format 'texinfo-format-copyright)
  1048. (defun texinfo-format-copyright ()
  1049.   (texinfo-parse-arg-discard)
  1050.   (insert "(C)"))
  1051.  
  1052. (put 'minus 'texinfo-format 'texinfo-format-minus)
  1053. (defun texinfo-format-minus ()
  1054.   (texinfo-parse-arg-discard)
  1055.   (insert "-"))
  1056.  
  1057. (put 'dots 'texinfo-format 'texinfo-format-dots)
  1058. (defun texinfo-format-dots ()
  1059.   (texinfo-parse-arg-discard)
  1060.   (insert "..."))
  1061.  
  1062. (put 'refill 'texinfo-format 'texinfo-format-refill)
  1063. (defun texinfo-format-refill ()
  1064.   (texinfo-discard-command)
  1065.   (fill-paragraph nil))
  1066.  
  1067.  
  1068. ;;; Index generation
  1069.  
  1070. (put 'vindex 'texinfo-format 'texinfo-format-vindex)
  1071. (defun texinfo-format-vindex ()
  1072.   (texinfo-index 'texinfo-vindex))
  1073.  
  1074. (put 'cindex 'texinfo-format 'texinfo-format-cindex)
  1075. (defun texinfo-format-cindex ()
  1076.   (texinfo-index 'texinfo-cindex))
  1077.  
  1078. (put 'findex 'texinfo-format 'texinfo-format-findex)
  1079. (defun texinfo-format-findex ()
  1080.   (texinfo-index 'texinfo-findex))
  1081.  
  1082. (put 'pindex 'texinfo-format 'texinfo-format-pindex)
  1083. (defun texinfo-format-pindex ()
  1084.   (texinfo-index 'texinfo-pindex))
  1085.  
  1086. (put 'tindex 'texinfo-format 'texinfo-format-tindex)
  1087. (defun texinfo-format-tindex ()
  1088.   (texinfo-index 'texinfo-tindex))
  1089.  
  1090. (put 'kindex 'texinfo-format 'texinfo-format-kindex)
  1091. (defun texinfo-format-kindex ()
  1092.   (texinfo-index 'texinfo-kindex))
  1093.  
  1094. (defun texinfo-index (indexvar)
  1095.   (let ((arg (texinfo-parse-expanded-arg)))
  1096.     (texinfo-discard-command)
  1097.     (set indexvar
  1098.      (cons (list arg texinfo-last-node)
  1099.            (symbol-value indexvar)))))
  1100.  
  1101. (defconst texinfo-indexvar-alist
  1102.   '(("cp" . texinfo-cindex)
  1103.     ("fn" . texinfo-findex)
  1104.     ("vr" . texinfo-vindex)
  1105.     ("tp" . texinfo-tindex)
  1106.     ("pg" . texinfo-pindex)
  1107.     ("ky" . texinfo-kindex)))
  1108.  
  1109.  
  1110. ;;; @defindex   @defcodeindex
  1111. (put 'defindex 'texinfo-format 'texinfo-format-defindex)
  1112. (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
  1113.  
  1114. (defun texinfo-format-defindex ()
  1115.   (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
  1116.          (indexing-command (intern (concat index-name "index")))
  1117.          (index-formatting-command      ; eg: `texinfo-format-aaindex'
  1118.           (intern (concat "texinfo-format-" index-name "index")))
  1119.          (index-alist-name              ; eg: `texinfo-aaindex'
  1120.           (intern (concat "texinfo-" index-name "index"))))
  1121.  
  1122.     (set index-alist-name nil)
  1123.  
  1124.     (put indexing-command               ; eg, aaindex
  1125.          'texinfo-format
  1126.          index-formatting-command)      ; eg, texinfo-format-aaindex
  1127.  
  1128.     ;; eg: "aa" . texinfo-aaindex
  1129.     (or (assoc index-name texinfo-indexvar-alist)
  1130.         (setq texinfo-indexvar-alist
  1131.               (cons
  1132.                (cons index-name
  1133.                      index-alist-name)
  1134.                texinfo-indexvar-alist)))
  1135.  
  1136.     (fset index-formatting-command
  1137.           (list 'lambda 'nil
  1138.                 (list 'texinfo-index 
  1139.                       (list 'quote index-alist-name))))))
  1140.  
  1141.  
  1142. ;;; @synindex   @syncodeindex
  1143.  
  1144. (put 'synindex 'texinfo-format 'texinfo-format-synindex)
  1145. (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
  1146.  
  1147. (defun texinfo-format-synindex ()
  1148.   (let* ((args (texinfo-parse-arg-discard))
  1149.          (second (cdr (read-from-string args)))
  1150.          (joiner (symbol-name (car (read-from-string args))))
  1151.          (joined (symbol-name (car (read-from-string args second)))))
  1152.  
  1153.     (if (assoc joiner texinfo-short-index-cmds-alist)
  1154.         (put
  1155.           (cdr (assoc joiner texinfo-short-index-cmds-alist))
  1156.          'texinfo-format
  1157.          (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
  1158.              (intern (concat "texinfo-format-" joined "index"))))
  1159.       (put
  1160.        (intern (concat joiner "index"))
  1161.        'texinfo-format
  1162.        (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
  1163.            (intern (concat "texinfo-format-" joined "index")))))))
  1164.  
  1165. (defconst texinfo-short-index-cmds-alist
  1166.   '(("cp" . cindex)
  1167.     ("fn" . findex)
  1168.     ("vr" . vindex)
  1169.     ("tp" . tindex)
  1170.     ("pg" . pindex)
  1171.     ("ky" . kindex)))
  1172.  
  1173. (defconst texinfo-short-index-format-cmds-alist
  1174.   '(("cp" . texinfo-format-cindex)
  1175.     ("fn" . texinfo-format-findex)
  1176.     ("vr" . texinfo-format-vindex)
  1177.     ("tp" . texinfo-format-tindex)
  1178.     ("pg" . texinfo-format-pindex)
  1179.     ("ky" . texinfo-format-kindex)))
  1180.  
  1181.  
  1182. ;;; @printindex
  1183.  
  1184. (put 'printindex 'texinfo-format 'texinfo-format-printindex)
  1185.  
  1186. (defun texinfo-format-printindex ()
  1187.   (let ((indexelts (symbol-value
  1188.             (cdr (assoc (texinfo-parse-arg-discard)
  1189.                 texinfo-indexvar-alist))))
  1190.     opoint)
  1191.     (insert "\n* Menu:\n\n")
  1192.     (setq opoint (point))
  1193.     (texinfo-print-index nil indexelts)
  1194.  
  1195.     (if (eq system-type 'vax-vms)
  1196.         (texinfo-sort-region opoint (point))
  1197.       (shell-command-on-region opoint (point) "sort -fd" 1))))
  1198.  
  1199. (defun texinfo-print-index (file indexelts)
  1200.   (while indexelts
  1201.     (if (stringp (car (car indexelts)))
  1202.     (insert "* " (car (car indexelts))
  1203.         ": " (if file (concat "(" file ")") "")
  1204.         (nth 1 (car indexelts)) ".\n")
  1205.       ;; index entries from @include'd file
  1206.       (texinfo-print-index (nth 1 (car indexelts))
  1207.                (nth 2 (car indexelts))))
  1208.     (setq indexelts (cdr indexelts))))
  1209.  
  1210.  
  1211. ;;; NOTATIONS: @equiv, @error, etc
  1212.  
  1213. ;; @equiv           to show that two expressions are equivalent
  1214. ;; @error           to show an error message
  1215. ;; @expansion       to show what a macro expands to
  1216. ;; @point           to show the location of point in an example
  1217. ;; @print           to show what an evaluated expression prints
  1218. ;; @result          to indicate the value returned by an expression
  1219.  
  1220. (put 'equiv 'texinfo-format 'texinfo-format-equiv)
  1221. (defun texinfo-format-equiv ()
  1222.   (texinfo-parse-arg-discard)
  1223.   (insert "=="))
  1224.  
  1225. (put 'error 'texinfo-format 'texinfo-format-error)
  1226. (defun texinfo-format-error ()
  1227.   (texinfo-parse-arg-discard)
  1228.   (insert "error-->"))
  1229.  
  1230. (put 'expansion 'texinfo-format 'texinfo-format-expansion)
  1231. (defun texinfo-format-expansion ()
  1232.   (texinfo-parse-arg-discard)
  1233.   (insert "==>"))
  1234.  
  1235. (put 'point 'texinfo-format 'texinfo-format-point)
  1236. (defun texinfo-format-point ()
  1237.   (texinfo-parse-arg-discard)
  1238.   (insert "-!-"))
  1239.  
  1240. (put 'print 'texinfo-format 'texinfo-format-print)
  1241. (defun texinfo-format-print ()
  1242.   (texinfo-parse-arg-discard)
  1243.   (insert "-|"))
  1244.  
  1245. (put 'result 'texinfo-format 'texinfo-format-result)
  1246. (defun texinfo-format-result ()
  1247.   (texinfo-parse-arg-discard)
  1248.   (insert "=>"))
  1249.  
  1250.  
  1251. ;;;; Description formatting: @deffn, @defun, etc
  1252.  
  1253. (defun texinfo-format-defun ()
  1254.   (texinfo-push-stack 'defun nil)
  1255.   (setq fill-column (- fill-column 5))
  1256.   (texinfo-format-defun-1 t))
  1257.  
  1258. (defun texinfo-format-defunx ()
  1259.   (texinfo-format-defun-1 nil))
  1260.  
  1261. (defun texinfo-format-defun-1 (first-p)
  1262.   (let ((args (texinfo-format-parse-defun-args))
  1263.     (type (get texinfo-command-name 'texinfo-defun-type))
  1264.         (class "")
  1265.         (name ""))
  1266.     (texinfo-discard-command)
  1267.  
  1268.     (cond 
  1269.      ;; Generalized object oriented entity: `category class name [args...]'
  1270.      ((eq (eval (car type)) 'defop-type)
  1271.       (progn (setq category (car args))
  1272.              (setq class (car (cdr args)))
  1273.              (setq args (cdr (cdr args)))
  1274.              (setq name (car args))))
  1275.  
  1276.      ;; Specialized object oriented entity:  @defmethod, @defivar
  1277.      ;; "Instance Variable"    `class name [args...]'
  1278.      ((eq  (eval (car type)) 'defmethod-type)
  1279.       (progn (setq category (car (cdr type)))
  1280.              (setq class (car args))
  1281.              (setq args (cdr args))
  1282.              (setq name (car args))))
  1283.      
  1284.      ;; Generalized function-like or variable-like entity:
  1285.      ;; `category name [args...]'
  1286.      ((or (eq (eval (car type)) 'deffn-type)
  1287.           (eq (eval (car type)) 'deftp-type))
  1288.       (progn (setq category (car args))
  1289.              (setq args (cdr args))
  1290.              (setq name (car args))))
  1291.      
  1292.      ;; Specialized function-like or variable-like entity:
  1293.      ;; "Macro"    `name [args...]'
  1294.      ((eq (eval (car type)) 'defun-type)
  1295.       (progn (setq category (car (cdr type)))
  1296.              (setq name (car args)))))
  1297.  
  1298.     (let ((formatter (get texinfo-command-name 'texinfo-defun-format-type)))
  1299.       (if formatter
  1300.       (setq category (funcall formatter category class))))
  1301.  
  1302.     ;; Delete extra newline inserted after previous header line.
  1303.     (if (not first-p)
  1304.     (delete-char -1))
  1305.     (insert "* " category ": " name)
  1306.     (let ((args (cdr args)))
  1307.       (while args
  1308.     (insert " "
  1309.         (if (or (= ?& (aref (car args) 0))
  1310.                         (eq (eval (car type)) 'deftp-type))
  1311.             (car args)
  1312.             (upcase (car args))))
  1313.     (setq args (cdr args))))
  1314.     ;; Insert extra newline so that paragraph filling does not mess
  1315.     ;; with header line.
  1316.     (insert "\n\n")
  1317.     (rplaca (cdr (cdr (car texinfo-stack))) (point))
  1318.     (let ((indexvar (get texinfo-command-name 'texinfo-defun-index))
  1319.       (formatter (get texinfo-command-name 'texinfo-defun-format-index)))
  1320.       (set indexvar
  1321.        (cons (list (if formatter
  1322.                            (funcall formatter name class)
  1323.                          (car args))
  1324.                texinfo-last-node)
  1325.          (symbol-value indexvar))))))
  1326.  
  1327. (defun texinfo-end-defun ()
  1328.   (setq fill-column (+ fill-column 5))
  1329.   (texinfo-discard-command)
  1330.   (let ((start (nth 1 (texinfo-pop-stack 'defun))))
  1331.     (texinfo-do-itemize start)
  1332.     ;; Delete extra newline inserted after header.
  1333.     (save-excursion
  1334.       (goto-char start)
  1335.       (delete-char -1))))
  1336.  
  1337. (defun texinfo-format-defop-type (category class)
  1338.   (format "%s on %s" category class))
  1339.  
  1340. (defun texinfo-format-defop-index (name class)
  1341.   (format "%s on %s" name class))
  1342.  
  1343. (defun texinfo-format-defcv-type (category class)
  1344.   (format "%s of %s" category class))
  1345.  
  1346. (defun texinfo-format-defcv-index (name class)
  1347.   (format "%s of %s" name class))
  1348.  
  1349. (put 'deffn 'texinfo-format 'texinfo-format-defun)
  1350. (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
  1351. (put 'deffn 'texinfo-end 'texinfo-end-defun)
  1352. (put 'deffn 'texinfo-defun-type '('deffn-type nil))
  1353. (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
  1354. (put 'deffn 'texinfo-defun-index 'texinfo-findex)
  1355. (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
  1356.  
  1357. (put 'defun 'texinfo-format 'texinfo-format-defun)
  1358. (put 'defunx 'texinfo-format 'texinfo-format-defunx)
  1359. (put 'defun 'texinfo-end 'texinfo-end-defun)
  1360. (put 'defun 'texinfo-defun-type '('defun-type "Function"))
  1361. (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
  1362. (put 'defun 'texinfo-defun-index 'texinfo-findex)
  1363. (put 'defunx 'texinfo-defun-index 'texinfo-findex)
  1364.  
  1365. (put 'defmac 'texinfo-format 'texinfo-format-defun)
  1366. (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
  1367. (put 'defmac 'texinfo-end 'texinfo-end-defun)
  1368. (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
  1369. (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
  1370. (put 'defmac 'texinfo-defun-index 'texinfo-findex)
  1371. (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
  1372.  
  1373. (put 'defspec 'texinfo-format 'texinfo-format-defun)
  1374. (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
  1375. (put 'defspec 'texinfo-end 'texinfo-end-defun)
  1376. (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
  1377. (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
  1378. (put 'defspec 'texinfo-defun-index 'texinfo-findex)
  1379. (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
  1380.  
  1381. (put 'defvr 'texinfo-format 'texinfo-format-defun)
  1382. (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
  1383. (put 'defvr 'texinfo-end 'texinfo-end-defun)
  1384. (put 'defvr 'texinfo-defun-type '('deffn-type nil))
  1385. (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
  1386. (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
  1387. (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
  1388.  
  1389. (put 'defvar 'texinfo-format 'texinfo-format-defun)
  1390. (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
  1391. (put 'defvar 'texinfo-end 'texinfo-end-defun)
  1392. (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
  1393. (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
  1394. (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
  1395. (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
  1396.  
  1397. (put 'defconst 'texinfo-format 'texinfo-format-defun)
  1398. (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
  1399. (put 'defconst 'texinfo-end 'texinfo-end-defun)
  1400. (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
  1401. (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
  1402. (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
  1403. (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
  1404.  
  1405. (put 'defcmd 'texinfo-format 'texinfo-format-defun)
  1406. (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
  1407. (put 'defcmd 'texinfo-end 'texinfo-end-defun)
  1408. (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
  1409. (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
  1410. (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
  1411. (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
  1412.  
  1413. (put 'defopt 'texinfo-format 'texinfo-format-defun)
  1414. (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
  1415. (put 'defopt 'texinfo-end 'texinfo-end-defun)
  1416. (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
  1417. (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
  1418. (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
  1419. (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
  1420.  
  1421. (put 'deftp 'texinfo-format 'texinfo-format-defun)
  1422. (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
  1423. (put 'deftp 'texinfo-end 'texinfo-end-defun)
  1424. (put 'deftp 'texinfo-defun-type '('deftp-type nil))
  1425. (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
  1426. (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
  1427. (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
  1428.  
  1429. ;;; Object-oriented stuff is a little hairier.
  1430.  
  1431. (put 'defop 'texinfo-format 'texinfo-format-defun)
  1432. (put 'defopx 'texinfo-format 'texinfo-format-defunx)
  1433. (put 'defop 'texinfo-end 'texinfo-end-defun)
  1434. (put 'defop 'texinfo-defun-type '('defop-type nil))
  1435. (put 'defopx 'texinfo-defun-type '('defop-type nil))
  1436. (put 'defop 'texinfo-defun-format-type 'texinfo-format-defop-type)
  1437. (put 'defopx 'texinfo-defun-format-type 'texinfo-format-defop-type)
  1438. (put 'defop 'texinfo-defun-index 'texinfo-findex)
  1439. (put 'defopx 'texinfo-defun-index 'texinfo-findex)
  1440. (put 'defop 'texinfo-defun-format-index 'texinfo-format-defop-index)
  1441. (put 'defopx 'texinfo-defun-format-index 'texinfo-format-defop-index)
  1442.  
  1443. (put 'defmethod 'texinfo-format 'texinfo-format-defun)
  1444. (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
  1445. (put 'defmethod 'texinfo-end 'texinfo-end-defun)
  1446. (put 'defmethod 'texinfo-defun-type '('defmethod-type "Operation"))
  1447. (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Operation"))
  1448. (put 'defmethod 'texinfo-defun-format-type 'texinfo-format-defop-type)
  1449. (put 'defmethodx 'texinfo-defun-format-type 'texinfo-format-defop-type)
  1450. (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
  1451. (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
  1452. (put 'defmethod 'texinfo-defun-format-index 'texinfo-format-defop-index)
  1453. (put 'defmethodx 'texinfo-defun-format-index 'texinfo-format-defop-index)
  1454.  
  1455. (put 'defcv 'texinfo-format 'texinfo-format-defun)
  1456. (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
  1457. (put 'defcv 'texinfo-end 'texinfo-end-defun)
  1458. (put 'defcv 'texinfo-defun-type '('defop-type nil))
  1459. (put 'defcvx 'texinfo-defun-type '('defop-type nil))
  1460. (put 'defcv 'texinfo-defun-format-type 'texinfo-format-defcv-type)
  1461. (put 'defcvx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
  1462. (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
  1463. (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
  1464. (put 'defcv 'texinfo-defun-format-index 'texinfo-format-defcv-index)
  1465. (put 'defcvx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
  1466.  
  1467. (put 'defivar 'texinfo-format 'texinfo-format-defun)
  1468. (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
  1469. (put 'defivar 'texinfo-end 'texinfo-end-defun)
  1470. (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
  1471. (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
  1472. (put 'defivar 'texinfo-defun-format-type 'texinfo-format-defcv-type)
  1473. (put 'defivarx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
  1474. (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
  1475. (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
  1476. (put 'defivar 'texinfo-defun-format-index 'texinfo-format-defcv-index)
  1477. (put 'defivarx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
  1478.  
  1479.  
  1480. ;; process included files
  1481. (put 'include 'texinfo-format 'texinfo-format-include)
  1482. (defun texinfo-format-include ()
  1483.   (let ((filename (texinfo-parse-arg-discard))
  1484.     (default-directory input-directory)
  1485.     subindex)
  1486.     (setq subindex
  1487.       (save-excursion
  1488.         (progn (find-file
  1489.             (cond ((file-readable-p (concat filename ".texinfo"))
  1490.                (concat filename ".texinfo"))
  1491.               ((file-readable-p (concat filename ".texi"))
  1492.                (concat filename ".texi"))
  1493.               ((file-readable-p (concat filename ".tex"))
  1494.                (concat filename ".tex"))
  1495.               ((file-readable-p filename)
  1496.                filename)
  1497.               (t (error "@include'd file %s not found"
  1498.                     filename))))
  1499.            (texinfo-format-buffer-1))))
  1500.     (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
  1501.     (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
  1502.     (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
  1503.     (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
  1504.     (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
  1505.     (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
  1506.  
  1507. (defun texinfo-subindex (indexvar file content)
  1508.   (set indexvar (cons (list 'recurse file content)
  1509.               (symbol-value indexvar))))
  1510.  
  1511.  
  1512. ;; Lots of bolio constructs do nothing in texinfo.
  1513.  
  1514. (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
  1515. (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
  1516. (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
  1517. (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
  1518. (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
  1519. (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
  1520. (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
  1521. (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
  1522. (put 'noindent 'texinfo-format 'texinfo-discard-line-with-args)
  1523. (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
  1524. (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
  1525. (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
  1526. (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
  1527. (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
  1528. (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
  1529. (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
  1530. (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
  1531. (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
  1532. (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
  1533. (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
  1534. (put 'bye 'texinfo-format 'texinfo-discard-line)
  1535. (put 'smallbook 'texinfo-format 'texinfo-discard-line)
  1536.  
  1537. (defun texinfo-discard-line-with-args ()
  1538.   (goto-char texinfo-command-start)
  1539.   (delete-region (point) (progn (forward-line 1) (point))))
  1540.  
  1541. ;; Sort an index which is in the current buffer between START and END.
  1542. ;; Used on VMS, where the `sort' utility is not available.
  1543. (defun texinfo-sort-region (start end)
  1544.   (require 'sort)
  1545.   (save-restriction
  1546.     (narrow-to-region start end)
  1547.     (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
  1548.  
  1549. ;; Subroutine for sorting an index.
  1550. ;; At start of a line, return a string to sort the line under.
  1551. (defun texinfo-sort-startkeyfun ()
  1552.   (let ((line
  1553.      (buffer-substring (point) (save-excursion (end-of-line) (point)))))
  1554.     ;; Canonicalize whitespace and eliminate funny chars.
  1555.     (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
  1556.       (setq line (concat (substring line 0 (match-beginning 0))
  1557.              " "
  1558.              (substring line (match-end 0) (length line)))))
  1559.     line))
  1560.  
  1561. ;; Some cannot be handled
  1562.  
  1563. (defun texinfo-unsupported ()
  1564.   (error "%s is not handled by texinfo"
  1565.      (buffer-substring texinfo-command-start texinfo-command-end)))
  1566.  
  1567. (defun batch-texinfo-format ()
  1568.   "Runs  texinfo-format-buffer  on the files remaining on the command line.
  1569. Must be used only with -batch, and kills emacs on completion.
  1570. Each file will be processed even if an error occurred previously.
  1571. For example, invoke
  1572.   \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
  1573.   (if (not noninteractive)
  1574.       (error "batch-texinfo-format may only be used -batch."))
  1575.   (let ((version-control t)
  1576.     (auto-save-default nil)
  1577.     (find-file-run-dired nil)
  1578.     (kept-old-versions 259259)
  1579.     (kept-new-versions 259259))
  1580.     (let ((error 0)
  1581.       file
  1582.       (files ()))
  1583.       (while command-line-args-left
  1584.     (setq file (expand-file-name (car command-line-args-left)))
  1585.     (cond ((not (file-exists-p file))
  1586.            (message ">> %s does not exist!" file)
  1587.            (setq error 1
  1588.              command-line-args-left (cdr command-line-args-left)))
  1589.           ((file-directory-p file)
  1590.            (setq command-line-args-left
  1591.              (nconc (directory-files file)
  1592.                 (cdr command-line-args-left))))
  1593.           (t
  1594.            (setq files (cons file files)
  1595.              command-line-args-left (cdr command-line-args-left)))))
  1596.       (while files
  1597.     (setq file (car files)
  1598.           files (cdr files))
  1599.     (condition-case err
  1600.         (progn
  1601.           (if buffer-file-name (kill-buffer (current-buffer)))
  1602.           (find-file file)
  1603.           (buffer-disable-undo (current-buffer))
  1604.           (set-buffer-modified-p nil)
  1605.           (texinfo-mode)
  1606.           (message "texinfo formatting %s..." file)
  1607.           (texinfo-format-buffer nil)
  1608.           (if (buffer-modified-p)
  1609.           (progn (message "Saving modified %s" (buffer-file-name))
  1610.              (save-buffer))))
  1611.       (error
  1612.        (message ">> Error: %s" (prin1-to-string err))
  1613.        (message ">>  point at")
  1614.        (let ((s (buffer-substring (point)
  1615.                       (min (+ (point) 100)
  1616.                        (point-max))))
  1617.          (tem 0))
  1618.          (while (setq tem (string-match "\n+" s tem))
  1619.            (setq s (concat (substring s 0 (match-beginning 0))
  1620.                    "\n>>  "
  1621.                    (substring s (match-end 0)))
  1622.              tem (1+ tem)))
  1623.          (message ">>  %s" s))
  1624.        (setq error 1))))
  1625.       (kill-emacs error))))
  1626.