* infohack.el (infohack-texi-format): Insert one excessive newline after a
[elisp/gnus.git-] / texi / infohack.el
index c869d94..1cf6e8d 100644 (file)
 
 (defun infohack-remove-unsupported ()
   (goto-char (point-min))
-  (while (re-search-forward "@\\(end \\)?ifnottex" nil t) 
-    (replace-match "")))
+  (while (re-search-forward "@\\(end \\)?ifnottex" nil t)
+    (replace-match ""))
+  (goto-char (point-min))
+  (while (search-forward "\n@iflatex\n" nil t)
+    (delete-region (1+ (match-beginning 0))
+                  (search-forward "\n@end iflatex\n"))))
 
 (defun infohack (file)
-  (let ((dest-directory default-directory))
+  (let ((dest-directory default-directory)
+       (max-lisp-eval-depth (max max-lisp-eval-depth 600))
+       coding-system)
     (find-file file)
+    (setq buffer-read-only nil)
+    (setq coding-system (if (boundp 'buffer-file-coding-system)
+                           buffer-file-coding-system
+                         file-coding-system))
     (infohack-remove-unsupported)
-    (texinfo-every-node-update) 
+    (texinfo-every-node-update)
     (texinfo-format-buffer t) ;; Don't save any file.
     (setq default-directory dest-directory)
-    (setq buffer-file-name 
+    (setq buffer-file-name
          (expand-file-name (file-name-nondirectory buffer-file-name)
                            default-directory))
+    (setq buffer-file-coding-system coding-system
+         file-coding-system coding-system)
     (if (> (buffer-size) 100000)
        (Info-split))
     (save-buffer)))
 
+(defun batch-makeinfo ()
+  "Emacs makeinfo in batch mode."
+  (infohack-texi-format (car command-line-args-left)
+                       (car (cdr command-line-args-left)))
+  (setq command-line-args-left nil))
+
 \f
 (let ((default-directory (expand-file-name "../lisp/"))
       (features (cons 'w3-forms (copy-sequence features))))
@@ -62,6 +80,7 @@
     (condition-case err
        (progn
          (find-file file)
+         (setq buffer-read-only nil)
          (buffer-disable-undo (current-buffer))
          (if (boundp 'MULE)
              (setq output-coding-system file-coding-system)
                          (delete-region (point) (save-excursion
                                                   (forward-line 1)
                                                   (point))))))))))
+         ;; Insert one excessive newline after a @foo{bar} thing to
+         ;; prevent clinging of a line and a line (old texinfmt bug?)
+         ;; if it should be considered only one thing in a line.
+         (goto-char (point-min))
+         (while (re-search-forward "^[\t ]*@[a-z]+{.+}[\t ]*\n[\t ]*\n"
+                                   nil t)
+           (if (not (looking-at "[\t ]*$\\|[\t ]*@[a-z]+[\t\n ]"))
+               (insert "\n")))
          (texinfo-mode)
          (texinfo-every-node-update)
          (set-buffer-modified-p nil)