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 ;; Maintainer: Colin Walters <walters@debian.org>
8 ;; This file is part of GNU Emacs.
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.
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.
29 (defun calc-compile ()
30 "Compile all parts of Calc.
32 emacs -batch -l calc-maint -f calc-compile"
34 (if (equal (user-full-name) "David Gillespie")
35 (load "~/lisp/newbytecomp"))
36 (setq byte-compile-verbose t)
38 (let ((old-message (symbol-function 'message))
39 (old-write-region (symbol-function 'write-region))
44 (fset 'message (symbol-function 'calc-compile-message))
45 (fset 'write-region (symbol-function 'calc-compile-write-region))
47 (fset 'message old-message)
48 (fset 'write-region old-write-region)))
51 (defun calc-do-compile ()
52 (let ((make-backup-files nil)
55 (message-bug (string-match "^18.\\([0-4][0-9]\\|5[0-6]\\)"
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)
62 ;; Make sure we're in the right directory.
64 (if (= (buffer-size) 0)
65 (error "This command must be used in the Calc source directory"))
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)
73 ;; Compile all the source files.
75 '("calc.el" "calc-ext.el")
76 (sort (directory-files
78 "\\`calc-.[^x].*\\.el\\'")
81 (if (file-newer-than-file-p (car files) (concat (car files) "c"))
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)))
89 (message "File %s is up to date" (car files)))
90 (if (string-match "calc\\(-ext\\)?.el" (car files))
91 (load (concat (car files) "c") nil t t))
92 (setq files (cdr files))))
94 (if (or changed-units changed-rules)
98 ;; Pre-build the units table.
99 (if (and changed-units
100 (not (string-match "Lucid" emacs-version)))
102 (or message-bug (message ""))
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)
113 ;; Pre-build rewrite rules for j D, j M, etc.
114 (if (and changed-rules (not (string-match "^19" emacs-version)))
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\\)"
121 (setq rules (cons (buffer-substring (match-beginning 1)
124 (goto-char (point-min))
125 (re-search-forward "\n(defun calc-[A-Za-z]*Rules")
127 (delete-region (point) (point-max))
130 (let* ((vv (intern (concat "var-" v)))
133 (calc-var-value vv))))
134 (insert "\n(defun calc-" v " () '"
135 (prin1-to-string val) ")\n"))))
136 (sort rules 'string<))
138 (error (message "Unable to pre-build tables %s" err))))
139 (message "Done. Don't forget to install with \"make public\" or \"make private\"")))
141 (defun calc-compile-message (fmt &rest args)
142 (cond ((and (= (length args) 2)
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))
153 (if (> (+ comp-len (length name)) 75)
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
164 (string-match ".elc?\\'" (car args)))
165 (unless (string-match "Saving file %s..." fmt)
166 (funcall old-message fmt (file-name-nondirectory (car args)))))
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"))
171 (t (apply old-message fmt args))))
173 (defun calc-compile-write-region (start end filename &optional append visit &rest rest)
175 (set-buffer-auto-saved))
176 (if (and (string-match "\\.elc" filename)
177 (= start (point-min))
180 (goto-char (point-min))
181 (if (search-forward "\n(require (quote calc-macs))\n" nil t)
183 (setq end (point-max))))
184 (apply old-write-region start end filename append 'quietly rest)
185 (message "Wrote %s" filename)
190 (defun calc-split-tutorial (&optional force)
192 (calc-split-manual force 1))
195 (defun calc-split-reference (&optional force)
197 (calc-split-manual force 2))
200 (defun calc-split-manual (&optional force part)
201 "Split the Calc manual into separate Tutorial and Reference manuals.
202 Use this if your TeX installation is too small-minded to handle
203 calc.texinfo all at once.
204 Usage: C-x C-f calc.texinfo RET
205 M-x calc-split-manual RET"
207 (or (let ((case-fold-search t))
208 (string-match "calc\\.texinfo" (buffer-name)))
210 (error "This command should be used in the calc.texinfo buffer"))
211 (let ((srcbuf (current-buffer))
212 tutpos refpos endpos (maxpos (point-max)))
214 (search-forward "@c [tutorial]")
216 (setq tutpos (point))
217 (search-forward "@c [reference]")
219 (setq refpos (point))
220 (search-forward "@c [end]")
222 (setq endpos (point))
225 (find-file "calctut.tex")
227 (insert-buffer-substring srcbuf 1 refpos)
228 (insert-buffer-substring srcbuf endpos maxpos)
229 (calc-split-volume "I" "ref" "Tutorial" "Reference")
233 (find-file "calcref.tex")
235 (insert-buffer-substring srcbuf 1 tutpos)
236 (insert "\n@tex\n\\global\\advance\\chapno by 1\n@end tex\n")
237 (insert-buffer-substring srcbuf refpos maxpos)
238 (calc-split-volume "II" "tut" "Reference" "Tutorial")
240 (switch-to-buffer srcbuf)
242 (message (cond ((eq part 1) "Wrote file calctut.tex")
243 ((eq part 2) "Wrote file calcref.tex")
244 (t "Wrote files calctut.tex and calcref.tex"))))
246 (defun calc-split-volume (number fix name other-name)
248 (search-forward "@c [title]\n")
249 (search-forward "Manual")
250 (delete-backward-char 6)
252 (search-forward "@c [volume]\n")
253 (insert "@sp 1\n@center Volume " number ": " name "\n")
254 (let ((pat (format "@c \\[fix-%s \\(.*\\)\\]\n" fix)))
255 (while (re-search-forward pat nil t)
256 (let ((topic (buffer-substring (match-beginning 1) (match-end 1))))
257 (re-search-forward "@\\(p?xref\\){[^}]*}")
258 (let ((cmd (buffer-substring (match-beginning 1) (match-end 1))))
259 (delete-region (match-beginning 0) (match-end 0))
260 (insert (if (equal cmd "pxref") "see" "See")
261 " ``" topic "'' in @emph{the Calc "
264 (while (search-forward "@c [when-split]\n" nil t)
265 (while (looking-at "@c ")
269 (while (search-forward "@c [not-split]\n" nil t)
270 (while (not (looking-at "@c"))
275 (defun calc-inline-summary ()
276 "Make a special \"calcsum.tex\" file to be used with main manual."
277 (calc-split-summary nil t))
279 (defun calc-split-summary (&optional force in-line)
280 "Make a special \"calcsum.tex\" file with just the Calc summary."
282 (or (let ((case-fold-search t))
283 (string-match "calc\\.texinfo" (buffer-name)))
285 (error "This command should be used in the calc.texinfo buffer"))
286 (let ((srcbuf (current-buffer))
287 begpos sumpos endpos midpos)
289 (search-forward "{Calc Manual}")
291 (delete-backward-char 6)
293 (search-forward "@c [begin]")
295 (setq begpos (point))
296 (search-forward "@c [summary]")
298 (setq sumpos (point))
299 (search-forward "@c [end-summary]")
301 (setq endpos (point))
302 (find-file "calcsum.tex")
304 (insert-buffer-substring srcbuf 1 begpos)
306 "\\global\\advance\\appendixno2\n"
307 "\\gdef\\xref#1.{See ``#1.''}\n")
308 (setq midpos (point))
309 (insert "@end tex\n")
310 (insert-buffer-substring srcbuf sumpos endpos)
313 (if (search-forward "{. a b c" nil t)
314 (replace-match "{... a b c"))
317 (let ((buf (current-buffer))
319 (find-file "calc.aux")
320 (if (> (buffer-size) 0)
323 (re-search-forward "{Summary-pg}{\\([0-9]+\\)}")
324 (setq page (string-to-int (buffer-substring (match-beginning 1)
326 (switch-to-buffer buf)
329 (message "Adjusting starting page number to %d" page)
331 (insert (format "\\global\\pageno=%d\n" page)))
332 (message "Unable to find page number from calc.aux")))
333 (if (search-forward "@c smallbook" nil t)
334 (progn ; activate "smallbook" format for compactness
338 (let ((buf (current-buffer)))
339 (find-file "calc.ky")
340 (if (> (buffer-size) 0)
341 (let ((ibuf (current-buffer)))
342 (message "Mixing in page numbers from Key Index (calc.ky)")
343 (switch-to-buffer buf)
345 (search-forward "notes at the end")
346 (insert "; the number in italics is\n"
347 "the page number where the command is described")
348 (while (re-search-forward
349 "@r{.*@: *\\([^ ]\\(.*[^ ]\\)?\\) *@:.*@:.*@:\\(.*\\)@:.*}"
351 (let ((key (buffer-substring (match-beginning 1) (match-end 1)))
352 (pos (match-beginning 3))
356 (let ((p '( ( "I H " . "H I " ) ; oops!
357 ( "@@ ' \"" . "@@" ) ( "h m s" . "@@" )
358 ( "\\\\" . "{\\tt\\indexbackslash }" )
360 ( "\\^" . "{\\tt\\hat}" )
361 ( "<" . "{\\tt\\less}" )
362 ( ">" . "{\\tt\\gtr}" )
363 ( "\"" ) ( "@{" ) ( "@}" )
364 ( "~" ) ( "|" ) ( "@@" )
365 ( "\\+" . "{\\tt\\char43}" )
367 ( "I f I" . "f I" ) ( "I f Q" . "f Q" )
368 ( "V &" . "&" ) ( "C-u " . "" ) ))
369 (case-fold-search nil))
371 (if (string-match (car (car p)) key)
372 (setq key (concat (substring key 0 (match-beginning 0))
374 (format "{\\tt\\char'%03o}"
375 (aref key (1- (match-end
377 (substring key (match-end 0)))))
379 (setq num (and (search-forward (format "\\entry {%s}{" key)
381 (looking-at "[0-9]+")
382 (buffer-substring (point) (match-end 0)))))
385 (insert "@pgref{" (or num "") "}")))
387 (insert "\\gdef\\pgref#1{\\hbox to 2em{\\indsl\\hss#1}\\ \\ }\n"))
389 "Unable to find Key Index (calc.ky); no page numbers inserted"))
390 (switch-to-buffer buf))
392 (message "Wrote file calcsum.tex"))
396 (defun calc-public-autoloads ()
397 "Modify the public \"default\" file to contain the necessary autoload and
398 global-set-key commands for Calc."
400 (let ((home default-directory)
405 (setq name (expand-file-name "default" (car p)))))
407 (setq name (expand-file-name "default.el" (car p))))))
410 (error "Unable to find \"default\" file. Create one and try again"))
412 (if buffer-read-only (error "No write permission for \"%s\"" buffer-file-name))
413 (goto-char (point-max))
414 (calc-add-autoloads home "calc-public-autoloads")))
416 (defun calc-private-autoloads ()
417 "Modify the user's \".emacs\" file to contain the necessary autoload and
418 global-set-key commands for Calc."
420 (let ((home default-directory))
421 (find-file "~/.emacs")
422 (goto-char (point-max))
423 (calc-add-autoloads home "calc-private-autoloads")))
425 (defun calc-add-autoloads (home cmd)
426 (barf-if-buffer-read-only)
428 (if (and (re-search-backward ";;; Commands added by calc-.*-autoloads"
431 (search-forward ";;; End of Calc autoloads" nil t))
434 (message "(Removing previous autoloads)")
435 (delete-region top (point)))
438 (insert ";;; Commands added by " cmd " on "
439 (current-time-string) ".
440 \(autoload 'calc-dispatch \"calc\" \"Calculator Options\" t)
441 \(autoload 'full-calc \"calc\" \"Full-screen Calculator\" t)
442 \(autoload 'full-calc-keypad \"calc\" \"Full-screen X Calculator\" t)
443 \(autoload 'calc-eval \"calc\" \"Use Calculator from Lisp\")
444 \(autoload 'defmath \"calc\" nil t t)
445 \(autoload 'calc \"calc\" \"Calculator Mode\" t)
446 \(autoload 'quick-calc \"calc\" \"Quick Calculator\" t)
447 \(autoload 'calc-keypad \"calc\" \"X windows Calculator\" t)
448 \(autoload 'calc-embedded \"calc\" \"Use Calc inside any buffer\" t)
449 \(autoload 'calc-embedded-activate \"calc\" \"Activate =>'s in buffer\" t)
450 \(autoload 'calc-grab-region \"calc\" \"Grab region of Calc data\" t)
451 \(autoload 'calc-grab-rectangle \"calc\" \"Grab rectangle of data\" t)
452 \(setq load-path (nconc load-path (list \"" (directory-file-name home) "\")))
453 \(global-set-key \"\\e#\" 'calc-dispatch)
454 ;;; End of Calc autoloads.\n")
455 (let ((trim-versions-without-asking t))
458 ;;; calc-maint.el ends here