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