1 ;;; infohack.el --- a hack to format info file.
2 ;; Copyright (C) 2001 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
28 (let ((default-directory (expand-file-name "../lisp/"))
29 (features (cons 'w3-forms (copy-sequence features))))
30 ;; Adjust `load-path' for APEL.
31 (load-file "dgnushack.el"))
32 (load-file (expand-file-name "ptexinfmt.el" "./"))
34 (defun infohack-remove-unsupported ()
35 (goto-char (point-min))
36 (while (re-search-forward "@\\(end \\)?ifnottex" nil t)
38 (goto-char (point-min))
39 (while (search-forward "\n@iflatex\n" nil t)
40 (delete-region (1+ (match-beginning 0))
41 (search-forward "\n@end iflatex\n"))))
43 (defun infohack (file)
44 (let ((dest-directory default-directory)
45 (max-lisp-eval-depth (max max-lisp-eval-depth 600))
48 (setq buffer-read-only nil)
49 (setq coding-system (if (boundp 'buffer-file-coding-system)
50 buffer-file-coding-system
52 (infohack-remove-unsupported)
53 (texinfo-every-node-update)
54 (texinfo-format-buffer t) ;; Don't save any file.
55 (setq default-directory dest-directory)
56 (setq buffer-file-name
57 (expand-file-name (file-name-nondirectory buffer-file-name)
59 (setq buffer-file-coding-system coding-system
60 file-coding-system coding-system)
61 (if (> (buffer-size) 100000)
66 (when (string-match "windows-nt\\|os/2\\|emx\\|cygwin"
67 (symbol-name system-type))
68 (defun subst-char-in-region (START END FROMCHAR TOCHAR &optional NOUNDO)
69 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.
70 If optional arg NOUNDO is non-nil, don't record this change for undo
71 and don't mark the buffer as really changed.
72 Both characters must have the same length of multi-byte form."
73 (let ((original-buffer-undo-list buffer-undo-list)
74 (modified (buffer-modified-p)))
76 (setq buffer-undo-list t))
78 (let ((from (char-to-string FROMCHAR))
79 (to (char-to-string TOCHAR)))
80 (while (search-forward from END t)
81 (replace-match to t t)))
83 (progn (setq buffer-undo-list original-buffer-undo-list)
84 (set-buffer-modidifed-p modified)))))))
86 (defun batch-makeinfo ()
87 "Emacs makeinfo in batch mode."
88 (infohack-texi-format (car command-line-args-left)
89 (car (cdr command-line-args-left)))
90 (setq command-line-args-left nil))
93 (defun infohack-texi-format (file &optional addsuffix)
94 (let ((auto-save-default nil)
95 (find-file-run-dired nil)
96 coding-system-for-write
102 (setq buffer-read-only nil)
103 (buffer-disable-undo (current-buffer))
105 (setq output-coding-system file-coding-system)
106 (setq coding-system-for-write buffer-file-coding-system))
107 ;; Remove ignored areas first.
108 (while (re-search-forward "^@ignore[\t\r ]*$" nil t)
109 (delete-region (match-beginning 0)
110 (if (re-search-forward
111 "^@end[\t ]+ignore[\t\r ]*$" nil t)
114 (infohack-remove-unsupported)
115 (goto-char (point-min))
116 ;; Add suffix if it is needed.
118 (re-search-forward "^@setfilename[\t ]+\\([^\t\n ]+\\)"
120 (not (string-match "\\.info$" (match-string 1))))
122 (goto-char (point-min)))
123 ;; process @include before updating node
124 ;; This might produce some problem if we use @lowersection or
126 (let ((input-directory default-directory)
127 (texinfo-command-end))
128 (while (re-search-forward "^@include" nil t)
129 (setq texinfo-command-end (point))
130 (let ((filename (concat input-directory
131 (texinfo-parse-line-arg))))
132 (re-search-backward "^@include")
133 (delete-region (point) (save-excursion
136 (message "Reading included file: %s" filename)
141 (car (cdr (insert-file-contents filename)))))
142 (goto-char (point-min))
143 ;; Remove `@setfilename' line from included file,
144 ;; if any, so @setfilename command not duplicated.
145 (if (re-search-forward "^@setfilename"
152 (delete-region (point) (save-excursion
156 (texinfo-every-node-update)
157 (set-buffer-modified-p nil)
158 (message "texinfo formatting %s..." file)
159 (texinfo-format-buffer nil)
160 (if (buffer-modified-p)
161 (progn (message "Saving modified %s" (buffer-file-name))
164 (message ">> Error: %s" (prin1-to-string err))
165 (message ">> point at")
166 (let ((s (buffer-substring (point) (min (+ (point) 100) (point-max))))
168 (while (setq tem (string-match "\n+" s tem))
169 (setq s (concat (substring s 0 (match-beginning 0))
171 (substring s (match-end 0)))
177 ;;; infohack.el ends here