Add new maintainer (deego).
[bpt/emacs.git] / lisp / calc / calc-maint.el
CommitLineData
3132f345
CW
1;;; calc-maint.el --- maintenance routines for Calc
2
bf77c646 3;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
3132f345
CW
4
5;; Author: David Gillespie <daveg@synaptics.com>
6;; Maintainer: Colin Walters <walters@debian.org>
136211a9
EZ
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY. No author or distributor
12;; accepts responsibility to anyone for the consequences of using it
13;; or for whether it serves any particular purpose or works at all,
14;; unless he says so in writing. Refer to the GNU Emacs General Public
15;; License for full details.
16
17;; Everyone is granted permission to copy, modify and redistribute
18;; GNU Emacs, but only under the conditions described in the
19;; GNU Emacs General Public License. A copy of this license is
20;; supposed to have been given to you along with GNU Emacs so you
21;; can know your rights and responsibilities. It should be in a
22;; file named COPYING. Among other things, the copyright notice
23;; and this notice must be preserved on all copies.
24
3132f345 25;;; Commentary:
136211a9 26
3132f345 27;;; Code:
136211a9
EZ
28
29(defun calc-compile ()
30 "Compile all parts of Calc.
31Unix usage:
32 emacs -batch -l calc-maint -f calc-compile"
33 (interactive)
34 (if (equal (user-full-name) "David Gillespie")
35 (load "~/lisp/newbytecomp"))
36 (setq byte-compile-verbose t)
37 (if noninteractive
38 (let ((old-message (symbol-function 'message))
39 (old-write-region (symbol-function 'write-region))
40 (comp-was-func nil)
41 (comp-len 0))
42 (unwind-protect
43 (progn
44 (fset 'message (symbol-function 'calc-compile-message))
45 (fset 'write-region (symbol-function 'calc-compile-write-region))
46 (calc-do-compile))
47 (fset 'message old-message)
48 (fset 'write-region old-write-region)))
bf77c646 49 (calc-do-compile)))
136211a9
EZ
50
51(defun calc-do-compile ()
52 (let ((make-backup-files nil)
53 (changed-rules nil)
54 (changed-units nil)
55 (message-bug (string-match "^18.\\([0-4][0-9]\\|5[0-6]\\)"
56 emacs-version)))
57 (setq max-lisp-eval-depth (max 400 max-lisp-eval-depth))
58 ;; Enable some irrelevant warnings to avoid compiler bug in 19.29:
59 (setq byte-compile-warnings (and (string-match "^19.29" emacs-version)
60 '(obsolete)))
61
62 ;; Make sure we're in the right directory.
63 (find-file "calc.el")
64 (if (= (buffer-size) 0)
3132f345 65 (error "This command must be used in the Calc source directory"))
136211a9
EZ
66
67 ;; Make sure current directory is in load-path.
68 (setq load-path (cons default-directory load-path))
69 (load "calc-macs.el" nil t t)
70 (provide 'calc)
71 (provide 'calc-ext)
72
73 ;; Compile all the source files.
74 (let ((files (append
75 '("calc.el" "calc-ext.el")
76 (sort (directory-files
77 default-directory nil
78 "\\`calc-.[^x].*\\.el\\'")
79 'string<))))
80 (while files
81 (if (file-newer-than-file-p (car files) (concat (car files) "c"))
82 (progn
83 (if (string-match "calc-rules" (car files))
84 (setq changed-rules t))
85 (if (string-match "calc-units" (car files))
86 (setq changed-units t))
87 (or message-bug (message ""))
88 (byte-compile-file (car files)))
3132f345 89 (message "File %s is up to date" (car files)))
136211a9
EZ
90 (if (string-match "calc\\(-ext\\)?.el" (car files))
91 (load (concat (car files) "c") nil t t))
92 (setq files (cdr files))))
93
94 (if (or changed-units changed-rules)
95 (condition-case err
96 (progn
97
98 ;; Pre-build the units table.
99 (if (and changed-units
100 (not (string-match "Lucid" emacs-version)))
101 (progn
102 (or message-bug (message ""))
103 (save-excursion
104 (calc-create-buffer)
105 (math-build-units-table))
106 (find-file "calc-units.elc")
107 (goto-char (point-max))
108 (insert "\n(setq math-units-table '"
109 (prin1-to-string math-units-table)
110 ")\n")
111 (save-buffer)))
112
113 ;; Pre-build rewrite rules for j D, j M, etc.
114 (if (and changed-rules (not (string-match "^19" emacs-version)))
115 (let ((rules nil))
116 (or message-bug (message ""))
117 (find-file "calc-rules.elc")
118 (goto-char (point-min))
119 (while (re-search-forward "defun calc-\\([A-Za-z]*Rules\\)"
120 nil t)
121 (setq rules (cons (buffer-substring (match-beginning 1)
122 (match-end 1))
123 rules)))
124 (goto-char (point-min))
125 (re-search-forward "\n(defun calc-[A-Za-z]*Rules")
126 (beginning-of-line)
127 (delete-region (point) (point-max))
128 (mapcar (function
129 (lambda (v)
130 (let* ((vv (intern (concat "var-" v)))
131 (val (save-excursion
132 (calc-create-buffer)
133 (calc-var-value vv))))
134 (insert "\n(defun calc-" v " () '"
135 (prin1-to-string val) ")\n"))))
136 (sort rules 'string<))
137 (save-buffer))))
138 (error (message "Unable to pre-build tables %s" err))))
3132f345 139 (message "Done. Don't forget to install with \"make public\" or \"make private\"")))
136211a9
EZ
140
141(defun calc-compile-message (fmt &rest args)
142 (cond ((and (= (length args) 2)
143 (stringp (car args))
144 (string-match ".elc?\\'" (car args))
145 (symbolp (nth 1 args)))
146 (let ((name (symbol-name (nth 1 args))))
147 (princ (if comp-was-func ", " " "))
148 (if (and comp-was-func (eq (string-match comp-was-func name) 0))
149 (setq name (substring name (1- (length comp-was-func))))
150 (setq comp-was-func (if (string-match "\\`[a-zA-Z]+-" name)
151 (substring name 0 (match-end 0))
152 " ")))
153 (if (> (+ comp-len (length name)) 75)
154 (progn
155 (princ "\n ")
156 (setq comp-len 0)))
157 (princ name)
158 (send-string-to-terminal "") ; cause an fflush(stdout)
159 (setq comp-len (+ comp-len 2 (length name)))))
160 ((and (setq comp-was-func nil
161 comp-len 0)
162 (= (length args) 1)
163 (stringp (car args))
164 (string-match ".elc?\\'" (car args)))
3132f345
CW
165 (unless (string-match "Saving file %s..." fmt)
166 (funcall old-message fmt (file-name-nondirectory (car args)))))
136211a9
EZ
167 ((string-match "\\(Preparing\\|Building\\).*\\.\\.\\.$" fmt)
168 (send-string-to-terminal (apply 'format fmt args)))
169 ((string-match "\\(Preparing\\|Building\\).*\\.\\.\\. *done$" fmt)
170 (send-string-to-terminal "done\n"))
bf77c646 171 (t (apply old-message fmt args))))
136211a9
EZ
172
173(defun calc-compile-write-region (start end filename &optional append visit &rest rest)
174 (if (eq visit t)
175 (set-buffer-auto-saved))
176 (if (and (string-match "\\.elc" filename)
177 (= start (point-min))
178 (= end (point-max)))
179 (save-excursion
180 (goto-char (point-min))
181 (if (search-forward "\n(require (quote calc-macs))\n" nil t)
182 (replace-match ""))
183 (setq end (point-max))))
184 (apply old-write-region start end filename append 'quietly rest)
185 (message "Wrote %s" filename)
bf77c646 186 nil)
136211a9 187
136211a9
EZ
188(defun calc-split-tutorial (&optional force)
189 (interactive "P")
190 (calc-split-manual force 1))
191
136211a9
EZ
192(defun calc-split-reference (&optional force)
193 (interactive "P")
194 (calc-split-manual force 2))
195
136211a9
EZ
196(defun calc-split-manual (&optional force part)
197 "Split the Calc manual into separate Tutorial and Reference manuals.
198Use this if your TeX installation is too small-minded to handle
199calc.texinfo all at once.
200Usage: C-x C-f calc.texinfo RET
201 M-x calc-split-manual RET"
202 (interactive "P")
203 (or (let ((case-fold-search t))
418685d8 204 (string-match "calc\\.texi" (buffer-name)))
136211a9 205 force
418685d8 206 (error "This command should be used in the calc.texi buffer"))
136211a9
EZ
207 (let ((srcbuf (current-buffer))
208 tutpos refpos endpos (maxpos (point-max)))
209 (goto-char 1)
210 (search-forward "@c [tutorial]")
211 (beginning-of-line)
212 (setq tutpos (point))
213 (search-forward "@c [reference]")
214 (beginning-of-line)
215 (setq refpos (point))
216 (search-forward "@c [end]")
217 (beginning-of-line)
218 (setq endpos (point))
219 (or (eq part 2)
220 (progn
221 (find-file "calctut.tex")
222 (erase-buffer)
223 (insert-buffer-substring srcbuf 1 refpos)
224 (insert-buffer-substring srcbuf endpos maxpos)
225 (calc-split-volume "I" "ref" "Tutorial" "Reference")
226 (save-buffer)))
227 (or (eq part 1)
228 (progn
229 (find-file "calcref.tex")
230 (erase-buffer)
231 (insert-buffer-substring srcbuf 1 tutpos)
232 (insert "\n@tex\n\\global\\advance\\chapno by 1\n@end tex\n")
233 (insert-buffer-substring srcbuf refpos maxpos)
234 (calc-split-volume "II" "tut" "Reference" "Tutorial")
235 (save-buffer)))
236 (switch-to-buffer srcbuf)
237 (goto-char 1))
238 (message (cond ((eq part 1) "Wrote file calctut.tex")
239 ((eq part 2) "Wrote file calcref.tex")
bf77c646 240 (t "Wrote files calctut.tex and calcref.tex"))))
136211a9
EZ
241
242(defun calc-split-volume (number fix name other-name)
243 (goto-char 1)
244 (search-forward "@c [title]\n")
245 (search-forward "Manual")
246 (delete-backward-char 6)
247 (insert name)
248 (search-forward "@c [volume]\n")
249 (insert "@sp 1\n@center Volume " number ": " name "\n")
250 (let ((pat (format "@c \\[fix-%s \\(.*\\)\\]\n" fix)))
251 (while (re-search-forward pat nil t)
252 (let ((topic (buffer-substring (match-beginning 1) (match-end 1))))
253 (re-search-forward "@\\(p?xref\\){[^}]*}")
254 (let ((cmd (buffer-substring (match-beginning 1) (match-end 1))))
255 (delete-region (match-beginning 0) (match-end 0))
256 (insert (if (equal cmd "pxref") "see" "See")
257 " ``" topic "'' in @emph{the Calc "
258 other-name "}")))))
259 (goto-char 1)
260 (while (search-forward "@c [when-split]\n" nil t)
261 (while (looking-at "@c ")
262 (delete-char 3)
263 (forward-line 1)))
264 (goto-char 1)
265 (while (search-forward "@c [not-split]\n" nil t)
266 (while (not (looking-at "@c"))
267 (insert "@c ")
bf77c646 268 (forward-line 1))))
136211a9
EZ
269
270
271(defun calc-inline-summary ()
272 "Make a special \"calcsum.tex\" file to be used with main manual."
bf77c646 273 (calc-split-summary nil t))
136211a9
EZ
274
275(defun calc-split-summary (&optional force in-line)
276 "Make a special \"calcsum.tex\" file with just the Calc summary."
277 (interactive "P")
278 (or (let ((case-fold-search t))
279 (string-match "calc\\.texinfo" (buffer-name)))
280 force
3132f345 281 (error "This command should be used in the calc.texinfo buffer"))
136211a9
EZ
282 (let ((srcbuf (current-buffer))
283 begpos sumpos endpos midpos)
284 (goto-char 1)
285 (search-forward "{Calc Manual}")
286 (backward-char 1)
287 (delete-backward-char 6)
288 (insert "Summary")
289 (search-forward "@c [begin]")
290 (beginning-of-line)
291 (setq begpos (point))
292 (search-forward "@c [summary]")
293 (beginning-of-line)
294 (setq sumpos (point))
295 (search-forward "@c [end-summary]")
296 (beginning-of-line)
297 (setq endpos (point))
298 (find-file "calcsum.tex")
299 (erase-buffer)
300 (insert-buffer-substring srcbuf 1 begpos)
301 (insert "@tex\n"
302 "\\global\\advance\\appendixno2\n"
303 "\\gdef\\xref#1.{See ``#1.''}\n")
304 (setq midpos (point))
305 (insert "@end tex\n")
306 (insert-buffer-substring srcbuf sumpos endpos)
307 (insert "@bye\n")
308 (goto-char 1)
309 (if (search-forward "{. a b c" nil t)
310 (replace-match "{... a b c"))
311 (goto-char 1)
312 (if in-line
313 (let ((buf (current-buffer))
314 (page nil))
315 (find-file "calc.aux")
316 (if (> (buffer-size) 0)
317 (progn
318 (goto-char 1)
319 (re-search-forward "{Summary-pg}{\\([0-9]+\\)}")
320 (setq page (string-to-int (buffer-substring (match-beginning 1)
321 (match-end 1))))))
322 (switch-to-buffer buf)
323 (if page
324 (progn
325 (message "Adjusting starting page number to %d" page)
326 (goto-char midpos)
327 (insert (format "\\global\\pageno=%d\n" page)))
328 (message "Unable to find page number from calc.aux")))
329 (if (search-forward "@c smallbook" nil t)
330 (progn ; activate "smallbook" format for compactness
331 (beginning-of-line)
332 (forward-char 1)
333 (delete-char 2))))
334 (let ((buf (current-buffer)))
335 (find-file "calc.ky")
336 (if (> (buffer-size) 0)
337 (let ((ibuf (current-buffer)))
338 (message "Mixing in page numbers from Key Index (calc.ky)")
339 (switch-to-buffer buf)
340 (goto-char 1)
341 (search-forward "notes at the end")
342 (insert "; the number in italics is\n"
343 "the page number where the command is described")
344 (while (re-search-forward
345 "@r{.*@: *\\([^ ]\\(.*[^ ]\\)?\\) *@:.*@:.*@:\\(.*\\)@:.*}"
346 nil t)
347 (let ((key (buffer-substring (match-beginning 1) (match-end 1)))
348 (pos (match-beginning 3))
349 num)
350 (set-buffer ibuf)
351 (goto-char 1)
352 (let ((p '( ( "I H " . "H I " ) ; oops!
353 ( "@@ ' \"" . "@@" ) ( "h m s" . "@@" )
354 ( "\\\\" . "{\\tt\\indexbackslash }" )
355 ( "_" . "{\\_}" )
356 ( "\\^" . "{\\tt\\hat}" )
357 ( "<" . "{\\tt\\less}" )
358 ( ">" . "{\\tt\\gtr}" )
359 ( "\"" ) ( "@{" ) ( "@}" )
360 ( "~" ) ( "|" ) ( "@@" )
361 ( "\\+" . "{\\tt\\char43}" )
362 ( "# l" . "# L" )
363 ( "I f I" . "f I" ) ( "I f Q" . "f Q" )
364 ( "V &" . "&" ) ( "C-u " . "" ) ))
365 (case-fold-search nil))
366 (while p
367 (if (string-match (car (car p)) key)
368 (setq key (concat (substring key 0 (match-beginning 0))
369 (or (cdr (car p))
370 (format "{\\tt\\char'%03o}"
371 (aref key (1- (match-end
372 0)))))
373 (substring key (match-end 0)))))
374 (setq p (cdr p)))
375 (setq num (and (search-forward (format "\\entry {%s}{" key)
376 nil t)
377 (looking-at "[0-9]+")
378 (buffer-substring (point) (match-end 0)))))
379 (set-buffer buf)
380 (goto-char pos)
381 (insert "@pgref{" (or num "") "}")))
382 (goto-char midpos)
383 (insert "\\gdef\\pgref#1{\\hbox to 2em{\\indsl\\hss#1}\\ \\ }\n"))
384 (message
385 "Unable to find Key Index (calc.ky); no page numbers inserted"))
386 (switch-to-buffer buf))
387 (save-buffer))
bf77c646 388 (message "Wrote file calcsum.tex"))
136211a9 389
bf77c646 390;;; calc-maint.el ends here