Mercurial > emacs
annotate lisp/calc/calc-store.el @ 41091:418fff19f92e
Minor clarification.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 15 Nov 2001 18:53:38 +0000 |
parents | 73f364fd8aaa |
children | fcd507927105 |
rev | line source |
---|---|
40785 | 1 ;; Calculator for GNU Emacs, part II [calc-store.el] |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
40785 | 3 ;; Written by Dave Gillespie, daveg@synaptics.com. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | |
8 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
9 ;; accepts responsibility to anyone for the consequences of using it | |
10 ;; or for whether it serves any particular purpose or works at all, | |
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
12 ;; License for full details. | |
13 | |
14 ;; Everyone is granted permission to copy, modify and redistribute | |
15 ;; GNU Emacs, but only under the conditions described in the | |
16 ;; GNU Emacs General Public License. A copy of this license is | |
17 ;; supposed to have been given to you along with GNU Emacs so you | |
18 ;; can know your rights and responsibilities. It should be in a | |
19 ;; file named COPYING. Among other things, the copyright notice | |
20 ;; and this notice must be preserved on all copies. | |
21 | |
22 | |
23 | |
24 ;; This file is autoloaded from calc-ext.el. | |
25 (require 'calc-ext) | |
26 | |
27 (require 'calc-macs) | |
28 | |
29 (defun calc-Need-calc-store () nil) | |
30 | |
31 | |
32 ;;; Memory commands. | |
33 | |
34 (defun calc-store (&optional var) | |
35 (interactive) | |
36 (let ((calc-store-keep t)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
37 (calc-store-into var))) |
40785 | 38 (setq calc-store-keep nil) |
39 | |
40 (defun calc-store-into (&optional var) | |
41 (interactive) | |
42 (calc-wrapper | |
43 (let ((calc-given-value nil) | |
44 (calc-given-value-flag 1)) | |
45 (or var (setq var (calc-read-var-name "Store: " t))) | |
46 (if var | |
47 (let ((found (assq var '( ( + . calc-store-plus ) | |
48 ( - . calc-store-minus ) | |
49 ( * . calc-store-times ) | |
50 ( / . calc-store-div ) | |
51 ( ^ . calc-store-power ) | |
52 ( | . calc-store-concat ) )))) | |
53 (if found | |
54 (funcall (cdr found)) | |
55 (calc-store-value var (or calc-given-value (calc-top 1)) | |
56 "" calc-given-value-flag) | |
57 (message "Stored to variable \"%s\"" (calc-var-name var)))) | |
58 (setq var (calc-is-assignments (calc-top 1))) | |
59 (if var | |
60 (while var | |
61 (calc-store-value (car (car var)) (cdr (car var)) | |
62 (if (not (cdr var)) "") | |
63 (if (not (cdr var)) 1)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
64 (setq var (cdr var)))))))) |
40785 | 65 |
66 (defun calc-store-plus (&optional var) | |
67 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
68 (calc-store-binary var "+" '+)) |
40785 | 69 |
70 (defun calc-store-minus (&optional var) | |
71 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
72 (calc-store-binary var "-" '-)) |
40785 | 73 |
74 (defun calc-store-times (&optional var) | |
75 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
76 (calc-store-binary var "*" '*)) |
40785 | 77 |
78 (defun calc-store-div (&optional var) | |
79 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
80 (calc-store-binary var "/" '/)) |
40785 | 81 |
82 (defun calc-store-power (&optional var) | |
83 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
84 (calc-store-binary var "^" '^)) |
40785 | 85 |
86 (defun calc-store-concat (&optional var) | |
87 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
88 (calc-store-binary var "|" '|)) |
40785 | 89 |
90 (defun calc-store-neg (n &optional var) | |
91 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
92 (calc-store-binary var "n" '/ (- n))) |
40785 | 93 |
94 (defun calc-store-inv (n &optional var) | |
95 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
96 (calc-store-binary var "&" '^ (- n))) |
40785 | 97 |
98 (defun calc-store-incr (n &optional var) | |
99 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
100 (calc-store-binary var "n" '- (- n))) |
40785 | 101 |
102 (defun calc-store-decr (n &optional var) | |
103 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
104 (calc-store-binary var "n" '- n)) |
40785 | 105 |
106 (defun calc-store-value (var value tag &optional pop) | |
107 (if var | |
108 (let ((old (calc-var-value var))) | |
109 (set var value) | |
110 (if pop (or calc-store-keep (calc-pop-stack pop))) | |
111 (calc-record-undo (list 'store (symbol-name var) old)) | |
112 (if tag | |
113 (let ((calc-full-trail-vectors nil)) | |
114 (calc-record value (format ">%s%s" tag (calc-var-name var))))) | |
115 (and (memq var '(var-e var-i var-pi var-phi var-gamma)) | |
116 (eq (car-safe old) 'special-const) | |
117 (message "(Note: Built-in definition of %s has been lost)" var)) | |
118 (and (memq var '(var-inf var-uinf var-nan)) | |
119 (null old) | |
120 (message "(Note: %s has built-in meanings which may interfere)" | |
121 var)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
122 (calc-refresh-evaltos var)))) |
40785 | 123 |
124 (defun calc-var-name (var) | |
125 (if (symbolp var) (setq var (symbol-name var))) | |
126 (if (string-match "\\`var-." var) | |
127 (substring var 4) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
128 var)) |
40785 | 129 |
130 (defun calc-store-binary (var tag func &optional val) | |
131 (calc-wrapper | |
132 (let ((calc-simplify-mode (if (eq calc-simplify-mode 'none) | |
133 'num calc-simplify-mode)) | |
134 (value (or val (calc-top 1)))) | |
135 (or var (setq var (calc-read-var-name (format "Store %s: " tag)))) | |
136 (if var | |
137 (let ((old (calc-var-value var))) | |
138 (or old | |
139 (error "No such variable: \"%s\"" (calc-var-name var))) | |
140 (if (stringp old) | |
141 (setq old (math-read-expr old))) | |
142 (if (eq (car-safe old) 'error) | |
143 (error "Bad format in variable contents: %s" (nth 2 old))) | |
144 (calc-store-value var | |
145 (calc-normalize (if (calc-is-inverse) | |
146 (list func value old) | |
147 (list func old value))) | |
148 tag (and (not val) 1)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
149 (message "Stored to variable \"%s\"" (calc-var-name var))))))) |
40785 | 150 |
151 (defun calc-read-var-name (prompt &optional calc-store-opers) | |
152 (setq calc-given-value nil | |
153 calc-aborted-prefix nil) | |
154 (let ((var (let ((minibuffer-completion-table obarray) | |
155 (minibuffer-completion-predicate 'boundp) | |
156 (minibuffer-completion-confirm t)) | |
157 (read-from-minibuffer prompt "var-" calc-var-name-map nil)))) | |
158 (setq calc-aborted-prefix "") | |
159 (and (not (equal var "")) | |
160 (not (equal var "var-")) | |
161 (if (string-match "\\`\\([-a-zA-Z0-9]+\\) *:?=" var) | |
162 (if (null calc-given-value-flag) | |
163 (error "Assignment is not allowed in this command") | |
164 (let ((svar (intern (substring var 0 (match-end 1))))) | |
165 (setq calc-given-value-flag 0 | |
166 calc-given-value (math-read-expr | |
167 (substring var (match-end 0)))) | |
168 (if (eq (car-safe calc-given-value) 'error) | |
169 (error "Bad format: %s" (nth 2 calc-given-value))) | |
170 (setq calc-given-value (math-evaluate-expr calc-given-value)) | |
171 svar)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
172 (intern var))))) |
40785 | 173 (setq calc-given-value-flag nil) |
174 | |
175 (defvar calc-var-name-map nil "Keymap for reading Calc variable names.") | |
176 (if calc-var-name-map | |
177 () | |
178 (setq calc-var-name-map (copy-keymap minibuffer-local-completion-map)) | |
179 (define-key calc-var-name-map " " 'self-insert-command) | |
180 (mapcar (function | |
181 (lambda (x) | |
182 (define-key calc-var-name-map (char-to-string x) | |
183 'calcVar-digit))) | |
184 "0123456789") | |
185 (mapcar (function | |
186 (lambda (x) | |
187 (define-key calc-var-name-map (char-to-string x) | |
188 'calcVar-oper))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
189 "+-*/^|")) |
40785 | 190 |
191 (defun calcVar-digit () | |
192 (interactive) | |
193 (if (calc-minibuffer-contains "var-\\'") | |
194 (if (eq calc-store-opers 0) | |
195 (beep) | |
196 (insert "q") | |
197 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
198 (self-insert-command 1))) |
40785 | 199 |
200 (defun calcVar-oper () | |
201 (interactive) | |
202 (if (and (eq calc-store-opers t) | |
203 (calc-minibuffer-contains "var-\\'")) | |
204 (progn | |
205 (erase-buffer) | |
206 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
207 (self-insert-command 1))) |
40785 | 208 |
209 (defun calc-store-map (&optional oper var) | |
210 (interactive) | |
211 (calc-wrapper | |
212 (let* ((sel-mode nil) | |
213 (calc-dollar-values (mapcar 'calc-get-stack-element | |
214 (nthcdr calc-stack-top calc-stack))) | |
215 (calc-dollar-used 0) | |
216 (oper (or oper (calc-get-operator "Store Mapping"))) | |
217 (nargs (car oper))) | |
218 (or var (setq var (calc-read-var-name (format "Store Mapping %s: " | |
219 (nth 2 oper))))) | |
220 (if var | |
221 (let ((old (or (calc-var-value var) | |
222 (error "No such variable: \"%s\"" | |
223 (calc-var-name var)))) | |
224 (calc-simplify-mode (if (eq calc-simplify-mode 'none) | |
225 'num calc-simplify-mode)) | |
226 (values (and (> nargs 1) | |
227 (calc-top-list (1- nargs) (1+ calc-dollar-used))))) | |
228 (message "Working...") | |
229 (calc-set-command-flag 'clear-message) | |
230 (if (stringp old) | |
231 (setq old (math-read-expr old))) | |
232 (if (eq (car-safe old) 'error) | |
233 (error "Bad format in variable contents: %s" (nth 2 old))) | |
234 (setq values (if (calc-is-inverse) | |
235 (append values (list old)) | |
236 (append (list old) values))) | |
237 (calc-store-value var | |
238 (calc-normalize (cons (nth 1 oper) values)) | |
239 (nth 2 oper) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
240 (+ calc-dollar-used (1- nargs)))))))) |
40785 | 241 |
242 (defun calc-store-exchange (&optional var) | |
243 (interactive) | |
244 (calc-wrapper | |
245 (let ((calc-given-value nil) | |
246 (calc-given-value-flag 1) | |
247 top) | |
248 (or var (setq var (calc-read-var-name "Exchange with: "))) | |
249 (if var | |
250 (let ((value (calc-var-value var))) | |
251 (or value | |
252 (error "No such variable: \"%s\"" (calc-var-name var))) | |
253 (if (eq (car-safe value) 'special-const) | |
254 (error "%s is a special constant" var)) | |
255 (setq top (or calc-given-value (calc-top 1))) | |
256 (calc-store-value var top nil) | |
257 (calc-pop-push-record calc-given-value-flag | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
258 (concat "<>" (calc-var-name var)) value)))))) |
40785 | 259 |
260 (defun calc-unstore (&optional var) | |
261 (interactive) | |
262 (calc-wrapper | |
263 (or var (setq var (calc-read-var-name "Unstore: "))) | |
264 (if var | |
265 (progn | |
266 (and (memq var '(var-e var-i var-pi var-phi var-gamma)) | |
267 (eq (car-safe (calc-var-value var)) 'special-const) | |
268 (message "(Note: Built-in definition of %s has been lost)" var)) | |
269 (if (and (boundp var) (symbol-value var)) | |
270 (message "Unstored variable \"%s\"" (calc-var-name var)) | |
271 (message "Variable \"%s\" remains unstored" (calc-var-name var))) | |
272 (makunbound var) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
273 (calc-refresh-evaltos var))))) |
40785 | 274 |
275 (defun calc-let (&optional var) | |
276 (interactive) | |
277 (calc-wrapper | |
278 (let* ((calc-given-value nil) | |
279 (calc-given-value-flag 1) | |
280 thing value) | |
281 (or var (setq var (calc-read-var-name "Let variable: "))) | |
282 (if calc-given-value | |
283 (setq value calc-given-value | |
284 thing (calc-top 1)) | |
285 (setq value (calc-top 1) | |
286 thing (calc-top 2))) | |
287 (setq var (if var | |
288 (list (cons var value)) | |
289 (calc-is-assignments value))) | |
290 (if var | |
291 (calc-pop-push-record | |
292 (1+ calc-given-value-flag) | |
293 (concat "=" (calc-var-name (car (car var)))) | |
294 (let ((saved-val (mapcar (function | |
295 (lambda (v) | |
296 (and (boundp (car v)) | |
297 (symbol-value (car v))))) | |
298 var))) | |
299 (unwind-protect | |
300 (let ((vv var)) | |
301 (while vv | |
302 (set (car (car vv)) (calc-normalize (cdr (car vv)))) | |
303 (calc-refresh-evaltos (car (car vv))) | |
304 (setq vv (cdr vv))) | |
305 (math-evaluate-expr thing)) | |
306 (while saved-val | |
307 (if (car saved-val) | |
308 (set (car (car var)) (car saved-val)) | |
309 (makunbound (car (car var)))) | |
310 (setq saved-val (cdr saved-val) | |
311 var (cdr var))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
312 (calc-handle-whys)))))))) |
40785 | 313 |
314 (defun calc-is-assignments (value) | |
315 (if (memq (car-safe value) '(calcFunc-eq calcFunc-assign)) | |
316 (and (eq (car-safe (nth 1 value)) 'var) | |
317 (list (cons (nth 2 (nth 1 value)) (nth 2 value)))) | |
318 (if (eq (car-safe value) 'vec) | |
319 (let ((vv nil)) | |
320 (while (and (setq value (cdr value)) | |
321 (memq (car-safe (car value)) | |
322 '(calcFunc-eq calcFunc-assign)) | |
323 (eq (car-safe (nth 1 (car value))) 'var)) | |
324 (setq vv (cons (cons (nth 2 (nth 1 (car value))) | |
325 (nth 2 (car value))) | |
326 vv))) | |
327 (and (not value) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
328 vv))))) |
40785 | 329 |
330 (defun calc-recall (&optional var) | |
331 (interactive) | |
332 (calc-wrapper | |
333 (or var (setq var (calc-read-var-name "Recall: "))) | |
334 (if var | |
335 (let ((value (calc-var-value var))) | |
336 (or value | |
337 (error "No such variable: \"%s\"" (calc-var-name var))) | |
338 (if (stringp value) | |
339 (setq value (math-read-expr value))) | |
340 (if (eq (car-safe value) 'error) | |
341 (error "Bad format in variable contents: %s" (nth 2 value))) | |
342 (setq value (calc-normalize value)) | |
343 (let ((calc-full-trail-vectors nil)) | |
344 (calc-record value (concat "<" (calc-var-name var)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
345 (calc-push value))))) |
40785 | 346 |
347 (defun calc-store-quick () | |
348 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
349 (calc-store (intern (format "var-q%c" last-command-char)))) |
40785 | 350 |
351 (defun calc-store-into-quick () | |
352 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
353 (calc-store-into (intern (format "var-q%c" last-command-char)))) |
40785 | 354 |
355 (defun calc-recall-quick () | |
356 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
357 (calc-recall (intern (format "var-q%c" last-command-char)))) |
40785 | 358 |
359 (defun calc-copy-variable (&optional var1 var2) | |
360 (interactive) | |
361 (calc-wrapper | |
362 (or var1 (setq var1 (calc-read-var-name "Copy variable: "))) | |
363 (if var1 | |
364 (let ((value (calc-var-value var1))) | |
365 (or value | |
366 (error "No such variable: \"%s\"" (calc-var-name var))) | |
367 (or var2 (setq var2 (calc-read-var-name | |
368 (format "Copy variable: %s, to: " var1)))) | |
369 (if var2 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
370 (calc-store-value var2 value "")))))) |
40785 | 371 |
372 (defun calc-edit-variable (&optional var) | |
373 (interactive) | |
374 (calc-wrapper | |
375 (or var (setq var (calc-read-var-name | |
376 (if calc-last-edited-variable | |
377 (format "Edit: (default %s) " | |
378 (calc-var-name calc-last-edited-variable)) | |
379 "Edit: ")))) | |
380 (or var (setq var calc-last-edited-variable)) | |
381 (if var | |
382 (let* ((value (calc-var-value var))) | |
383 (if (eq (car-safe value) 'special-const) | |
384 (error "%s is a special constant" var)) | |
385 (setq calc-last-edited-variable var) | |
386 (calc-edit-mode (list 'calc-finish-stack-edit (list 'quote var)) | |
387 t | |
388 (concat "Editing " (calc-var-name var))) | |
389 (and value | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
390 (insert (math-format-nice-expr value (frame-width)) "\n"))))) |
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
391 (calc-show-edit-buffer)) |
40785 | 392 (setq calc-last-edited-variable nil) |
393 | |
394 (defun calc-edit-Decls () | |
395 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
396 (calc-edit-variable 'var-Decls)) |
40785 | 397 |
398 (defun calc-edit-EvalRules () | |
399 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
400 (calc-edit-variable 'var-EvalRules)) |
40785 | 401 |
402 (defun calc-edit-FitRules () | |
403 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
404 (calc-edit-variable 'var-FitRules)) |
40785 | 405 |
406 (defun calc-edit-GenCount () | |
407 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
408 (calc-edit-variable 'var-GenCount)) |
40785 | 409 |
410 (defun calc-edit-Holidays () | |
411 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
412 (calc-edit-variable 'var-Holidays)) |
40785 | 413 |
414 (defun calc-edit-IntegLimit () | |
415 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
416 (calc-edit-variable 'var-IntegLimit)) |
40785 | 417 |
418 (defun calc-edit-LineStyles () | |
419 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
420 (calc-edit-variable 'var-LineStyles)) |
40785 | 421 |
422 (defun calc-edit-PointStyles () | |
423 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
424 (calc-edit-variable 'var-PointStyles)) |
40785 | 425 |
426 (defun calc-edit-PlotRejects () | |
427 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
428 (calc-edit-variable 'var-PlotRejects)) |
40785 | 429 |
430 (defun calc-edit-AlgSimpRules () | |
431 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
432 (calc-edit-variable 'var-AlgSimpRules)) |
40785 | 433 |
434 (defun calc-edit-TimeZone () | |
435 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
436 (calc-edit-variable 'var-TimeZone)) |
40785 | 437 |
438 (defun calc-edit-Units () | |
439 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
440 (calc-edit-variable 'var-Units)) |
40785 | 441 |
442 (defun calc-edit-ExtSimpRules () | |
443 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
444 (calc-edit-variable 'var-ExtSimpRules)) |
40785 | 445 |
446 (defun calc-declare-variable (&optional var) | |
447 (interactive) | |
448 (calc-wrapper | |
449 (or var (setq var (calc-read-var-name "Declare: " 0))) | |
450 (or var (setq var 'var-All)) | |
451 (let* (dp decl def row rp) | |
452 (or (and (calc-var-value 'var-Decls) | |
453 (eq (car-safe var-Decls) 'vec)) | |
454 (setq var-Decls (list 'vec))) | |
455 (setq dp var-Decls) | |
456 (while (and (setq dp (cdr dp)) | |
457 (or (not (eq (car-safe (car dp)) 'vec)) | |
458 (/= (length (car dp)) 3) | |
459 (progn | |
460 (setq row (nth 1 (car dp)) | |
461 rp row) | |
462 (if (eq (car-safe row) 'vec) | |
463 (progn | |
464 (while | |
465 (and (setq rp (cdr rp)) | |
466 (or (not (eq (car-safe (car rp)) 'var)) | |
467 (not (eq (nth 2 (car rp)) var))))) | |
468 (setq rp (car rp))) | |
469 (if (or (not (eq (car-safe row) 'var)) | |
470 (not (eq (nth 2 row) var))) | |
471 (setq rp nil))) | |
472 (not rp))))) | |
473 (calc-unread-command ?\C-a) | |
474 (setq decl (read-string (format "Declare: %s to be: " var) | |
475 (and rp | |
476 (math-format-flat-expr (nth 2 (car dp)) 0)))) | |
477 (setq decl (and (string-match "[^ \t]" decl) | |
478 (math-read-exprs decl))) | |
479 (if (eq (car-safe decl) 'error) | |
480 (error "Bad format in declaration: %s" (nth 2 decl))) | |
481 (if (cdr decl) | |
482 (setq decl (cons 'vec decl)) | |
483 (setq decl (car decl))) | |
484 (and (eq (car-safe decl) 'vec) | |
485 (= (length decl) 2) | |
486 (setq decl (nth 1 decl))) | |
487 (calc-record (append '(vec) (list (math-build-var-name var)) | |
488 (and decl (list decl))) | |
489 "decl") | |
490 (setq var-Decls (copy-sequence var-Decls)) | |
491 (if (eq (car-safe row) 'vec) | |
492 (progn | |
493 (setcdr row (delq rp (cdr row))) | |
494 (or (cdr row) | |
495 (setq var-Decls (delq (car dp) var-Decls)))) | |
496 (setq var-Decls (delq (car dp) var-Decls))) | |
497 (if decl | |
498 (progn | |
499 (setq dp (and (not (eq var 'var-All)) var-Decls)) | |
500 (while (and (setq dp (cdr dp)) | |
501 (or (not (eq (car-safe (car dp)) 'vec)) | |
502 (/= (length (car dp)) 3) | |
503 (not (equal (nth 2 (car dp)) decl))))) | |
504 (if dp | |
505 (setcar (cdr (car dp)) | |
506 (append (if (eq (car-safe (nth 1 (car dp))) 'vec) | |
507 (nth 1 (car dp)) | |
508 (list 'vec (nth 1 (car dp)))) | |
509 (list (math-build-var-name var)))) | |
510 (setq var-Decls (append var-Decls | |
511 (list (list 'vec | |
512 (math-build-var-name var) | |
513 decl))))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
514 (calc-refresh-evaltos 'var-Decls)))) |
40785 | 515 |
516 (defun calc-permanent-variable (&optional var) | |
517 (interactive) | |
518 (calc-wrapper | |
519 (or var (setq var (calc-read-var-name "Save variable (default=all): "))) | |
520 (let (pos) | |
521 (and var (or (and (boundp var) (symbol-value var)) | |
522 (error "No such variable"))) | |
523 (set-buffer (find-file-noselect (substitute-in-file-name | |
524 calc-settings-file))) | |
525 (if var | |
526 (calc-insert-permanent-variable var) | |
527 (mapatoms (function | |
528 (lambda (x) | |
529 (and (string-match "\\`var-" (symbol-name x)) | |
530 (not (memq x calc-dont-insert-variables)) | |
531 (calc-var-value x) | |
532 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
533 (calc-insert-permanent-variable x)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
534 (save-buffer)))) |
40785 | 535 (defvar calc-dont-insert-variables '(var-FitRules var-FactorRules |
536 var-CommuteRules var-JumpRules | |
537 var-DistribRules var-MergeRules | |
538 var-NegateRules var-InvertRules | |
539 var-IntegAfterRules | |
540 var-TimeZone var-PlotRejects | |
541 var-PlotData1 var-PlotData2 | |
542 var-PlotData3 var-PlotData4 | |
543 var-PlotData5 var-PlotData6 | |
544 var-DUMMY | |
545 )) | |
546 | |
547 (defun calc-insert-permanent-variable (var) | |
548 (goto-char (point-min)) | |
549 (if (search-forward (concat "(setq " (symbol-name var) " '") nil t) | |
550 (progn | |
551 (setq pos (point-marker)) | |
552 (forward-line -1) | |
553 (if (looking-at ";;; Variable .* stored by Calc on ") | |
554 (progn | |
555 (delete-region (match-end 0) (progn (end-of-line) (point))) | |
556 (insert (current-time-string)))) | |
557 (goto-char (- pos 8 (length (symbol-name var)))) | |
558 (forward-sexp 1) | |
559 (backward-char 1) | |
560 (delete-region pos (point))) | |
561 (goto-char (point-max)) | |
562 (insert "\n;;; Variable \"" | |
563 (symbol-name var) | |
564 "\" stored by Calc on " | |
565 (current-time-string) | |
566 "\n(setq " | |
567 (symbol-name var) | |
568 " ')\n") | |
569 (backward-char 2)) | |
570 (insert (prin1-to-string (calc-var-value var))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
571 (forward-line 1)) |
40785 | 572 |
573 (defun calc-insert-variables (buf) | |
574 (interactive "bBuffer in which to save variable values: ") | |
575 (save-excursion | |
576 (set-buffer buf) | |
577 (mapatoms (function | |
578 (lambda (x) | |
579 (and (string-match "\\`var-" (symbol-name x)) | |
580 (not (memq x calc-dont-insert-variables)) | |
581 (calc-var-value x) | |
582 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
583 (or (not (eq x 'var-Decls)) | |
584 (not (equal var-Decls '(vec)))) | |
585 (or (not (eq x 'var-Holidays)) | |
586 (not (equal var-Holidays '(vec (var sat var-sat) | |
587 (var sun var-sun))))) | |
588 (insert "(setq " | |
589 (symbol-name x) | |
590 " " | |
591 (prin1-to-string | |
592 (let ((calc-language | |
593 (if (memq calc-language '(nil big)) | |
594 'flat | |
595 calc-language))) | |
596 (math-format-value (symbol-value x) 100000))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
597 ")\n"))))))) |
40785 | 598 |
599 (defun calc-assign (arg) | |
600 (interactive "P") | |
601 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
602 (calc-binary-op ":=" 'calcFunc-assign arg))) |
40785 | 603 |
604 (defun calc-evalto (arg) | |
605 (interactive "P") | |
606 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
607 (calc-unary-op "=>" 'calcFunc-evalto arg))) |
40785 | 608 |
609 (defun calc-subscript (arg) | |
610 (interactive "P") | |
611 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
612 (calc-binary-op "sub" 'calcFunc-subscr arg))) |
40785 | 613 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
614 ;;; calc-store.el ends here |