home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / tinfo210.lzh / TINFO210 / ELISP / TEXINFMT.EL < prev    next >
Lisp/Scheme  |  1991-09-19  |  91KB  |  2,532 lines

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