3425b27df16fc404537b600cb91e18ba64cff372
[gnus] / texi / infohack.el
1 ;;; infohack.el --- a hack to format info file.
2 ;; Copyright (C)  2001  Free Software Foundation, Inc.
3
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: info
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'texinfmt)
29
30 (defun infohack-remove-unsupported ()
31   (goto-char (point-min))
32   (while (re-search-forward "@\\(end \\)?ifnottex" nil t) 
33     (replace-match ""))
34   (goto-char (point-min))
35   (while (search-forward "\n@iflatex\n" nil t)
36     (delete-region (1+ (match-beginning 0))
37                    (search-forward "\n@end iflatex\n"))))
38
39 (defun infohack (file)
40   (let ((dest-directory default-directory)
41         (max-lisp-eval-depth (max max-lisp-eval-depth 600))
42         coding-system)
43     ;; Emacs 21.3 doesn't support @documentencoding
44     (unless (get 'documentencoding 'texinfo-format)
45       (put 'documentencoding 'texinfo-format 
46            'texinfo-discard-line-with-args))
47     (find-file file)
48     (setq buffer-read-only nil)
49     (setq coding-system buffer-file-coding-system)
50     (infohack-remove-unsupported)
51     (texinfo-every-node-update) 
52     (texinfo-format-buffer t) ;; Don't save any file.
53     (setq default-directory dest-directory)
54     (setq buffer-file-name 
55           (expand-file-name (file-name-nondirectory buffer-file-name)
56                             default-directory))
57     (setq buffer-file-coding-system coding-system)
58     (if (> (buffer-size) 100000)
59         (Info-split))
60     (save-buffer)))
61
62 (eval-and-compile
63   (when (string-match "windows-nt\\|os/2\\|emx\\|cygwin"
64                       (symbol-name system-type))
65     (defun subst-char-in-region (START END FROMCHAR TOCHAR &optional NOUNDO)
66       "From START to END, replace FROMCHAR with TOCHAR each time it occurs.
67 If optional arg NOUNDO is non-nil, don't record this change for undo
68 and don't mark the buffer as really changed.
69 Both characters must have the same length of multi-byte form."
70       (let ((original-buffer-undo-list buffer-undo-list)
71             (modified (buffer-modified-p)))
72         (if NOUNDO
73             (setq buffer-undo-list t))
74         (goto-char START)
75         (let ((from (char-to-string FROMCHAR))
76               (to (char-to-string TOCHAR)))
77           (while (search-forward from END t)
78             (replace-match to t t)))
79         (if NOUNDO
80             (progn (setq buffer-undo-list original-buffer-undo-list)
81                    (set-buffer-modidifed-p modified)))))))
82
83 (defun batch-makeinfo ()
84   "Emacs makeinfo in batch mode."
85   (infohack (car command-line-args-left))
86   (setq command-line-args-left nil))
87
88 ;;; infohack.el ends here