]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/texinfmt.el
(outline-up-heading): Avoid infinite loop at beginning of buffer.
[gnu-emacs] / lisp / textmodes / texinfmt.el
index df897e9b34028c5400aa7a09cc4673abf7852518..90e682f4705c7c31c894ad93e26c51943f9ea00c 100644 (file)
 
 ;;; Emacs lisp functions to convert Texinfo files to Info files.
 
+(or (fboundp 'defgroup)
+    (defmacro defgroup (&rest ignore) nil))
+
+(or (fboundp 'defcustom)
+    (defmacro defcustom (var value doc &rest ignore)
+      `(defvar ,var ,value ,doc)))
+
 (defvar texinfmt-version "2.37 of 24 May 1997")
 
 (defun texinfmt-version (&optional here)
@@ -357,11 +364,18 @@ Info-split to do these manually."
           (error "Texinfo file needs an `@setfilename FILENAME' line."))
       (setq texinfo-command-end (point))
       (setq outfile (texinfo-parse-line-arg)))
+
     (find-file outfile)
     (texinfo-mode)
+    (erase-buffer)
+
+    (message "Formatting Info file: %s" outfile)
+    (setq texinfo-format-filename
+          (file-name-nondirectory (expand-file-name outfile)))
+
     (setq fill-column fill-column-for-info)
     (set-syntax-table texinfo-format-syntax-table)
-    (erase-buffer)
+
     (insert-buffer-substring input-buffer)
     (message "Converting %s to Info format..." (buffer-name input-buffer))
     
@@ -410,8 +424,26 @@ Info-split to do these manually."
         (insert "\n"))
     ;; Scan the whole buffer, converting to Info format.
     (texinfo-format-scan)
-    ;; Return data for indices.
     (goto-char (point-min))
+    ;; Insert info about how this file was made.
+    (insert "Info file: "
+            texinfo-format-filename ",    -*-Text-*-\n"
+            "produced by `texinfo-format-buffer'\n"
+            ;; Date string removed so that regression testing is easier.
+            ;; "on "
+            ;; (insert (format-time-string "%e %b %Y")) " "
+            "from file"
+            (if (buffer-file-name input-buffer)
+                (concat " `"
+                        (file-name-sans-versions
+                         (file-name-nondirectory
+                          (buffer-file-name input-buffer)))
+                        "'")
+              (concat "buffer `" (buffer-name input-buffer) "'"))
+            "\nusing `texinfmt.el' version "
+            texinfmt-version
+            ".\n\n")
+    ;; Return data for indices.
     (list outfile
           texinfo-vindex texinfo-findex texinfo-cindex
           texinfo-pindex texinfo-tindex texinfo-kindex)))
@@ -442,6 +474,7 @@ Info-split to do these manually."
   (concat
    "^@"
    "\\("
+   "direntry\\|"
    "example\\|"
    "smallexample\\|"
    "lisp\\|"
@@ -1068,27 +1101,7 @@ Leave point after argument."
 ;; specially. 
 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
 (defun texinfo-format-setfilename ()
-  (let ((arg (texinfo-parse-arg-discard)))
-    (message "Formatting Info file: %s" arg)
-    (setq texinfo-format-filename
-          (file-name-nondirectory (expand-file-name arg)))
-    (insert "Info file: "
-            texinfo-format-filename ",    -*-Text-*-\n"
-            "produced by `texinfo-format-buffer'\n"
-            ;; Date string removed so that regression testing is easier.
-            ;; "on "
-            ;; (insert (format-time-string "%e %b %Y")) " "
-            "from file"
-            (if (buffer-file-name input-buffer)
-                (concat " `"
-                        (file-name-sans-versions
-                         (file-name-nondirectory
-                          (buffer-file-name input-buffer)))
-                        "'")
-              (concat "buffer `" (buffer-name input-buffer) "'"))
-            "\nusing `texinfmt.el' version "
-            texinfmt-version
-            ".\n\n")))
+  (texinfo-parse-arg-discard))
 \f
 ;;; @node, @menu, @detailmenu
 
@@ -1737,7 +1750,7 @@ Used by @refill indenting command to avoid indenting within lists, etc.")
 ;;
 ;; Using the Emacs Lisp formatter, texinfmt.el, 
 ;; the whitespace between columns can be increased by setting
-;; `extra-inter-column-width' to a value greater than 0.  By default,
+;; `texinfo-extra-inter-column-width' to a value greater than 0.  By default,
 ;; there is at least one blank space between columns.
 ;;
 ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
@@ -1787,12 +1800,11 @@ Used by @refill indenting command to avoid indenting within lists, etc.")
 ;; Note that @tab, the cell separators, are not treated as independent
 ;; Texinfo commands.
 
-(defvar extra-inter-column-width 0
-"*Insert NUMBER of additional columns of whitespace between entries of
-a multi-column table.")
+(defvar texinfo-extra-inter-column-width 0
+  "*Number of extra spaces between entries (columns) in @multitable.")
 
-(defvar multitable-temp-buffer-name "*multitable-temporary-buffer*")
-(defvar multitable-temp-rectangle-name "texinfo-multitable-temp-")
+(defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
+(defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
 
 ;; These commands are defined in texinfo.tex for printed output.
 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
@@ -1801,6 +1813,7 @@ a multi-column table.")
 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
 
 (put 'multitable 'texinfo-format 'texinfo-multitable)
+
 (defun texinfo-multitable ()
   "Produce multi-column tables.
 
@@ -1829,7 +1842,7 @@ Long lines of text are filled within columns.
 
 Using the Emacs Lisp formatter, texinfmt.el, 
 the whitespace between columns can be increased by setting
-`extra-inter-column-width' to a value greater than 0.  By default,
+`texinfo-extra-inter-column-width' to a value greater than 0.  By default,
 there is at least one blank space between columns.
 
 The Emacs Lisp formatter, texinfmt.el, ignores the following four
@@ -1918,7 +1931,7 @@ commands that are defined in texinfo.tex for printed output.
             ;; between column spaces
             (length texinfo-multitable-width-list)
             ;; additional between column spaces, if any
-            extra-inter-column-width
+            texinfo-extra-inter-column-width
             ;; sum of spaces for each entry
             (apply '+ texinfo-multitable-width-list))))
       (if (> desired-columns fill-column)
@@ -1964,7 +1977,7 @@ This command is executed when texinfmt sees @item inside @multitable."
         ;; extract-row command deletes the source line in the table.
         (unformated-row (texinfo-multitable-extract-row)))
     ;; Use a temporary buffer
-    (set-buffer (get-buffer-create multitable-temp-buffer-name))
+    (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
     (delete-region (point-min) (point-max))
     (insert unformated-row)
     (goto-char (point-min))
@@ -1991,7 +2004,7 @@ This command is executed when texinfmt sees @item inside @multitable."
                   (point)))
       ;; Set fill-column *wider* than needed to produce inter-column space
       (setq fill-column (+ 1
-                           extra-inter-column-width
+                           texinfo-extra-inter-column-width
                            (nth table-column table-widths)))
       (narrow-to-region start end)
       ;; Remove whitespace before and after entry.
@@ -2023,7 +2036,7 @@ This command is executed when texinfmt sees @item inside @multitable."
                  (if (> needed-whitespace 0) needed-whitespace 1)
                  ? )))
       ;; now, put formatted cell into a rectangle
-      (set (intern (concat multitable-temp-rectangle-name
+      (set (intern (concat texinfo-multitable-rectangle-name
                            (int-to-string table-column)))
            (extract-rectangle (point-min) (point)))
       (delete-region (point-min) (point))
@@ -2046,12 +2059,12 @@ This command is executed when texinfmt sees @item inside @multitable."
         (setq here (point))
         (insert-rectangle
          (eval (intern
-                (concat multitable-temp-rectangle-name
+                (concat texinfo-multitable-rectangle-name
                         (int-to-string column-number)))))
         (goto-char here)
         (end-of-line)
         (setq column-number (1+ column-number))))
-    (kill-buffer multitable-temp-buffer-name)
+    (kill-buffer texinfo-multitable-buffer-name)
     (setq fill-column existing-fill-column)))
 
 \f
@@ -2251,8 +2264,9 @@ This command is executed when texinfmt sees @item inside @multitable."
 
 (put 'email 'texinfo-format 'texinfo-format-key)
 (put 'key 'texinfo-format 'texinfo-format-key)
+;; I've decided not want to have angle brackets around these -- rms.
 (defun texinfo-format-key ()
-  (insert "<" (texinfo-parse-arg-discard) ">")
+  (insert (texinfo-parse-arg-discard))
   (goto-char texinfo-command-start))
 
 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
@@ -2364,6 +2378,29 @@ If used within a line, follow `@bullet' with braces."
     (insert "\n     ")))
 
 \f
+;; @direntry and @dircategory
+
+(put 'direntry 'texinfo-format 'texinfo-format-direntry)
+(defun texinfo-format-direntry ()
+  (texinfo-push-stack 'direntry nil)
+  (texinfo-discard-line)
+  (insert "START-INFO-DIR-ENTRY\n\n"))
+
+(put 'direntry 'texinfo-end 'texinfo-end-direntry)
+(defun texinfo-end-direntry ()
+  (texinfo-discard-command)
+  (insert "END-INFO-DIR-ENTRY\n\n")
+  (texinfo-pop-stack 'direntry))
+
+(put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
+(defun texinfo-format-dircategory ()
+  (let ((str (texinfo-parse-arg-discard)))
+    (delete-region (point)
+                  (progn
+                    (skip-chars-forward " ")
+                    (point)))
+    (insert "INFO-DIR-SECTION " str "\n")))
+\f
 ;;; @cartouche 
 
 ;; The @cartouche command is a noop in Info; in a printed manual,
@@ -3739,13 +3776,12 @@ The command  `@value{foo}'  expands to the value."
       ;; In this case flag is neither set nor cleared.  
       ;; Act as if clear, i.e. do nothing.
       ()))))
-
 \f
 ;;; @ifeq
 
 (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
 (defun texinfo-format-ifeq ()
-  "If ARG1 and ARG2 caselessly string compare to same string, performs COMMAND.
+  "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
 Otherwise produces no output.
 
 Thus:
@@ -3935,7 +3971,6 @@ the @ifeq command."
 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
 (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
-(put 'dircategory 'texinfo-format 'texinfo-discard-line-with-args)
 
 \f
 ;;; Some commands cannot be handled