1 ;;; calc-maint.el --- maintenance routines for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainers: D. Goel <deego@gnufans.org>
7 ;; Colin Walters <walters@debian.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
13 ;; accepts responsibility to anyone for the consequences of using it
14 ;; or for whether it serves any particular purpose or works at all,
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
16 ;; License for full details.
18 ;; Everyone is granted permission to copy, modify and redistribute
19 ;; GNU Emacs, but only under the conditions described in the
20 ;; GNU Emacs General Public License. A copy of this license is
21 ;; supposed to have been given to you along with GNU Emacs so you
22 ;; can know your rights and responsibilities. It should be in a
23 ;; file named COPYING. Among other things, the copyright notice
24 ;; and this notice must be preserved on all copies.
30 (defun calc-compile ()
31 "Compile all parts of Calc.
33 emacs -batch -l calc-maint -f calc-compile"
35 (if (equal (user-full-name) "David Gillespie")
36 (load "~/lisp/newbytecomp"))
37 (setq byte-compile-verbose t
)
39 (let ((old-message (symbol-function 'message
))
40 (old-write-region (symbol-function 'write-region
))
45 (fset 'message
(symbol-function 'calc-compile-message
))
46 (fset 'write-region
(symbol-function 'calc-compile-write-region
))
48 (fset 'message old-message
)
49 (fset 'write-region old-write-region
)))
52 (defun calc-do-compile ()
53 (let ((make-backup-files nil
)
56 (message-bug (string-match "^18.\\([0-4][0-9]\\|5[0-6]\\)"
58 (setq max-lisp-eval-depth
(max 400 max-lisp-eval-depth
))
59 ;; Enable some irrelevant warnings to avoid compiler bug in 19.29:
60 (setq byte-compile-warnings
(and (string-match "^19.29" emacs-version
)
63 ;; Make sure we're in the right directory.
65 (if (= (buffer-size) 0)
66 (error "This command must be used in the Calc source directory"))
68 ;; Make sure current directory is in load-path.
69 (setq load-path
(cons default-directory load-path
))
70 (load "calc-macs.el" nil t t
)
74 ;; Compile all the source files.
76 '("calc.el" "calc-ext.el")
77 (sort (directory-files
79 "\\`calc-.[^x].*\\.el\\'")
82 (if (file-newer-than-file-p (car files
) (concat (car files
) "c"))
84 (if (string-match "calc-rules" (car files
))
85 (setq changed-rules t
))
86 (if (string-match "calc-units" (car files
))
87 (setq changed-units t
))
88 (or message-bug
(message ""))
89 (byte-compile-file (car files
)))
90 (message "File %s is up to date" (car files
)))
91 (if (string-match "calc\\(-ext\\)?.el" (car files
))
92 (load (concat (car files
) "c") nil t t
))
93 (setq files
(cdr files
))))
95 (if (or changed-units changed-rules
)
99 ;; Pre-build the units table.
100 (if (and changed-units
101 (not (string-match "Lucid" emacs-version
)))
103 (or message-bug
(message ""))
106 (math-build-units-table))
107 (find-file "calc-units.elc")
108 (goto-char (point-max))
109 (insert "\n(setq math-units-table '"
110 (prin1-to-string math-units-table
)
114 ;; Pre-build rewrite rules for j D, j M, etc.
115 (if (and changed-rules
(not (string-match "^19" emacs-version
)))
117 (or message-bug
(message ""))
118 (find-file "calc-rules.elc")
119 (goto-char (point-min))
120 (while (re-search-forward "defun calc-\\([A-Za-z]*Rules\\)"
122 (setq rules
(cons (buffer-substring (match-beginning 1)
125 (goto-char (point-min))
126 (re-search-forward "\n(defun calc-[A-Za-z]*Rules")
128 (delete-region (point) (point-max))
131 (let* ((vv (intern (concat "var-" v
)))
134 (calc-var-value vv
))))
135 (insert "\n(defun calc-" v
" () '"
136 (prin1-to-string val
) ")\n"))))
137 (sort rules
'string
<))
139 (error (message "Unable to pre-build tables %s" err
))))
140 (message "Done. Don't forget to install with \"make public\" or \"make private\"")))
142 (defun calc-compile-message (fmt &rest args
)
143 (cond ((and (= (length args
) 2)
145 (string-match ".elc?\\'" (car args
))
146 (symbolp (nth 1 args
)))
147 (let ((name (symbol-name (nth 1 args
))))
148 (princ (if comp-was-func
", " " "))
149 (if (and comp-was-func
(eq (string-match comp-was-func name
) 0))
150 (setq name
(substring name
(1- (length comp-was-func
))))
151 (setq comp-was-func
(if (string-match "\\`[a-zA-Z]+-" name
)
152 (substring name
0 (match-end 0))
154 (if (> (+ comp-len
(length name
)) 75)
159 (send-string-to-terminal "") ; cause an fflush(stdout)
160 (setq comp-len
(+ comp-len
2 (length name
)))))
161 ((and (setq comp-was-func nil
165 (string-match ".elc?\\'" (car args
)))
166 (unless (string-match "Saving file %s..." fmt
)
167 (funcall old-message fmt
(file-name-nondirectory (car args
)))))
168 ((string-match "\\(Preparing\\|Building\\).*\\.\\.\\.$" fmt
)
169 (send-string-to-terminal (apply 'format fmt args
)))
170 ((string-match "\\(Preparing\\|Building\\).*\\.\\.\\. *done$" fmt
)
171 (send-string-to-terminal "done\n"))
172 (t (apply old-message fmt args
))))
174 (defun calc-compile-write-region (start end filename
&optional append visit
&rest rest
)
176 (set-buffer-auto-saved))
177 (if (and (string-match "\\.elc" filename
)
178 (= start
(point-min))
181 (goto-char (point-min))
182 (if (search-forward "\n(require (quote calc-macs))\n" nil t
)
184 (setq end
(point-max))))
185 (apply old-write-region start end filename append
'quietly rest
)
186 (message "Wrote %s" filename
)
189 (defun calc-split-tutorial (&optional force
)
191 (calc-split-manual force
1))
193 (defun calc-split-reference (&optional force
)
195 (calc-split-manual force
2))
197 (defun calc-split-manual (&optional force part
)
198 "Split the Calc manual into separate Tutorial and Reference manuals.
199 Use this if your TeX installation is too small-minded to handle
200 calc.texinfo all at once.
201 Usage: C-x C-f calc.texinfo RET
202 M-x calc-split-manual RET"
204 (or (let ((case-fold-search t
))
205 (string-match "calc\\.texi" (buffer-name)))
207 (error "This command should be used in the calc.texi buffer"))
208 (let ((srcbuf (current-buffer))
209 tutpos refpos endpos
(maxpos (point-max)))
211 (search-forward "@c [tutorial]")
213 (setq tutpos
(point))
214 (search-forward "@c [reference]")
216 (setq refpos
(point))
217 (search-forward "@c [end]")
219 (setq endpos
(point))
222 (find-file "calctut.tex")
224 (insert-buffer-substring srcbuf
1 refpos
)
225 (insert-buffer-substring srcbuf endpos maxpos
)
226 (calc-split-volume "I" "ref" "Tutorial" "Reference")
230 (find-file "calcref.tex")
232 (insert-buffer-substring srcbuf
1 tutpos
)
233 (insert "\n@tex\n\\global\\advance\\chapno by 1\n@end tex\n")
234 (insert-buffer-substring srcbuf refpos maxpos
)
235 (calc-split-volume "II" "tut" "Reference" "Tutorial")
237 (switch-to-buffer srcbuf
)
239 (message (cond ((eq part
1) "Wrote file calctut.tex")
240 ((eq part
2) "Wrote file calcref.tex")
241 (t "Wrote files calctut.tex and calcref.tex"))))
243 (defun calc-split-volume (number fix name other-name
)
245 (search-forward "@c [title]\n")
246 (search-forward "Manual")
247 (delete-backward-char 6)
249 (search-forward "@c [volume]\n")
250 (insert "@sp 1\n@center Volume " number
": " name
"\n")
251 (let ((pat (format "@c \\[fix-%s \\(.*\\)\\]\n" fix
)))
252 (while (re-search-forward pat nil t
)
253 (let ((topic (buffer-substring (match-beginning 1) (match-end 1))))
254 (re-search-forward "@\\(p?xref\\){[^}]*}")
255 (let ((cmd (buffer-substring (match-beginning 1) (match-end 1))))
256 (delete-region (match-beginning 0) (match-end 0))
257 (insert (if (equal cmd
"pxref") "see" "See")
258 " ``" topic
"'' in @emph{the Calc "
261 (while (search-forward "@c [when-split]\n" nil t
)
262 (while (looking-at "@c ")
266 (while (search-forward "@c [not-split]\n" nil t
)
267 (while (not (looking-at "@c"))
272 (defun calc-inline-summary ()
273 "Make a special \"calcsum.tex\" file to be used with main manual."
274 (calc-split-summary nil t
))
276 (defun calc-split-summary (&optional force in-line
)
277 "Make a special \"calcsum.tex\" file with just the Calc summary."
279 (or (let ((case-fold-search t
))
280 (string-match "calc\\.texinfo" (buffer-name)))
282 (error "This command should be used in the calc.texinfo buffer"))
283 (let ((srcbuf (current-buffer))
284 begpos sumpos endpos midpos
)
286 (search-forward "{Calc Manual}")
288 (delete-backward-char 6)
290 (search-forward "@c [begin]")
292 (setq begpos
(point))
293 (search-forward "@c [summary]")
295 (setq sumpos
(point))
296 (search-forward "@c [end-summary]")
298 (setq endpos
(point))
299 (find-file "calcsum.tex")
301 (insert-buffer-substring srcbuf
1 begpos
)
303 "\\global\\advance\\appendixno2\n"
304 "\\gdef\\xref#1.{See ``#1.''}\n")
305 (setq midpos
(point))
306 (insert "@end tex\n")
307 (insert-buffer-substring srcbuf sumpos endpos
)
310 (if (search-forward "{. a b c" nil t
)
311 (replace-match "{... a b c"))
314 (let ((buf (current-buffer))
316 (find-file "calc.aux")
317 (if (> (buffer-size) 0)
320 (re-search-forward "{Summary-pg}{\\([0-9]+\\)}")
321 (setq page
(string-to-int (buffer-substring (match-beginning 1)
323 (switch-to-buffer buf
)
326 (message "Adjusting starting page number to %d" page
)
328 (insert (format "\\global\\pageno=%d\n" page
)))
329 (message "Unable to find page number from calc.aux")))
330 (if (search-forward "@c smallbook" nil t
)
331 (progn ; activate "smallbook" format for compactness
335 (let ((buf (current-buffer)))
336 (find-file "calc.ky")
337 (if (> (buffer-size) 0)
338 (let ((ibuf (current-buffer)))
339 (message "Mixing in page numbers from Key Index (calc.ky)")
340 (switch-to-buffer buf
)
342 (search-forward "notes at the end")
343 (insert "; the number in italics is\n"
344 "the page number where the command is described")
345 (while (re-search-forward
346 "@r{.*@: *\\([^ ]\\(.*[^ ]\\)?\\) *@:.*@:.*@:\\(.*\\)@:.*}"
348 (let ((key (buffer-substring (match-beginning 1) (match-end 1)))
349 (pos (match-beginning 3))
353 (let ((p '( ( "I H " .
"H I " ) ; oops!
354 ( "@@ ' \"" .
"@@" ) ( "h m s" .
"@@" )
355 ( "\\\\" .
"{\\tt\\indexbackslash }" )
357 ( "\\^" .
"{\\tt\\hat}" )
358 ( "<" .
"{\\tt\\less}" )
359 ( ">" .
"{\\tt\\gtr}" )
360 ( "\"" ) ( "@{" ) ( "@}" )
361 ( "~" ) ( "|" ) ( "@@" )
362 ( "\\+" .
"{\\tt\\char43}" )
364 ( "I f I" .
"f I" ) ( "I f Q" .
"f Q" )
365 ( "V &" .
"&" ) ( "C-u " .
"" ) ))
366 (case-fold-search nil
))
368 (if (string-match (car (car p
)) key
)
369 (setq key
(concat (substring key
0 (match-beginning 0))
371 (format "{\\tt\\char'%03o}"
372 (aref key
(1- (match-end
374 (substring key
(match-end 0)))))
376 (setq num
(and (search-forward (format "\\entry {%s}{" key
)
378 (looking-at "[0-9]+")
379 (buffer-substring (point) (match-end 0)))))
382 (insert "@pgref{" (or num
"") "}")))
384 (insert "\\gdef\\pgref#1{\\hbox to 2em{\\indsl\\hss#1}\\ \\ }\n"))
386 "Unable to find Key Index (calc.ky); no page numbers inserted"))
387 (switch-to-buffer buf
))
389 (message "Wrote file calcsum.tex"))
391 ;;; calc-maint.el ends here