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.
30 (defun infohack-remove-unsupported ()
31 (goto-char (point-min))
32 (while (re-search-forward "@\\(end \\)?ifnottex" nil t)
35 (defun infohack (file)
36 (let ((dest-directory default-directory)
37 (max-lisp-eval-depth (max max-lisp-eval-depth 600)))
39 (infohack-remove-unsupported)
40 (texinfo-every-node-update)
41 (texinfo-format-buffer t) ;; Don't save any file.
42 (setq default-directory dest-directory)
43 (setq buffer-file-name
44 (expand-file-name (file-name-nondirectory buffer-file-name)
46 (if (> (buffer-size) 100000)
50 (defun batch-makeinfo ()
51 "Emacs makeinfo in batch mode."
52 (infohack-texi-format (car command-line-args-left)
53 (car (cdr command-line-args-left)))
54 (setq command-line-args-left nil))
57 (let ((default-directory (expand-file-name "../lisp/"))
58 (features (cons 'w3-forms (copy-sequence features))))
59 ;; Adjust `load-path' for APEL.
60 (load-file "dgnushack.el"))
61 (load-file (expand-file-name "ptexinfmt.el" "./"))
63 (defun infohack-texi-format (file &optional addsuffix)
64 (let ((auto-save-default nil)
65 (find-file-run-dired nil)
66 coding-system-for-write
72 (buffer-disable-undo (current-buffer))
74 (setq output-coding-system file-coding-system)
75 (setq coding-system-for-write buffer-file-coding-system))
76 ;; Remove ignored areas first.
77 (while (re-search-forward "^@ignore[\t\r ]*$" nil t)
78 (delete-region (match-beginning 0)
79 (if (re-search-forward
80 "^@end[\t ]+ignore[\t\r ]*$" nil t)
83 (infohack-remove-unsupported)
84 (goto-char (point-min))
85 ;; Add suffix if it is needed.
87 (re-search-forward "^@setfilename[\t ]+\\([^\t\n ]+\\)"
89 (not (string-match "\\.info$" (match-string 1))))
91 (goto-char (point-min)))
92 ;; process @include before updating node
93 ;; This might produce some problem if we use @lowersection or
95 (let ((input-directory default-directory)
96 (texinfo-command-end))
97 (while (re-search-forward "^@include" nil t)
98 (setq texinfo-command-end (point))
99 (let ((filename (concat input-directory
100 (texinfo-parse-line-arg))))
101 (re-search-backward "^@include")
102 (delete-region (point) (save-excursion
105 (message "Reading included file: %s" filename)
110 (car (cdr (insert-file-contents filename)))))
111 (goto-char (point-min))
112 ;; Remove `@setfilename' line from included file,
113 ;; if any, so @setfilename command not duplicated.
114 (if (re-search-forward "^@setfilename"
121 (delete-region (point) (save-excursion
125 (texinfo-every-node-update)
126 (set-buffer-modified-p nil)
127 (message "texinfo formatting %s..." file)
128 (texinfo-format-buffer nil)
129 (if (buffer-modified-p)
130 (progn (message "Saving modified %s" (buffer-file-name))
133 (message ">> Error: %s" (prin1-to-string err))
134 (message ">> point at")
135 (let ((s (buffer-substring (point) (min (+ (point) 100) (point-max))))
137 (while (setq tem (string-match "\n+" s tem))
138 (setq s (concat (substring s 0 (match-beginning 0))
140 (substring s (match-end 0)))
146 ;;; infohack.el ends here